diff options
author | Michael Muré <batolettre@gmail.com> | 2022-08-18 23:34:05 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2022-08-18 23:44:06 +0200 |
commit | 5511c230b678a181cc596238bf6669428d1b1902 (patch) | |
tree | 8701efc87732439f993eb4f1d00585fc419b87ab /entities/identity/version_test.go | |
parent | 5ca686b59751e3c87740b84108c54fc675a074cf (diff) | |
download | git-bug-5511c230b678a181cc596238bf6669428d1b1902.tar.gz |
move {bug,identity} to /entities, move input to /commands
Diffstat (limited to 'entities/identity/version_test.go')
-rw-r--r-- | entities/identity/version_test.go | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/entities/identity/version_test.go b/entities/identity/version_test.go new file mode 100644 index 00000000..385ad4d7 --- /dev/null +++ b/entities/identity/version_test.go @@ -0,0 +1,78 @@ +package identity + +import ( + "encoding/json" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/MichaelMure/git-bug/entity" + "github.com/MichaelMure/git-bug/repository" + "github.com/MichaelMure/git-bug/util/lamport" +) + +func makeIdentityTestRepo(t *testing.T) repository.ClockedRepo { + repo := repository.NewMockRepo() + + clock1, err := repo.GetOrCreateClock("foo") + require.NoError(t, err) + err = clock1.Witness(42) + require.NoError(t, err) + + clock2, err := repo.GetOrCreateClock("bar") + require.NoError(t, err) + err = clock2.Witness(34) + require.NoError(t, err) + + return repo +} + +func TestVersionJSON(t *testing.T) { + repo := makeIdentityTestRepo(t) + + keys := []*Key{ + generatePublicKey(), + generatePublicKey(), + } + + before, err := newVersion(repo, "name", "email", "login", "avatarUrl", keys) + require.NoError(t, err) + + before.SetMetadata("key1", "value1") + before.SetMetadata("key2", "value2") + + expected := &version{ + id: entity.UnsetId, + name: "name", + email: "email", + login: "login", + avatarURL: "avatarUrl", + unixTime: time.Now().Unix(), + times: map[string]lamport.Time{ + "foo": 42, + "bar": 34, + }, + keys: keys, + nonce: before.nonce, + metadata: map[string]string{ + "key1": "value1", + "key2": "value2", + }, + } + + require.Equal(t, expected, before) + + data, err := json.Marshal(before) + assert.NoError(t, err) + + var after version + err = json.Unmarshal(data, &after) + assert.NoError(t, err) + + // make sure we now have an Id + expected.Id() + + assert.Equal(t, expected, &after) +} |