Further test refactoring
This commit is contained in:
parent
9a202207b4
commit
f0b8e5ab64
@ -9,7 +9,7 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func testListInDB(t *testing.T, store storage.ListStorage, root *aclrecordproto.RawACLRecordWithId, head string) {
|
||||
func testList(t *testing.T, store storage.ListStorage, root *aclrecordproto.RawACLRecordWithId, head string) {
|
||||
require.Equal(t, store.ID(), root.Id)
|
||||
|
||||
aclRoot, err := store.Root()
|
||||
@ -38,7 +38,7 @@ func TestListStorage(t *testing.T) {
|
||||
fx.db.View(func(txn *badger.Txn) (err error) {
|
||||
listStore, err = newListStorage(spaceId, fx.db, txn)
|
||||
require.NoError(t, err)
|
||||
testListInDB(t, listStore, aclRoot, aclRoot.Id)
|
||||
testList(t, listStore, aclRoot, aclRoot.Id)
|
||||
|
||||
return nil
|
||||
})
|
||||
@ -48,7 +48,7 @@ func TestListStorage(t *testing.T) {
|
||||
// this is ok, because we only create new list storage when we create space storage
|
||||
listStore, err := createListStorage(spaceId, fx.db, txn, aclRoot)
|
||||
require.NoError(t, err)
|
||||
testListInDB(t, listStore, aclRoot, aclRoot.Id)
|
||||
testList(t, listStore, aclRoot, aclRoot.Id)
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
@ -24,14 +24,14 @@ func spaceTestPayload() spacestorage.SpaceStorageCreatePayload {
|
||||
}
|
||||
}
|
||||
|
||||
func testSpaceInDB(t *testing.T, store spacestorage.SpaceStorage, payload spacestorage.SpaceStorageCreatePayload) {
|
||||
func testSpace(t *testing.T, store spacestorage.SpaceStorage, payload spacestorage.SpaceStorageCreatePayload) {
|
||||
header, err := store.SpaceHeader()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, payload.SpaceHeaderWithId, header)
|
||||
|
||||
aclStorage, err := store.ACLStorage()
|
||||
require.NoError(t, err)
|
||||
testListInDB(t, aclStorage, payload.RecWithId, payload.RecWithId.Id)
|
||||
testList(t, aclStorage, payload.RecWithId, payload.RecWithId.Id)
|
||||
}
|
||||
|
||||
func TestSpaceStorage_Create(t *testing.T) {
|
||||
@ -43,7 +43,7 @@ func TestSpaceStorage_Create(t *testing.T) {
|
||||
store, err := createSpaceStorage(fx.db, payload)
|
||||
require.NoError(t, err)
|
||||
|
||||
testSpaceInDB(t, store, payload)
|
||||
testSpace(t, store, payload)
|
||||
require.NoError(t, store.Close())
|
||||
|
||||
t.Run("create same storage returns error", func(t *testing.T) {
|
||||
@ -66,17 +66,17 @@ func TestSpaceStorage_NewAndCreateTree(t *testing.T) {
|
||||
defer fx.stop(t)
|
||||
store, err = newSpaceStorage(fx.db, payload.SpaceHeaderWithId.Id)
|
||||
require.NoError(t, err)
|
||||
testSpaceInDB(t, store, payload)
|
||||
testSpace(t, store, payload)
|
||||
|
||||
t.Run("create tree and get tree", func(t *testing.T) {
|
||||
payload := treeTestPayload()
|
||||
treeStore, err := store.CreateTreeStorage(payload)
|
||||
require.NoError(t, err)
|
||||
testTreePayloadInDB(t, treeStore, payload)
|
||||
testTreePayload(t, treeStore, payload)
|
||||
|
||||
otherStore, err := store.TreeStorage(payload.RootRawChange.Id)
|
||||
require.NoError(t, err)
|
||||
testTreePayloadInDB(t, otherStore, payload)
|
||||
testTreePayload(t, otherStore, payload)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ type fixture struct {
|
||||
db *badger.DB
|
||||
}
|
||||
|
||||
func testTreePayloadInDB(t *testing.T, store storage.TreeStorage, payload storage.TreeStorageCreatePayload) {
|
||||
func testTreePayload(t *testing.T, store storage.TreeStorage, payload storage.TreeStorageCreatePayload) {
|
||||
require.Equal(t, payload.RootRawChange.Id, store.ID())
|
||||
|
||||
root, err := store.Root()
|
||||
@ -70,7 +70,7 @@ func TestTreeStorage_Create(t *testing.T) {
|
||||
payload := treeTestPayload()
|
||||
store, err := createTreeStorage(fx.db, spaceId, payload)
|
||||
require.NoError(t, err)
|
||||
testTreePayloadInDB(t, store, payload)
|
||||
testTreePayload(t, store, payload)
|
||||
|
||||
t.Run("create same storage returns error", func(t *testing.T) {
|
||||
_, err := createTreeStorage(fx.db, spaceId, payload)
|
||||
@ -91,7 +91,7 @@ func TestTreeStorage_Methods(t *testing.T) {
|
||||
defer fx.stop(t)
|
||||
store, err := newTreeStorage(fx.db, spaceId, payload.RootRawChange.Id)
|
||||
require.NoError(t, err)
|
||||
testTreePayloadInDB(t, store, payload)
|
||||
testTreePayload(t, store, payload)
|
||||
|
||||
t.Run("update heads", func(t *testing.T) {
|
||||
newHeads := []string{"a", "b"}
|
||||
|
||||
@ -57,7 +57,7 @@ func BuildACLListWithIdentity(acc *account.AccountData, storage storage.ListStor
|
||||
|
||||
func BuildACLList(storage storage.ListStorage) (ACLList, error) {
|
||||
id := storage.ID()
|
||||
return build(storage.ID(), newACLStateBuilder(), newACLRecordBuilder(id, common.NewKeychain()), storage)
|
||||
return build(id, newACLStateBuilder(), newACLRecordBuilder(id, common.NewKeychain()), storage)
|
||||
}
|
||||
|
||||
func build(id string, stateBuilder *aclStateBuilder, recBuilder ACLRecordBuilder, storage storage.ListStorage) (list ACLList, err error) {
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func testListInDB(t *testing.T, store storage.ListStorage, root *aclrecordproto.RawACLRecordWithId, head string) {
|
||||
func testList(t *testing.T, store storage.ListStorage, root *aclrecordproto.RawACLRecordWithId, head string) {
|
||||
require.Equal(t, store.ID(), root.Id)
|
||||
|
||||
aclRoot, err := store.Root()
|
||||
@ -28,13 +28,13 @@ func TestListStorage_Create(t *testing.T) {
|
||||
aclRoot := &aclrecordproto.RawACLRecordWithId{Payload: []byte("root"), Id: "someRootId"}
|
||||
listStore, err := createListStorage(fx.db, aclRoot)
|
||||
require.NoError(t, err)
|
||||
testListInDB(t, listStore, aclRoot, aclRoot.Id)
|
||||
testList(t, listStore, aclRoot, aclRoot.Id)
|
||||
|
||||
t.Run("create same list storage returns nil", func(t *testing.T) {
|
||||
// this is ok, because we only create new list storage when we create space storage
|
||||
listStore, err := createListStorage(fx.db, aclRoot)
|
||||
require.NoError(t, err)
|
||||
testListInDB(t, listStore, aclRoot, aclRoot.Id)
|
||||
testList(t, listStore, aclRoot, aclRoot.Id)
|
||||
})
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ func TestListStorage_Methods(t *testing.T) {
|
||||
defer fx.stop(t)
|
||||
listStore, err := newListStorage(fx.db)
|
||||
require.NoError(t, err)
|
||||
testListInDB(t, listStore, aclRoot, aclRoot.Id)
|
||||
testList(t, listStore, aclRoot, aclRoot.Id)
|
||||
|
||||
t.Run("set head", func(t *testing.T) {
|
||||
head := "newHead"
|
||||
|
||||
@ -25,14 +25,14 @@ func spaceTestPayload() spacestorage.SpaceStorageCreatePayload {
|
||||
}
|
||||
}
|
||||
|
||||
func testSpaceInDB(t *testing.T, store spacestorage.SpaceStorage, payload spacestorage.SpaceStorageCreatePayload) {
|
||||
func testSpace(t *testing.T, store spacestorage.SpaceStorage, payload spacestorage.SpaceStorageCreatePayload) {
|
||||
header, err := store.SpaceHeader()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, payload.SpaceHeaderWithId, header)
|
||||
|
||||
aclStorage, err := store.ACLStorage()
|
||||
require.NoError(t, err)
|
||||
testListInDB(t, aclStorage, payload.RecWithId, payload.RecWithId.Id)
|
||||
testList(t, aclStorage, payload.RecWithId, payload.RecWithId.Id)
|
||||
}
|
||||
|
||||
func TestSpaceStorage_Create(t *testing.T) {
|
||||
@ -43,7 +43,7 @@ func TestSpaceStorage_Create(t *testing.T) {
|
||||
store, err := createSpaceStorage(dir, payload)
|
||||
require.NoError(t, err)
|
||||
|
||||
testSpaceInDB(t, store, payload)
|
||||
testSpace(t, store, payload)
|
||||
require.NoError(t, store.Close())
|
||||
|
||||
t.Run("create same storage returns error", func(t *testing.T) {
|
||||
@ -66,17 +66,17 @@ func TestSpaceStorage_NewAndCreateTree(t *testing.T) {
|
||||
defer func() {
|
||||
require.NoError(t, store.Close())
|
||||
}()
|
||||
testSpaceInDB(t, store, payload)
|
||||
testSpace(t, store, payload)
|
||||
|
||||
t.Run("create tree and get tree", func(t *testing.T) {
|
||||
payload := treeTestPayload()
|
||||
treeStore, err := store.CreateTreeStorage(payload)
|
||||
require.NoError(t, err)
|
||||
testTreePayloadInDB(t, treeStore, payload)
|
||||
testTreePayload(t, treeStore, payload)
|
||||
|
||||
otherStore, err := store.TreeStorage(payload.RootRawChange.Id)
|
||||
require.NoError(t, err)
|
||||
testTreePayloadInDB(t, otherStore, payload)
|
||||
testTreePayload(t, otherStore, payload)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -42,7 +42,7 @@ func (fx *fixture) stop(t *testing.T) {
|
||||
require.NoError(t, fx.db.Close())
|
||||
}
|
||||
|
||||
func testTreePayloadInDB(t *testing.T, store storage.TreeStorage, payload storage.TreeStorageCreatePayload) {
|
||||
func testTreePayload(t *testing.T, store storage.TreeStorage, payload storage.TreeStorageCreatePayload) {
|
||||
require.Equal(t, payload.RootRawChange.Id, store.ID())
|
||||
|
||||
root, err := store.Root()
|
||||
@ -69,7 +69,7 @@ func TestTreeStorage_Create(t *testing.T) {
|
||||
payload := treeTestPayload()
|
||||
store, err := createTreeStorage(fx.db, payload)
|
||||
require.NoError(t, err)
|
||||
testTreePayloadInDB(t, store, payload)
|
||||
testTreePayload(t, store, payload)
|
||||
|
||||
t.Run("create same storage returns error", func(t *testing.T) {
|
||||
_, err := createTreeStorage(fx.db, payload)
|
||||
@ -89,7 +89,7 @@ func TestTreeStorage_Methods(t *testing.T) {
|
||||
defer fx.stop(t)
|
||||
store, err := newTreeStorage(fx.db, payload.RootRawChange.Id)
|
||||
require.NoError(t, err)
|
||||
testTreePayloadInDB(t, store, payload)
|
||||
testTreePayload(t, store, payload)
|
||||
|
||||
t.Run("update heads", func(t *testing.T) {
|
||||
newHeads := []string{"a", "b"}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user