diff options
-rw-r--r-- | identity/identity.go | 2 | ||||
-rw-r--r-- | identity/identity_test.go | 23 |
2 files changed, 19 insertions, 6 deletions
diff --git a/identity/identity.go b/identity/identity.go index 6b71fa35..3da8c5a3 100644 --- a/identity/identity.go +++ b/identity/identity.go @@ -289,7 +289,7 @@ type Mutator struct { Keys []*Key } -// Mutate allow to create a new version of the Identity +// Mutate allow to create a new version of the Identity in one go func (i *Identity) Mutate(f func(orig Mutator) Mutator) { orig := Mutator{ Name: i.Name(), diff --git a/identity/identity_test.go b/identity/identity_test.go index ee6ccdf7..f9091294 100644 --- a/identity/identity_test.go +++ b/identity/identity_test.go @@ -79,11 +79,6 @@ func TestIdentityCommitLoad(t *testing.T) { // add more version - identity.Mutate(func(orig Mutator) Mutator { - - return orig - }) - identity.addVersionForTest(&Version{ time: 201, name: "René Descartes", @@ -113,6 +108,24 @@ func TestIdentityCommitLoad(t *testing.T) { assert.Equal(t, identity, loaded) } +func TestIdentityMutate(t *testing.T) { + identity := NewIdentity("René Descartes", "rene.descartes@example.com") + + assert.Len(t, identity.versions, 1) + + identity.Mutate(func(orig Mutator) Mutator { + orig.Email = "rene@descartes.fr" + orig.Name = "René" + orig.Login = "rene" + return orig + }) + + assert.Len(t, identity.versions, 2) + assert.Equal(t, identity.Email(), "rene@descartes.fr") + assert.Equal(t, identity.Name(), "René") + assert.Equal(t, identity.Login(), "rene") +} + func commitsAreSet(t *testing.T, identity *Identity) { for _, version := range identity.versions { assert.NotEmpty(t, version.commitHash) |