aboutsummaryrefslogtreecommitdiffstats
path: root/identity/version_test.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2021-04-09 13:01:14 +0200
committerMichael Muré <batolettre@gmail.com>2021-04-09 13:01:14 +0200
commit1520f678f7a2bc6e01d9b01df5ce49f2f46be7d7 (patch)
treef6d71c1f29cf06ccab9e4ae434b19ab17caa4385 /identity/version_test.go
parent0fd570171d171aa574d7f01d6033a9c01d668465 (diff)
parentbc5f618eba812859bf87ce2c31b278bd518d4555 (diff)
downloadgit-bug-1520f678f7a2bc6e01d9b01df5ce49f2f46be7d7.tar.gz
Merge remote-tracking branch 'origin/master' into dev-gh-bridge
Diffstat (limited to 'identity/version_test.go')
-rw-r--r--identity/version_test.go67
1 files changed, 52 insertions, 15 deletions
diff --git a/identity/version_test.go b/identity/version_test.go
index 25848eb5..385ad4d7 100644
--- a/identity/version_test.go
+++ b/identity/version_test.go
@@ -3,39 +3,76 @@ 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 TestVersionSerialize(t *testing.T) {
- before := &Version{
+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",
- keys: []*Key{
- {
- Fingerprint: "fingerprint1",
- PubKey: "pubkey1",
- },
- {
- Fingerprint: "fingerprint2",
- PubKey: "pubkey2",
- },
+ unixTime: time.Now().Unix(),
+ times: map[string]lamport.Time{
+ "foo": 42,
+ "bar": 34,
},
- nonce: makeNonce(20),
+ keys: keys,
+ nonce: before.nonce,
metadata: map[string]string{
"key1": "value1",
"key2": "value2",
},
- time: 3,
}
+ require.Equal(t, expected, before)
+
data, err := json.Marshal(before)
assert.NoError(t, err)
- var after Version
+ var after version
err = json.Unmarshal(data, &after)
assert.NoError(t, err)
- assert.Equal(t, before, &after)
+ // make sure we now have an Id
+ expected.Id()
+
+ assert.Equal(t, expected, &after)
}