Add list storage
This commit is contained in:
parent
ca6964702f
commit
7ddd6825ba
63
node/storage/liststorage_test.go
Normal file
63
node/storage/liststorage_test.go
Normal file
@ -0,0 +1,63 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/aclrecordproto"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/storage"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func (fx *fixture) testListInDB(t *testing.T, store storage.ListStorage, root *aclrecordproto.RawACLRecordWithId, head string) {
|
||||
require.Equal(t, store.ID(), root.Id)
|
||||
|
||||
aclRoot, err := store.Root()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, root, aclRoot)
|
||||
|
||||
aclHead, err := store.Head()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, head, aclHead)
|
||||
}
|
||||
|
||||
func TestListStorage_Create(t *testing.T) {
|
||||
fx := newFixture(t)
|
||||
fx.open(t)
|
||||
defer fx.stop(t)
|
||||
|
||||
aclRoot := &aclrecordproto.RawACLRecordWithId{Payload: []byte("root"), Id: "someRootId"}
|
||||
listStore, err := createListStorage(fx.db, aclRoot)
|
||||
require.NoError(t, err)
|
||||
fx.testListInDB(t, listStore, aclRoot, aclRoot.Id)
|
||||
}
|
||||
|
||||
func TestListStorage_Methods(t *testing.T) {
|
||||
fx := newFixture(t)
|
||||
fx.open(t)
|
||||
aclRoot := &aclrecordproto.RawACLRecordWithId{Payload: []byte("root"), Id: "someRootId"}
|
||||
_, err := createListStorage(fx.db, aclRoot)
|
||||
require.NoError(t, err)
|
||||
fx.stop(t)
|
||||
|
||||
fx.open(t)
|
||||
defer fx.stop(t)
|
||||
listStore, err := newListStorage(fx.db)
|
||||
require.NoError(t, err)
|
||||
fx.testListInDB(t, listStore, aclRoot, aclRoot.Id)
|
||||
|
||||
t.Run("set head", func(t *testing.T) {
|
||||
head := "newHead"
|
||||
require.NoError(t, listStore.SetHead(head))
|
||||
aclHead, err := listStore.Head()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, head, aclHead)
|
||||
})
|
||||
|
||||
t.Run("add raw record and get raw record", func(t *testing.T) {
|
||||
newRec := &aclrecordproto.RawACLRecordWithId{Payload: []byte("rec"), Id: "someRecId"}
|
||||
require.NoError(t, listStore.AddRawRecord(context.Background(), newRec))
|
||||
aclRec, err := listStore.GetRawRecord(context.Background(), newRec.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, newRec, aclRec)
|
||||
})
|
||||
}
|
||||
@ -38,7 +38,7 @@ func (fx *fixture) open(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func (fx *fixture) testPayloadInDB(t *testing.T, store storage.TreeStorage, payload storage.TreeStorageCreatePayload) {
|
||||
func (fx *fixture) testTreePayloadInDB(t *testing.T, store storage.TreeStorage, payload storage.TreeStorageCreatePayload) {
|
||||
require.Equal(t, payload.RootRawChange.Id, store.ID())
|
||||
|
||||
root, err := store.Root()
|
||||
@ -61,7 +61,7 @@ func (fx *fixture) stop(t *testing.T) {
|
||||
require.NoError(t, fx.db.Close())
|
||||
}
|
||||
|
||||
func TestTreeStorage(t *testing.T) {
|
||||
func TestTreeStorage_Create(t *testing.T) {
|
||||
fx := newFixture(t)
|
||||
fx.open(t)
|
||||
defer fx.stop(t)
|
||||
@ -69,7 +69,7 @@ func TestTreeStorage(t *testing.T) {
|
||||
payload := treeTestPayload()
|
||||
store, err := createTreeStorage(fx.db, payload)
|
||||
require.NoError(t, err)
|
||||
fx.testPayloadInDB(t, store, payload)
|
||||
fx.testTreePayloadInDB(t, store, payload)
|
||||
}
|
||||
|
||||
func TestTreeStorage_Methods(t *testing.T) {
|
||||
@ -84,7 +84,7 @@ func TestTreeStorage_Methods(t *testing.T) {
|
||||
defer fx.stop(t)
|
||||
store, err := newTreeStorage(fx.db, payload.RootRawChange.Id)
|
||||
require.NoError(t, err)
|
||||
fx.testPayloadInDB(t, store, payload)
|
||||
fx.testTreePayloadInDB(t, store, payload)
|
||||
|
||||
t.Run("update heads", func(t *testing.T) {
|
||||
newHeads := []string{"a", "b"}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user