identity: actually test the mutator

Michael Muré created

Change summary

identity/identity.go      |  2 +-
identity/identity_test.go | 23 ++++++++++++++++++-----
2 files changed, 19 insertions(+), 6 deletions(-)

Detailed changes

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(),

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)