diff options
Diffstat (limited to 'identity/identity_test.go')
-rw-r--r-- | identity/identity_test.go | 33 |
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) +} |