aboutsummaryrefslogtreecommitdiffstats
path: root/identity/identity_test.go
diff options
context:
space:
mode:
authorMichael Muré <michael.mure@consensys.net>2018-11-21 18:56:12 +0100
committerMichael Muré <batolettre@gmail.com>2019-03-01 22:35:36 +0100
commitfeab9412dffe5772048aad29893c4cb01d566387 (patch)
treeb7bc9751f2ebdf8d41f5621bbf372eaf7625c4b9 /identity/identity_test.go
parent0aefae6fcca5786f2c898029c3d6282f760f2c63 (diff)
downloadgit-bug-feab9412dffe5772048aad29893c4cb01d566387.tar.gz
WIP identity in git
Diffstat (limited to 'identity/identity_test.go')
-rw-r--r--identity/identity_test.go145
1 files changed, 145 insertions, 0 deletions
diff --git a/identity/identity_test.go b/identity/identity_test.go
new file mode 100644
index 00000000..161fd56f
--- /dev/null
+++ b/identity/identity_test.go
@@ -0,0 +1,145 @@
+package identity
+
+import (
+ "testing"
+
+ "github.com/MichaelMure/git-bug/repository"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestIdentityCommit(t *testing.T) {
+ mockRepo := repository.NewMockRepoForTest()
+
+ // single version
+
+ identity := Identity{
+ Versions: []Version{
+ {
+ Name: "René Descartes",
+ Email: "rene.descartes@example.com",
+ },
+ },
+ }
+
+ err := identity.Commit(mockRepo)
+
+ assert.Nil(t, err)
+ assert.NotEmpty(t, identity.id)
+
+ // multiple version
+
+ identity = Identity{
+ Versions: []Version{
+ {
+ Time: 100,
+ Name: "René Descartes",
+ Email: "rene.descartes@example.com",
+ Keys: []Key{
+ {PubKey: "pubkeyA"},
+ },
+ },
+ {
+ Time: 200,
+ Name: "René Descartes",
+ Email: "rene.descartes@example.com",
+ Keys: []Key{
+ {PubKey: "pubkeyB"},
+ },
+ },
+ {
+ Time: 201,
+ Name: "René Descartes",
+ Email: "rene.descartes@example.com",
+ Keys: []Key{
+ {PubKey: "pubkeyC"},
+ },
+ },
+ },
+ }
+
+ err = identity.Commit(mockRepo)
+
+ assert.Nil(t, err)
+ assert.NotEmpty(t, identity.id)
+
+ // add more version
+
+ identity.AddVersion(Version{
+ Time: 201,
+ Name: "René Descartes",
+ Email: "rene.descartes@example.com",
+ Keys: []Key{
+ {PubKey: "pubkeyD"},
+ },
+ })
+
+ identity.AddVersion(Version{
+ Time: 300,
+ Name: "René Descartes",
+ Email: "rene.descartes@example.com",
+ Keys: []Key{
+ {PubKey: "pubkeyE"},
+ },
+ })
+
+ err = identity.Commit(mockRepo)
+
+ assert.Nil(t, err)
+ assert.NotEmpty(t, identity.id)
+}
+
+func TestIdentity_ValidKeysAtTime(t *testing.T) {
+ identity := Identity{
+ Versions: []Version{
+ {
+ Time: 100,
+ Name: "René Descartes",
+ Email: "rene.descartes@example.com",
+ Keys: []Key{
+ {PubKey: "pubkeyA"},
+ },
+ },
+ {
+ Time: 200,
+ Name: "René Descartes",
+ Email: "rene.descartes@example.com",
+ Keys: []Key{
+ {PubKey: "pubkeyB"},
+ },
+ },
+ {
+ Time: 201,
+ Name: "René Descartes",
+ Email: "rene.descartes@example.com",
+ Keys: []Key{
+ {PubKey: "pubkeyC"},
+ },
+ },
+ {
+ Time: 201,
+ Name: "René Descartes",
+ Email: "rene.descartes@example.com",
+ Keys: []Key{
+ {PubKey: "pubkeyD"},
+ },
+ },
+ {
+ Time: 300,
+ Name: "René Descartes",
+ Email: "rene.descartes@example.com",
+ Keys: []Key{
+ {PubKey: "pubkeyE"},
+ },
+ },
+ },
+ }
+
+ assert.Nil(t, identity.ValidKeysAtTime(10))
+ assert.Equal(t, identity.ValidKeysAtTime(100), []Key{{PubKey: "pubkeyA"}})
+ assert.Equal(t, identity.ValidKeysAtTime(140), []Key{{PubKey: "pubkeyA"}})
+ assert.Equal(t, identity.ValidKeysAtTime(200), []Key{{PubKey: "pubkeyB"}})
+ assert.Equal(t, identity.ValidKeysAtTime(201), []Key{{PubKey: "pubkeyD"}})
+ assert.Equal(t, identity.ValidKeysAtTime(202), []Key{{PubKey: "pubkeyD"}})
+ assert.Equal(t, identity.ValidKeysAtTime(300), []Key{{PubKey: "pubkeyE"}})
+ assert.Equal(t, identity.ValidKeysAtTime(3000), []Key{{PubKey: "pubkeyE"}})
+}