6
1
mirror of https://git.mills.io/saltyim/saltyim.git synced 2024-06-16 03:48:24 +00:00
prologic-saltyim/identity_test.go
2022-03-27 01:55:24 +10:00

40 lines
876 B
Go

package saltyim
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
const (
testAddr = "alice@example.com"
testIdentityPath = "alice.key"
)
func TestIdentity(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
dir, err := ioutil.TempDir("", "salty")
require.NoError(err)
defer os.RemoveAll(dir)
addr, err := ParseAddr(testAddr)
require.NoError(err)
fn := filepath.Join(dir, testIdentityPath)
ident1, err := CreateIdentity(WithIdentityAddr(addr), WithIdentityPath(fn))
require.NoError(err)
assert.NotNil(ident1.Key())
assert.Equal(addr.String(), ident1.Addr().String())
ident2, err := GetIdentity(WithIdentityAddr(addr), WithIdentityPath(fn))
require.NoError(err)
assert.NotNil(ident2.Key())
assert.Equal(addr.String(), ident2.Addr().String())
}