mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-08 05:57:03 +09:00
Add tests
This commit is contained in:
parent
e97d484242
commit
ecee52638a
2 changed files with 81 additions and 1 deletions
|
@ -928,6 +928,86 @@ func TestObjectTree(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("test fix incorrect changes added", func(t *testing.T) {
|
||||||
|
treeCtx := prepareTreeContext(t, aclList)
|
||||||
|
treeStorage := treeCtx.treeStorage
|
||||||
|
changeCreator := treeCtx.changeCreator
|
||||||
|
objTree := treeCtx.objTree
|
||||||
|
|
||||||
|
rawChangesFirst := []*treechangeproto.RawTreeChangeWithId{
|
||||||
|
changeCreator.CreateRoot("0", aclList.Head().Id),
|
||||||
|
changeCreator.CreateRaw("1", aclList.Head().Id, "0", true, "0"),
|
||||||
|
}
|
||||||
|
rawChangesSecond := []*treechangeproto.RawTreeChangeWithId{
|
||||||
|
changeCreator.CreateRoot("0", aclList.Head().Id),
|
||||||
|
changeCreator.CreateRaw("2", aclList.Head().Id, "0", true, "0"),
|
||||||
|
}
|
||||||
|
payloadFirst := RawChangesPayload{
|
||||||
|
NewHeads: []string{"1"},
|
||||||
|
RawChanges: rawChangesFirst,
|
||||||
|
}
|
||||||
|
payloadSecond := RawChangesPayload{
|
||||||
|
NewHeads: []string{"2"},
|
||||||
|
RawChanges: rawChangesSecond,
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := objTree.AddRawChanges(context.Background(), payloadFirst)
|
||||||
|
require.NoError(t, err, "adding changes should be without error")
|
||||||
|
require.Equal(t, []string{"1"}, res.Heads)
|
||||||
|
|
||||||
|
res, err = objTree.AddRawChanges(context.Background(), payloadSecond)
|
||||||
|
require.NoError(t, err, "adding changes should be without error")
|
||||||
|
require.Equal(t, []string{"1", "2"}, res.Heads)
|
||||||
|
|
||||||
|
for _, ch := range append(rawChangesFirst, rawChangesSecond...) {
|
||||||
|
raw, err := treeStorage.Get(context.Background(), ch.Id)
|
||||||
|
assert.NoError(t, err, "storage should have all the changes")
|
||||||
|
assert.Equal(t, ch.Id, raw.RawTreeChangeWithId().Id, "the changes in the storage should be the same")
|
||||||
|
assert.Equal(t, ch.RawChange, raw.RawTreeChangeWithId().RawChange, "the changes in the storage should be the same")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("test fix incorrect changes added with snapshot path", func(t *testing.T) {
|
||||||
|
treeCtx := prepareTreeContext(t, aclList)
|
||||||
|
treeStorage := treeCtx.treeStorage
|
||||||
|
changeCreator := treeCtx.changeCreator
|
||||||
|
objTree := treeCtx.objTree
|
||||||
|
|
||||||
|
rawChangesFirst := []*treechangeproto.RawTreeChangeWithId{
|
||||||
|
changeCreator.CreateRoot("0", aclList.Head().Id),
|
||||||
|
changeCreator.CreateRaw("1", aclList.Head().Id, "0", true, "0"),
|
||||||
|
}
|
||||||
|
rawChangesSecond := []*treechangeproto.RawTreeChangeWithId{
|
||||||
|
changeCreator.CreateRoot("0", aclList.Head().Id),
|
||||||
|
changeCreator.CreateRaw("2", aclList.Head().Id, "0", true, "0"),
|
||||||
|
}
|
||||||
|
payloadFirst := RawChangesPayload{
|
||||||
|
NewHeads: []string{"1"},
|
||||||
|
RawChanges: rawChangesFirst,
|
||||||
|
SnapshotPath: []string{"0", "1"},
|
||||||
|
}
|
||||||
|
payloadSecond := RawChangesPayload{
|
||||||
|
NewHeads: []string{"2"},
|
||||||
|
RawChanges: rawChangesSecond,
|
||||||
|
SnapshotPath: []string{"0", "2"},
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := objTree.AddRawChanges(context.Background(), payloadFirst)
|
||||||
|
require.NoError(t, err, "adding changes should be without error")
|
||||||
|
require.Equal(t, []string{"1"}, res.Heads)
|
||||||
|
|
||||||
|
res, err = objTree.AddRawChanges(context.Background(), payloadSecond)
|
||||||
|
require.NoError(t, err, "adding changes should be without error")
|
||||||
|
require.Equal(t, []string{"1", "2"}, res.Heads)
|
||||||
|
|
||||||
|
for _, ch := range append(rawChangesFirst, rawChangesSecond...) {
|
||||||
|
raw, err := treeStorage.Get(context.Background(), ch.Id)
|
||||||
|
assert.NoError(t, err, "storage should have all the changes")
|
||||||
|
assert.Equal(t, ch.Id, raw.RawTreeChangeWithId().Id, "the changes in the storage should be the same")
|
||||||
|
assert.Equal(t, ch.RawChange, raw.RawTreeChangeWithId().RawChange, "the changes in the storage should be the same")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("add with rollback", func(t *testing.T) {
|
t.Run("add with rollback", func(t *testing.T) {
|
||||||
ctx := prepareTreeContext(t, aclList)
|
ctx := prepareTreeContext(t, aclList)
|
||||||
changeCreator := ctx.changeCreator
|
changeCreator := ctx.changeCreator
|
||||||
|
|
|
@ -225,7 +225,7 @@ func (tb *treeBuilder) lowestSnapshots(cache map[string]*Change, heads []string,
|
||||||
current = append(current, next...)
|
current = append(current, next...)
|
||||||
next = next[:0]
|
next = next[:0]
|
||||||
for _, id := range current {
|
for _, id := range current {
|
||||||
if ch, ok := cache[id]; ok {
|
if ch, ok := cache[id]; ok && ch.SnapshotId != "" {
|
||||||
if ch.visited {
|
if ch.visited {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue