From fe4237df3c62bd6dfd1f385893295f93072d0e51 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Mon, 25 Jan 2021 12:39:34 +0100 Subject: entity: readAll and more testing --- entity/dag/entity_actions_test.go | 110 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 entity/dag/entity_actions_test.go (limited to 'entity/dag/entity_actions_test.go') 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) +} -- cgit From e35c7c4d170d1b682992c95f1c14772158501015 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Fri, 5 Feb 2021 11:18:38 +0100 Subject: entity: more testing and bug fixing --- entity/dag/entity_actions_test.go | 181 ++++++++++++++++++++++++++++++-------- 1 file changed, 144 insertions(+), 37 deletions(-) (limited to 'entity/dag/entity_actions_test.go') diff --git a/entity/dag/entity_actions_test.go b/entity/dag/entity_actions_test.go index 6cc544b6..d7717056 100644 --- a/entity/dag/entity_actions_test.go +++ b/entity/dag/entity_actions_test.go @@ -1,62 +1,58 @@ package dag import ( + "sort" "testing" "github.com/stretchr/testify/require" - "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/repository" ) func allEntities(t testing.TB, bugs <-chan StreamedEntity) []*Entity { + t.Helper() + var result []*Entity for streamed := range bugs { - if streamed.Err != nil { - t.Fatal(streamed.Err) - } + require.NoError(t, streamed.Err) + result = append(result, streamed.Entity) } return result } func TestPushPull(t *testing.T) { - repoA, repoB, remote, id1, id2, def := makeTestContextRemote() + repoA, repoB, remote, id1, id2, def := makeTestContextRemote(t) 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")) + e := New(def) + e.Append(newOp1(id1, "foo")) - err = entity.Commit(repoA) + err := e.Commit(repoA) require.NoError(t, err) - _, err = Push(def, repoA, "origin") + _, err = Push(def, repoA, "remote") require.NoError(t, err) - err = Pull(def, repoB, "origin") + err = Pull(def, repoB, "remote") 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")) + e = New(def) + e.Append(newOp2(id2, "bar")) - err = entity.Commit(repoB) + err = e.Commit(repoB) require.NoError(t, err) - _, err = Push(def, repoB, "origin") + _, err = Push(def, repoB, "remote") require.NoError(t, err) - err = Pull(def, repoA, "origin") + err = Pull(def, repoA, "remote") require.NoError(t, err) entities = allEntities(t, ReadAll(def, repoB)) @@ -64,39 +60,33 @@ func TestPushPull(t *testing.T) { } func TestListLocalIds(t *testing.T) { - repoA, repoB, remote, id1, id2, def := makeTestContextRemote() + repoA, repoB, remote, id1, id2, def := makeTestContextRemote(t) 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) + e := New(def) + e.Append(newOp1(id1, "foo")) + err := e.Commit(repoA) require.NoError(t, err) - entity = New(def) - entity.Append(newOp2(id2, "bar")) - err = entity.Commit(repoA) + e = New(def) + e.Append(newOp2(id2, "bar")) + err = e.Commit(repoA) require.NoError(t, err) listLocalIds(t, def, repoA, 2) listLocalIds(t, def, repoB, 0) - _, err = Push(def, repoA, "origin") + _, err = Push(def, repoA, "remote") require.NoError(t, err) - _, err = Fetch(def, repoB, "origin") + _, err = Fetch(def, repoB, "remote") require.NoError(t, err) listLocalIds(t, def, repoA, 2) listLocalIds(t, def, repoB, 0) - err = Pull(def, repoB, "origin") + err = Pull(def, repoB, "remote") require.NoError(t, err) listLocalIds(t, def, repoA, 2) @@ -108,3 +98,120 @@ func listLocalIds(t *testing.T, def Definition, repo repository.RepoData, expect require.NoError(t, err) require.Len(t, ids, expectedCount) } + +func assertMergeResults(t *testing.T, expected []entity.MergeResult, results <-chan entity.MergeResult) { + t.Helper() + + var allResults []entity.MergeResult + for result := range results { + allResults = append(allResults, result) + } + + require.Equal(t, len(expected), len(allResults)) + + sort.Slice(allResults, func(i, j int) bool { + return allResults[i].Id < allResults[j].Id + }) + sort.Slice(expected, func(i, j int) bool { + return expected[i].Id < expected[j].Id + }) + + for i, result := range allResults { + require.NoError(t, result.Err) + + require.Equal(t, expected[i].Id, result.Id) + require.Equal(t, expected[i].Status, result.Status) + + switch result.Status { + case entity.MergeStatusNew, entity.MergeStatusUpdated: + require.NotNil(t, result.Entity) + require.Equal(t, expected[i].Id, result.Entity.Id()) + } + + i++ + } +} + +func TestMerge(t *testing.T) { + repoA, repoB, remote, id1, id2, def := makeTestContextRemote(t) + defer repository.CleanupTestRepos(repoA, repoB, remote) + + // SCENARIO 1 + // if the remote Entity doesn't exist locally, it's created + + // 2 entities in repoA + push to remote + e1 := New(def) + e1.Append(newOp1(id1, "foo")) + err := e1.Commit(repoA) + require.NoError(t, err) + + e2 := New(def) + e2.Append(newOp2(id2, "bar")) + err = e2.Commit(repoA) + require.NoError(t, err) + + _, err = Push(def, repoA, "remote") + require.NoError(t, err) + + // repoB: fetch + merge from remote + + _, err = Fetch(def, repoB, "remote") + require.NoError(t, err) + + results := MergeAll(def, repoB, "remote") + + assertMergeResults(t, []entity.MergeResult{ + { + Id: e1.Id(), + Status: entity.MergeStatusNew, + }, + { + Id: e2.Id(), + Status: entity.MergeStatusNew, + }, + }, results) + + // SCENARIO 2 + // if the remote and local Entity have the same state, nothing is changed + + results = MergeAll(def, repoB, "remote") + + assertMergeResults(t, []entity.MergeResult{ + { + Id: e1.Id(), + Status: entity.MergeStatusNothing, + }, + { + Id: e2.Id(), + Status: entity.MergeStatusNothing, + }, + }, results) + + // SCENARIO 3 + // if the local Entity has new commits but the remote don't, nothing is changed + + e1.Append(newOp1(id1, "barbar")) + err = e1.Commit(repoA) + require.NoError(t, err) + + e2.Append(newOp2(id2, "barbarbar")) + err = e2.Commit(repoA) + require.NoError(t, err) + + results = MergeAll(def, repoA, "remote") + + assertMergeResults(t, []entity.MergeResult{ + { + Id: e1.Id(), + Status: entity.MergeStatusNothing, + }, + { + Id: e2.Id(), + Status: entity.MergeStatusNothing, + }, + }, results) + + // SCENARIO 4 + // if the remote has new commit, the local bug is updated to match the same history + // (fast-forward update) +} -- cgit From 26a4b0332e0f0a52026ac6e333e0bbd78a588171 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 7 Feb 2021 13:54:03 +0100 Subject: entity: test all merge scenario --- entity/dag/entity_actions_test.go | 214 ++++++++++++++++++++++++++++++++++---- 1 file changed, 192 insertions(+), 22 deletions(-) (limited to 'entity/dag/entity_actions_test.go') diff --git a/entity/dag/entity_actions_test.go b/entity/dag/entity_actions_test.go index d7717056..78baf41f 100644 --- a/entity/dag/entity_actions_test.go +++ b/entity/dag/entity_actions_test.go @@ -2,6 +2,7 @@ package dag import ( "sort" + "strings" "testing" "github.com/stretchr/testify/require" @@ -36,7 +37,7 @@ func TestPushPull(t *testing.T) { _, err = Push(def, repoA, "remote") require.NoError(t, err) - err = Pull(def, repoB, "remote") + err = Pull(def, repoB, "remote", id1) require.NoError(t, err) entities := allEntities(t, ReadAll(def, repoB)) @@ -52,7 +53,7 @@ func TestPushPull(t *testing.T) { _, err = Push(def, repoB, "remote") require.NoError(t, err) - err = Pull(def, repoA, "remote") + err = Pull(def, repoA, "remote", id1) require.NoError(t, err) entities = allEntities(t, ReadAll(def, repoB)) @@ -86,7 +87,7 @@ func TestListLocalIds(t *testing.T) { listLocalIds(t, def, repoA, 2) listLocalIds(t, def, repoB, 0) - err = Pull(def, repoB, "remote") + err = Pull(def, repoB, "remote", id1) require.NoError(t, err) listLocalIds(t, def, repoA, 2) @@ -132,6 +133,78 @@ func assertMergeResults(t *testing.T, expected []entity.MergeResult, results <-c } } +func assertEqualRefs(t *testing.T, repoA, repoB repository.RepoData, prefix string) { + t.Helper() + + refsA, err := repoA.ListRefs("") + require.NoError(t, err) + + var refsAFiltered []string + for _, ref := range refsA { + if strings.HasPrefix(ref, prefix) { + refsAFiltered = append(refsAFiltered, ref) + } + } + + refsB, err := repoB.ListRefs("") + require.NoError(t, err) + + var refsBFiltered []string + for _, ref := range refsB { + if strings.HasPrefix(ref, prefix) { + refsBFiltered = append(refsBFiltered, ref) + } + } + + require.NotEmpty(t, refsAFiltered) + require.Equal(t, refsAFiltered, refsBFiltered) + + for _, ref := range refsAFiltered { + commitA, err := repoA.ResolveRef(ref) + require.NoError(t, err) + commitB, err := repoB.ResolveRef(ref) + require.NoError(t, err) + + require.Equal(t, commitA, commitB) + } +} + +func assertNotEqualRefs(t *testing.T, repoA, repoB repository.RepoData, prefix string) { + t.Helper() + + refsA, err := repoA.ListRefs("") + require.NoError(t, err) + + var refsAFiltered []string + for _, ref := range refsA { + if strings.HasPrefix(ref, prefix) { + refsAFiltered = append(refsAFiltered, ref) + } + } + + refsB, err := repoB.ListRefs("") + require.NoError(t, err) + + var refsBFiltered []string + for _, ref := range refsB { + if strings.HasPrefix(ref, prefix) { + refsBFiltered = append(refsBFiltered, ref) + } + } + + require.NotEmpty(t, refsAFiltered) + require.Equal(t, refsAFiltered, refsBFiltered) + + for _, ref := range refsAFiltered { + commitA, err := repoA.ResolveRef(ref) + require.NoError(t, err) + commitB, err := repoB.ResolveRef(ref) + require.NoError(t, err) + + require.NotEqual(t, commitA, commitB) + } +} + func TestMerge(t *testing.T) { repoA, repoB, remote, id1, id2, def := makeTestContextRemote(t) defer repository.CleanupTestRepos(repoA, repoB, remote) @@ -140,14 +213,14 @@ func TestMerge(t *testing.T) { // if the remote Entity doesn't exist locally, it's created // 2 entities in repoA + push to remote - e1 := New(def) - e1.Append(newOp1(id1, "foo")) - err := e1.Commit(repoA) + e1A := New(def) + e1A.Append(newOp1(id1, "foo")) + err := e1A.Commit(repoA) require.NoError(t, err) - e2 := New(def) - e2.Append(newOp2(id2, "bar")) - err = e2.Commit(repoA) + e2A := New(def) + e2A.Append(newOp2(id2, "bar")) + err = e2A.Commit(repoA) require.NoError(t, err) _, err = Push(def, repoA, "remote") @@ -158,60 +231,157 @@ func TestMerge(t *testing.T) { _, err = Fetch(def, repoB, "remote") require.NoError(t, err) - results := MergeAll(def, repoB, "remote") + results := MergeAll(def, repoB, "remote", id1) assertMergeResults(t, []entity.MergeResult{ { - Id: e1.Id(), + Id: e1A.Id(), Status: entity.MergeStatusNew, }, { - Id: e2.Id(), + Id: e2A.Id(), Status: entity.MergeStatusNew, }, }, results) + assertEqualRefs(t, repoA, repoB, "refs/"+def.namespace) + // SCENARIO 2 // if the remote and local Entity have the same state, nothing is changed - results = MergeAll(def, repoB, "remote") + results = MergeAll(def, repoB, "remote", id1) assertMergeResults(t, []entity.MergeResult{ { - Id: e1.Id(), + Id: e1A.Id(), Status: entity.MergeStatusNothing, }, { - Id: e2.Id(), + Id: e2A.Id(), Status: entity.MergeStatusNothing, }, }, results) + assertEqualRefs(t, repoA, repoB, "refs/"+def.namespace) + // SCENARIO 3 // if the local Entity has new commits but the remote don't, nothing is changed - e1.Append(newOp1(id1, "barbar")) - err = e1.Commit(repoA) + e1A.Append(newOp1(id1, "barbar")) + err = e1A.Commit(repoA) require.NoError(t, err) - e2.Append(newOp2(id2, "barbarbar")) - err = e2.Commit(repoA) + e2A.Append(newOp2(id2, "barbarbar")) + err = e2A.Commit(repoA) require.NoError(t, err) - results = MergeAll(def, repoA, "remote") + results = MergeAll(def, repoA, "remote", id1) assertMergeResults(t, []entity.MergeResult{ { - Id: e1.Id(), + Id: e1A.Id(), Status: entity.MergeStatusNothing, }, { - Id: e2.Id(), + Id: e2A.Id(), Status: entity.MergeStatusNothing, }, }, results) + assertNotEqualRefs(t, repoA, repoB, "refs/"+def.namespace) + // SCENARIO 4 // if the remote has new commit, the local bug is updated to match the same history // (fast-forward update) + + _, err = Push(def, repoA, "remote") + require.NoError(t, err) + + _, err = Fetch(def, repoB, "remote") + require.NoError(t, err) + + results = MergeAll(def, repoB, "remote", id1) + + assertMergeResults(t, []entity.MergeResult{ + { + Id: e1A.Id(), + Status: entity.MergeStatusUpdated, + }, + { + Id: e2A.Id(), + Status: entity.MergeStatusUpdated, + }, + }, results) + + assertEqualRefs(t, repoA, repoB, "refs/"+def.namespace) + + // SCENARIO 5 + // if both local and remote Entity have new commits (that is, we have a concurrent edition), + // a merge commit with an empty operationPack is created to join both branch and form a DAG. + + e1A.Append(newOp1(id1, "barbarfoo")) + err = e1A.Commit(repoA) + require.NoError(t, err) + + e2A.Append(newOp2(id2, "barbarbarfoo")) + err = e2A.Commit(repoA) + require.NoError(t, err) + + e1B, err := Read(def, repoB, e1A.Id()) + require.NoError(t, err) + + e2B, err := Read(def, repoB, e2A.Id()) + require.NoError(t, err) + + e1B.Append(newOp1(id1, "barbarfoofoo")) + err = e1B.Commit(repoB) + require.NoError(t, err) + + e2B.Append(newOp2(id2, "barbarbarfoofoo")) + err = e2B.Commit(repoB) + require.NoError(t, err) + + _, err = Push(def, repoA, "remote") + require.NoError(t, err) + + _, err = Fetch(def, repoB, "remote") + require.NoError(t, err) + + results = MergeAll(def, repoB, "remote", id1) + + assertMergeResults(t, []entity.MergeResult{ + { + Id: e1A.Id(), + Status: entity.MergeStatusUpdated, + }, + { + Id: e2A.Id(), + Status: entity.MergeStatusUpdated, + }, + }, results) + + assertNotEqualRefs(t, repoA, repoB, "refs/"+def.namespace) + + _, err = Push(def, repoB, "remote") + require.NoError(t, err) + + _, err = Fetch(def, repoA, "remote") + require.NoError(t, err) + + results = MergeAll(def, repoA, "remote", id1) + + assertMergeResults(t, []entity.MergeResult{ + { + Id: e1A.Id(), + Status: entity.MergeStatusUpdated, + }, + { + Id: e2A.Id(), + Status: entity.MergeStatusUpdated, + }, + }, results) + + // make sure that the graphs become stable over multiple repo, due to the + // fast-forward + assertEqualRefs(t, repoA, repoB, "refs/"+def.namespace) } -- cgit From ef05c15f87468e0f4f1c688b0b9359cee2181c68 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Wed, 10 Feb 2021 18:22:21 +0100 Subject: entity: implement remove --- entity/dag/entity_actions_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'entity/dag/entity_actions_test.go') diff --git a/entity/dag/entity_actions_test.go b/entity/dag/entity_actions_test.go index 78baf41f..79afe525 100644 --- a/entity/dag/entity_actions_test.go +++ b/entity/dag/entity_actions_test.go @@ -385,3 +385,28 @@ func TestMerge(t *testing.T) { // fast-forward assertEqualRefs(t, repoA, repoB, "refs/"+def.namespace) } + +func TestRemove(t *testing.T) { + repoA, repoB, remote, id1, _, def := makeTestContextRemote(t) + defer repository.CleanupTestRepos(repoA, repoB, remote) + + e := New(def) + e.Append(newOp1(id1, "foo")) + require.NoError(t, e.Commit(repoA)) + + _, err := Push(def, repoA, "remote") + require.NoError(t, err) + + err = Remove(def, repoA, e.Id()) + require.NoError(t, err) + + _, err = Read(def, repoA, e.Id()) + require.Error(t, err) + + _, err = readRemote(def, repoA, "remote", e.Id()) + require.Error(t, err) + + // Remove is idempotent + err = Remove(def, repoA, e.Id()) + require.NoError(t, err) +} -- cgit From 94f06cd54defa73f5e8b79345597279e454c78e6 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 14 Feb 2021 10:02:01 +0100 Subject: entity: pass the identity resolver instead of defining it once Having the resolver in Definition doesn't actually work well as the resolver is very situational. --- entity/dag/entity_actions_test.go | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'entity/dag/entity_actions_test.go') diff --git a/entity/dag/entity_actions_test.go b/entity/dag/entity_actions_test.go index 79afe525..848d6468 100644 --- a/entity/dag/entity_actions_test.go +++ b/entity/dag/entity_actions_test.go @@ -24,7 +24,7 @@ func allEntities(t testing.TB, bugs <-chan StreamedEntity) []*Entity { } func TestPushPull(t *testing.T) { - repoA, repoB, remote, id1, id2, def := makeTestContextRemote(t) + repoA, repoB, remote, id1, id2, resolver, def := makeTestContextRemote(t) defer repository.CleanupTestRepos(repoA, repoB, remote) // A --> remote --> B @@ -37,10 +37,10 @@ func TestPushPull(t *testing.T) { _, err = Push(def, repoA, "remote") require.NoError(t, err) - err = Pull(def, repoB, "remote", id1) + err = Pull(def, repoB, resolver, "remote", id1) require.NoError(t, err) - entities := allEntities(t, ReadAll(def, repoB)) + entities := allEntities(t, ReadAll(def, repoB, resolver)) require.Len(t, entities, 1) // B --> remote --> A @@ -53,15 +53,15 @@ func TestPushPull(t *testing.T) { _, err = Push(def, repoB, "remote") require.NoError(t, err) - err = Pull(def, repoA, "remote", id1) + err = Pull(def, repoA, resolver, "remote", id1) require.NoError(t, err) - entities = allEntities(t, ReadAll(def, repoB)) + entities = allEntities(t, ReadAll(def, repoB, resolver)) require.Len(t, entities, 2) } func TestListLocalIds(t *testing.T) { - repoA, repoB, remote, id1, id2, def := makeTestContextRemote(t) + repoA, repoB, remote, id1, id2, resolver, def := makeTestContextRemote(t) defer repository.CleanupTestRepos(repoA, repoB, remote) // A --> remote --> B @@ -87,7 +87,7 @@ func TestListLocalIds(t *testing.T) { listLocalIds(t, def, repoA, 2) listLocalIds(t, def, repoB, 0) - err = Pull(def, repoB, "remote", id1) + err = Pull(def, repoB, resolver, "remote", id1) require.NoError(t, err) listLocalIds(t, def, repoA, 2) @@ -206,7 +206,7 @@ func assertNotEqualRefs(t *testing.T, repoA, repoB repository.RepoData, prefix s } func TestMerge(t *testing.T) { - repoA, repoB, remote, id1, id2, def := makeTestContextRemote(t) + repoA, repoB, remote, id1, id2, resolver, def := makeTestContextRemote(t) defer repository.CleanupTestRepos(repoA, repoB, remote) // SCENARIO 1 @@ -231,7 +231,7 @@ func TestMerge(t *testing.T) { _, err = Fetch(def, repoB, "remote") require.NoError(t, err) - results := MergeAll(def, repoB, "remote", id1) + results := MergeAll(def, repoB, resolver, "remote", id1) assertMergeResults(t, []entity.MergeResult{ { @@ -249,7 +249,7 @@ func TestMerge(t *testing.T) { // SCENARIO 2 // if the remote and local Entity have the same state, nothing is changed - results = MergeAll(def, repoB, "remote", id1) + results = MergeAll(def, repoB, resolver, "remote", id1) assertMergeResults(t, []entity.MergeResult{ { @@ -275,7 +275,7 @@ func TestMerge(t *testing.T) { err = e2A.Commit(repoA) require.NoError(t, err) - results = MergeAll(def, repoA, "remote", id1) + results = MergeAll(def, repoA, resolver, "remote", id1) assertMergeResults(t, []entity.MergeResult{ { @@ -300,7 +300,7 @@ func TestMerge(t *testing.T) { _, err = Fetch(def, repoB, "remote") require.NoError(t, err) - results = MergeAll(def, repoB, "remote", id1) + results = MergeAll(def, repoB, resolver, "remote", id1) assertMergeResults(t, []entity.MergeResult{ { @@ -327,10 +327,10 @@ func TestMerge(t *testing.T) { err = e2A.Commit(repoA) require.NoError(t, err) - e1B, err := Read(def, repoB, e1A.Id()) + e1B, err := Read(def, repoB, resolver, e1A.Id()) require.NoError(t, err) - e2B, err := Read(def, repoB, e2A.Id()) + e2B, err := Read(def, repoB, resolver, e2A.Id()) require.NoError(t, err) e1B.Append(newOp1(id1, "barbarfoofoo")) @@ -347,7 +347,7 @@ func TestMerge(t *testing.T) { _, err = Fetch(def, repoB, "remote") require.NoError(t, err) - results = MergeAll(def, repoB, "remote", id1) + results = MergeAll(def, repoB, resolver, "remote", id1) assertMergeResults(t, []entity.MergeResult{ { @@ -387,7 +387,7 @@ func TestMerge(t *testing.T) { } func TestRemove(t *testing.T) { - repoA, repoB, remote, id1, _, def := makeTestContextRemote(t) + repoA, repoB, remote, id1, _, resolver, def := makeTestContextRemote(t) defer repository.CleanupTestRepos(repoA, repoB, remote) e := New(def) @@ -400,10 +400,10 @@ func TestRemove(t *testing.T) { err = Remove(def, repoA, e.Id()) require.NoError(t, err) - _, err = Read(def, repoA, e.Id()) + _, err = Read(def, repoA, resolver, e.Id()) require.Error(t, err) - _, err = readRemote(def, repoA, "remote", e.Id()) + _, err = readRemote(def, repoA, resolver, "remote", e.Id()) require.Error(t, err) // Remove is idempotent -- cgit From 99b9dd84cb4b0cfd3eb1fd50b07c8b826eb52d19 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 14 Feb 2021 10:06:16 +0100 Subject: entity: support different author in staging operations --- entity/dag/entity_actions_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'entity/dag/entity_actions_test.go') diff --git a/entity/dag/entity_actions_test.go b/entity/dag/entity_actions_test.go index 848d6468..402f459c 100644 --- a/entity/dag/entity_actions_test.go +++ b/entity/dag/entity_actions_test.go @@ -244,7 +244,7 @@ func TestMerge(t *testing.T) { }, }, results) - assertEqualRefs(t, repoA, repoB, "refs/"+def.namespace) + assertEqualRefs(t, repoA, repoB, "refs/"+def.Namespace) // SCENARIO 2 // if the remote and local Entity have the same state, nothing is changed @@ -262,7 +262,7 @@ func TestMerge(t *testing.T) { }, }, results) - assertEqualRefs(t, repoA, repoB, "refs/"+def.namespace) + assertEqualRefs(t, repoA, repoB, "refs/"+def.Namespace) // SCENARIO 3 // if the local Entity has new commits but the remote don't, nothing is changed @@ -288,7 +288,7 @@ func TestMerge(t *testing.T) { }, }, results) - assertNotEqualRefs(t, repoA, repoB, "refs/"+def.namespace) + assertNotEqualRefs(t, repoA, repoB, "refs/"+def.Namespace) // SCENARIO 4 // if the remote has new commit, the local bug is updated to match the same history @@ -313,7 +313,7 @@ func TestMerge(t *testing.T) { }, }, results) - assertEqualRefs(t, repoA, repoB, "refs/"+def.namespace) + assertEqualRefs(t, repoA, repoB, "refs/"+def.Namespace) // SCENARIO 5 // if both local and remote Entity have new commits (that is, we have a concurrent edition), @@ -360,7 +360,7 @@ func TestMerge(t *testing.T) { }, }, results) - assertNotEqualRefs(t, repoA, repoB, "refs/"+def.namespace) + assertNotEqualRefs(t, repoA, repoB, "refs/"+def.Namespace) _, err = Push(def, repoB, "remote") require.NoError(t, err) @@ -368,7 +368,7 @@ func TestMerge(t *testing.T) { _, err = Fetch(def, repoA, "remote") require.NoError(t, err) - results = MergeAll(def, repoA, "remote", id1) + results = MergeAll(def, repoA, resolver, "remote", id1) assertMergeResults(t, []entity.MergeResult{ { @@ -383,7 +383,7 @@ func TestMerge(t *testing.T) { // make sure that the graphs become stable over multiple repo, due to the // fast-forward - assertEqualRefs(t, repoA, repoB, "refs/"+def.namespace) + assertEqualRefs(t, repoA, repoB, "refs/"+def.Namespace) } func TestRemove(t *testing.T) { -- cgit From 45e540c178533ef9aab01b1c3e782bc63061e313 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 14 Feb 2021 12:38:09 +0100 Subject: bug: wrap dag.Entity into a full Bug in MergeAll --- entity/dag/entity_actions_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'entity/dag/entity_actions_test.go') diff --git a/entity/dag/entity_actions_test.go b/entity/dag/entity_actions_test.go index 402f459c..45e69c7d 100644 --- a/entity/dag/entity_actions_test.go +++ b/entity/dag/entity_actions_test.go @@ -23,7 +23,7 @@ func allEntities(t testing.TB, bugs <-chan StreamedEntity) []*Entity { return result } -func TestPushPull(t *testing.T) { +func TestEntityPushPull(t *testing.T) { repoA, repoB, remote, id1, id2, resolver, def := makeTestContextRemote(t) defer repository.CleanupTestRepos(repoA, repoB, remote) -- cgit