Add lastIteratedId when setting merged heads
This commit is contained in:
parent
ea6ca799e7
commit
02b326cc90
@ -3,6 +3,9 @@ package objecttree
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/anyproto/any-sync/commonspace/object/accountdata"
|
"github.com/anyproto/any-sync/commonspace/object/accountdata"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/acl/list"
|
"github.com/anyproto/any-sync/commonspace/object/acl/list"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
|
"github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
|
||||||
@ -10,8 +13,6 @@ import (
|
|||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type testTreeContext struct {
|
type testTreeContext struct {
|
||||||
@ -123,6 +124,7 @@ func TestObjectTree(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.GreaterOrEqual(t, start.Unix(), ch.Timestamp)
|
require.GreaterOrEqual(t, start.Unix(), ch.Timestamp)
|
||||||
require.LessOrEqual(t, end.Unix(), ch.Timestamp)
|
require.LessOrEqual(t, end.Unix(), ch.Timestamp)
|
||||||
|
require.Equal(t, res.Added[0].Id, oTree.(*objectTree).tree.lastIteratedHeadId)
|
||||||
})
|
})
|
||||||
t.Run("timestamp is set correctly", func(t *testing.T) {
|
t.Run("timestamp is set correctly", func(t *testing.T) {
|
||||||
someTs := time.Now().Add(time.Hour).Unix()
|
someTs := time.Now().Add(time.Hour).Unix()
|
||||||
@ -139,6 +141,7 @@ func TestObjectTree(t *testing.T) {
|
|||||||
ch, err := oTree.(*objectTree).changeBuilder.Unmarshall(res.Added[0], true)
|
ch, err := oTree.(*objectTree).changeBuilder.Unmarshall(res.Added[0], true)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, ch.Timestamp, someTs)
|
require.Equal(t, ch.Timestamp, someTs)
|
||||||
|
require.Equal(t, res.Added[0].Id, oTree.(*objectTree).tree.lastIteratedHeadId)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -82,6 +82,7 @@ func (t *Tree) AddMergedHead(c *Change) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.headIds = []string{c.Id}
|
t.headIds = []string{c.Id}
|
||||||
|
t.lastIteratedHeadId = c.Id
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,10 +2,12 @@ package objecttree
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newChange(id string, snapshotId string, prevIds ...string) *Change {
|
func newChange(id string, snapshotId string, prevIds ...string) *Change {
|
||||||
@ -26,6 +28,17 @@ func newSnapshot(id, snapshotId string, prevIds ...string) *Change {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTree_AddMergedHead(t *testing.T) {
|
||||||
|
tr := new(Tree)
|
||||||
|
_, _ = tr.Add(
|
||||||
|
newSnapshot("root", ""),
|
||||||
|
newChange("one", "root", "root"),
|
||||||
|
)
|
||||||
|
require.Equal(t, tr.lastIteratedHeadId, "one")
|
||||||
|
tr.AddMergedHead(newChange("two", "root", "one"))
|
||||||
|
require.Equal(t, tr.lastIteratedHeadId, "two")
|
||||||
|
}
|
||||||
|
|
||||||
func TestTree_Add(t *testing.T) {
|
func TestTree_Add(t *testing.T) {
|
||||||
t.Run("add first el", func(t *testing.T) {
|
t.Run("add first el", func(t *testing.T) {
|
||||||
tr := new(Tree)
|
tr := new(Tree)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user