aboutsummaryrefslogtreecommitdiffstats
path: root/identity/identity_test.go
diff options
context:
space:
mode:
authorMichael Muré <michael.mure@consensys.net>2019-02-01 12:22:00 +0100
committerMichael Muré <batolettre@gmail.com>2019-03-01 22:40:22 +0100
commit56c6147eb6012252cf0b723b9eb6d1e841fc2f94 (patch)
treecce638adbf4a7d5b424fe9682cafc2fea5c64785 /identity/identity_test.go
parent14b240af8fef269d2c1d5dde2fff192b656c50f3 (diff)
downloadgit-bug-56c6147eb6012252cf0b723b9eb6d1e841fc2f94.tar.gz
identity: more refactoring progress
Diffstat (limited to 'identity/identity_test.go')
-rw-r--r--identity/identity_test.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/identity/identity_test.go b/identity/identity_test.go
index afb804fc..f1c07e79 100644
--- a/identity/identity_test.go
+++ b/identity/identity_test.go
@@ -1,6 +1,7 @@
package identity
import (
+ "encoding/json"
"testing"
"github.com/MichaelMure/git-bug/repository"
@@ -220,3 +221,35 @@ func assertHasKeyValue(t *testing.T, metadata map[string]string, key, value stri
assert.True(t, ok)
assert.Equal(t, val, value)
}
+
+func TestJSON(t *testing.T) {
+ mockRepo := repository.NewMockRepoForTest()
+
+ identity := &Identity{
+ Versions: []*Version{
+ {
+ Name: "René Descartes",
+ Email: "rene.descartes@example.com",
+ },
+ },
+ }
+
+ // commit to make sure we have an ID
+ err := identity.Commit(mockRepo)
+ assert.Nil(t, err)
+ assert.NotEmpty(t, identity.id)
+
+ // serialize
+ data, err := json.Marshal(identity)
+ assert.NoError(t, err)
+
+ // deserialize, got a IdentityStub with the same id
+ var i Interface
+ i, err = UnmarshalJSON(data)
+ assert.NoError(t, err)
+ assert.Equal(t, identity.id, i.Id())
+
+ // make sure we can load the identity properly
+ i, err = Read(mockRepo, i.Id())
+ assert.NoError(t, err)
+}