aboutsummaryrefslogtreecommitdiffstats
path: root/entity/dag/entity_actions_test.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2021-01-25 12:39:34 +0100
committerMichael Muré <batolettre@gmail.com>2021-02-14 12:19:01 +0100
commitfe4237df3c62bd6dfd1f385893295f93072d0e51 (patch)
tree66eabac7a2aaae9f7b4f2aff07092556e3a2a2ac /entity/dag/entity_actions_test.go
parentdc5059bc3372941e2908739831188768335ac50b (diff)
downloadgit-bug-fe4237df3c62bd6dfd1f385893295f93072d0e51.tar.gz
entity: readAll and more testing
Diffstat (limited to 'entity/dag/entity_actions_test.go')
-rw-r--r--entity/dag/entity_actions_test.go110
1 files changed, 110 insertions, 0 deletions
diff --git a/entity/dag/entity_actions_test.go b/entity/dag/entity_actions_test.go
new file mode 100644
index 00000000..6cc544b6
--- /dev/null
+++ b/entity/dag/entity_actions_test.go
@@ -0,0 +1,110 @@
+package dag
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/require"
+
+ "github.com/MichaelMure/git-bug/identity"
+ "github.com/MichaelMure/git-bug/repository"
+)
+
+func allEntities(t testing.TB, bugs <-chan StreamedEntity) []*Entity {
+ var result []*Entity
+ for streamed := range bugs {
+ if streamed.Err != nil {
+ t.Fatal(streamed.Err)
+ }
+ result = append(result, streamed.Entity)
+ }
+ return result
+}
+
+func TestPushPull(t *testing.T) {
+ repoA, repoB, remote, id1, id2, def := makeTestContextRemote()
+ defer repository.CleanupTestRepos(repoA, repoB, remote)
+
+ // distribute the identities
+ _, err := identity.Push(repoA, "origin")
+ require.NoError(t, err)
+ err = identity.Pull(repoB, "origin")
+ require.NoError(t, err)
+
+ // A --> remote --> B
+ entity := New(def)
+ entity.Append(newOp1(id1, "foo"))
+
+ err = entity.Commit(repoA)
+ require.NoError(t, err)
+
+ _, err = Push(def, repoA, "origin")
+ require.NoError(t, err)
+
+ err = Pull(def, repoB, "origin")
+ require.NoError(t, err)
+
+ entities := allEntities(t, ReadAll(def, repoB))
+ require.Len(t, entities, 1)
+
+ // B --> remote --> A
+ entity = New(def)
+ entity.Append(newOp2(id2, "bar"))
+
+ err = entity.Commit(repoB)
+ require.NoError(t, err)
+
+ _, err = Push(def, repoB, "origin")
+ require.NoError(t, err)
+
+ err = Pull(def, repoA, "origin")
+ require.NoError(t, err)
+
+ entities = allEntities(t, ReadAll(def, repoB))
+ require.Len(t, entities, 2)
+}
+
+func TestListLocalIds(t *testing.T) {
+ repoA, repoB, remote, id1, id2, def := makeTestContextRemote()
+ defer repository.CleanupTestRepos(repoA, repoB, remote)
+
+ // distribute the identities
+ _, err := identity.Push(repoA, "origin")
+ require.NoError(t, err)
+ err = identity.Pull(repoB, "origin")
+ require.NoError(t, err)
+
+ // A --> remote --> B
+ entity := New(def)
+ entity.Append(newOp1(id1, "foo"))
+ err = entity.Commit(repoA)
+ require.NoError(t, err)
+
+ entity = New(def)
+ entity.Append(newOp2(id2, "bar"))
+ err = entity.Commit(repoA)
+ require.NoError(t, err)
+
+ listLocalIds(t, def, repoA, 2)
+ listLocalIds(t, def, repoB, 0)
+
+ _, err = Push(def, repoA, "origin")
+ require.NoError(t, err)
+
+ _, err = Fetch(def, repoB, "origin")
+ require.NoError(t, err)
+
+ listLocalIds(t, def, repoA, 2)
+ listLocalIds(t, def, repoB, 0)
+
+ err = Pull(def, repoB, "origin")
+ require.NoError(t, err)
+
+ listLocalIds(t, def, repoA, 2)
+ listLocalIds(t, def, repoB, 2)
+}
+
+func listLocalIds(t *testing.T, def Definition, repo repository.RepoData, expectedCount int) {
+ ids, err := ListLocalIds(def, repo)
+ require.NoError(t, err)
+ require.Len(t, ids, expectedCount)
+}