2020-12-08 07:51:34 +00:00
|
|
|
package meta_test
|
2020-10-30 13:42:24 +00:00
|
|
|
|
|
|
|
import (
|
2020-12-08 07:51:34 +00:00
|
|
|
"encoding/hex"
|
2020-10-30 13:42:24 +00:00
|
|
|
"testing"
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
v2object "github.com/nspcc-dev/neofs-api-go/v2/object"
|
2022-03-03 14:19:05 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
2020-12-08 09:56:14 +00:00
|
|
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
2021-11-10 07:08:33 +00:00
|
|
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
|
|
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-01-26 12:11:13 +00:00
|
|
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/version"
|
2020-10-30 13:42:24 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
func TestDB_SelectUserAttributes(t *testing.T) {
|
|
|
|
db := newDB(t)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2021-12-01 13:56:48 +00:00
|
|
|
cid := cidtest.ID()
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
raw1 := generateObjectWithCID(t, cid)
|
2020-12-08 07:51:34 +00:00
|
|
|
addAttribute(raw1, "foo", "bar")
|
|
|
|
addAttribute(raw1, "x", "y")
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, raw1)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
raw2 := generateObjectWithCID(t, cid)
|
2020-12-08 07:51:34 +00:00
|
|
|
addAttribute(raw2, "foo", "bar")
|
|
|
|
addAttribute(raw2, "x", "z")
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw2)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
raw3 := generateObjectWithCID(t, cid)
|
2020-12-08 07:51:34 +00:00
|
|
|
addAttribute(raw3, "a", "b")
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw3)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
raw4 := generateObjectWithCID(t, cid)
|
2021-08-18 07:26:14 +00:00
|
|
|
addAttribute(raw4, "path", "test/1/2")
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw4)
|
2021-08-18 07:26:14 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
raw5 := generateObjectWithCID(t, cid)
|
2021-08-18 07:26:14 +00:00
|
|
|
addAttribute(raw5, "path", "test/1/3")
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw5)
|
2021-08-18 07:26:14 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
raw6 := generateObjectWithCID(t, cid)
|
2021-08-18 07:26:14 +00:00
|
|
|
addAttribute(raw6, "path", "test/2/3")
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw6)
|
2021-08-18 07:26:14 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter("foo", "bar", objectSDK.MatchStringEqual)
|
2020-12-10 13:17:45 +00:00
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw1),
|
|
|
|
object.AddressOf(raw2),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs = objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter("x", "y", objectSDK.MatchStringEqual)
|
2022-03-03 14:19:05 +00:00
|
|
|
testSelect(t, db, cid, fs, object.AddressOf(raw1))
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2021-02-01 21:00:40 +00:00
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("x", "y", objectSDK.MatchStringNotEqual)
|
2022-03-03 14:19:05 +00:00
|
|
|
testSelect(t, db, cid, fs, object.AddressOf(raw2))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs = objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter("a", "b", objectSDK.MatchStringEqual)
|
2022-03-03 14:19:05 +00:00
|
|
|
testSelect(t, db, cid, fs, object.AddressOf(raw3))
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs = objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter("c", "d", objectSDK.MatchStringEqual)
|
2020-12-10 13:17:45 +00:00
|
|
|
testSelect(t, db, cid, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs = objectSDK.SearchFilters{}
|
2021-02-01 21:00:40 +00:00
|
|
|
fs.AddFilter("foo", "", objectSDK.MatchNotPresent)
|
2021-08-18 07:26:14 +00:00
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw3),
|
|
|
|
object.AddressOf(raw4),
|
|
|
|
object.AddressOf(raw5),
|
|
|
|
object.AddressOf(raw6),
|
2021-08-18 07:26:14 +00:00
|
|
|
)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("a", "", objectSDK.MatchNotPresent)
|
2021-08-18 07:26:14 +00:00
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw1),
|
|
|
|
object.AddressOf(raw2),
|
|
|
|
object.AddressOf(raw4),
|
|
|
|
object.AddressOf(raw5),
|
|
|
|
object.AddressOf(raw6),
|
2021-08-18 07:26:14 +00:00
|
|
|
)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw1),
|
|
|
|
object.AddressOf(raw2),
|
|
|
|
object.AddressOf(raw3),
|
|
|
|
object.AddressOf(raw4),
|
|
|
|
object.AddressOf(raw5),
|
|
|
|
object.AddressOf(raw6),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("key", "", objectSDK.MatchNotPresent)
|
2020-12-10 13:17:45 +00:00
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw1),
|
|
|
|
object.AddressOf(raw2),
|
|
|
|
object.AddressOf(raw3),
|
|
|
|
object.AddressOf(raw4),
|
|
|
|
object.AddressOf(raw5),
|
|
|
|
object.AddressOf(raw6),
|
2021-08-18 07:26:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("path", "test", objectSDK.MatchCommonPrefix)
|
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw4),
|
|
|
|
object.AddressOf(raw5),
|
|
|
|
object.AddressOf(raw6),
|
2021-08-18 07:26:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("path", "test/1", objectSDK.MatchCommonPrefix)
|
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw4),
|
|
|
|
object.AddressOf(raw5),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
2020-10-30 13:42:24 +00:00
|
|
|
}
|
2020-11-03 13:12:34 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
func TestDB_SelectRootPhyParent(t *testing.T) {
|
2020-11-03 13:12:34 +00:00
|
|
|
db := newDB(t)
|
|
|
|
|
2021-12-01 13:56:48 +00:00
|
|
|
cid := cidtest.ID()
|
2020-11-03 13:12:34 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// prepare
|
2020-11-03 13:12:34 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
small := generateObjectWithCID(t, cid)
|
|
|
|
err := putBig(db, small)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 13:12:34 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
ts := generateObjectWithCID(t, cid)
|
2020-12-08 07:51:34 +00:00
|
|
|
ts.SetType(objectSDK.TypeTombstone)
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, ts)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 13:12:34 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
sg := generateObjectWithCID(t, cid)
|
2020-12-08 07:51:34 +00:00
|
|
|
sg.SetType(objectSDK.TypeStorageGroup)
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, sg)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 13:12:34 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
leftChild := generateObjectWithCID(t, cid)
|
2020-12-08 07:51:34 +00:00
|
|
|
leftChild.InitRelations()
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, leftChild)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 13:12:34 +00:00
|
|
|
|
2022-02-15 12:51:56 +00:00
|
|
|
lock := generateObjectWithCID(t, cid)
|
|
|
|
lock.SetType(objectSDK.TypeLock)
|
|
|
|
err = putBig(db, lock)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
parent := generateObjectWithCID(t, cid)
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
rightChild := generateObjectWithCID(t, cid)
|
|
|
|
rightChild.SetParent(parent)
|
2020-12-08 07:51:34 +00:00
|
|
|
rightChild.SetParentID(parent.ID())
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, rightChild)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
link := generateObjectWithCID(t, cid)
|
|
|
|
link.SetParent(parent)
|
2020-12-08 07:51:34 +00:00
|
|
|
link.SetParentID(parent.ID())
|
|
|
|
link.SetChildren(leftChild.ID(), rightChild.ID())
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, link)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
t.Run("root objects", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddRootFilter()
|
2020-12-10 13:17:45 +00:00
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(small),
|
|
|
|
object.AddressOf(parent),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterPropertyRoot, "", objectSDK.MatchNotPresent)
|
|
|
|
testSelect(t, db, cid, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
t.Run("phy objects", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddPhyFilter()
|
2020-12-10 13:17:45 +00:00
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(small),
|
|
|
|
object.AddressOf(ts),
|
|
|
|
object.AddressOf(sg),
|
|
|
|
object.AddressOf(leftChild),
|
|
|
|
object.AddressOf(rightChild),
|
|
|
|
object.AddressOf(link),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterPropertyPhy, "", objectSDK.MatchNotPresent)
|
|
|
|
testSelect(t, db, cid, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
t.Run("regular objects", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2021-02-01 21:00:40 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeRegular.String(), objectSDK.MatchStringEqual)
|
2020-12-10 13:17:45 +00:00
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(small),
|
|
|
|
object.AddressOf(leftChild),
|
|
|
|
object.AddressOf(rightChild),
|
|
|
|
object.AddressOf(link),
|
|
|
|
object.AddressOf(parent),
|
2020-11-03 14:09:59 +00:00
|
|
|
)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeRegular.String(), objectSDK.MatchStringNotEqual)
|
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(ts),
|
|
|
|
object.AddressOf(sg),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, "", objectSDK.MatchNotPresent)
|
|
|
|
testSelect(t, db, cid, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("tombstone objects", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2021-02-01 21:00:40 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeTombstone.String(), objectSDK.MatchStringEqual)
|
2022-03-03 14:19:05 +00:00
|
|
|
testSelect(t, db, cid, fs, object.AddressOf(ts))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeTombstone.String(), objectSDK.MatchStringNotEqual)
|
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(small),
|
|
|
|
object.AddressOf(leftChild),
|
|
|
|
object.AddressOf(rightChild),
|
|
|
|
object.AddressOf(link),
|
|
|
|
object.AddressOf(parent),
|
|
|
|
object.AddressOf(sg),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, "", objectSDK.MatchNotPresent)
|
|
|
|
testSelect(t, db, cid, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
t.Run("storage group objects", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2021-02-01 21:00:40 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeStorageGroup.String(), objectSDK.MatchStringEqual)
|
2022-03-03 14:19:05 +00:00
|
|
|
testSelect(t, db, cid, fs, object.AddressOf(sg))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeStorageGroup.String(), objectSDK.MatchStringNotEqual)
|
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(small),
|
|
|
|
object.AddressOf(leftChild),
|
|
|
|
object.AddressOf(rightChild),
|
|
|
|
object.AddressOf(link),
|
|
|
|
object.AddressOf(parent),
|
|
|
|
object.AddressOf(ts),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, "", objectSDK.MatchNotPresent)
|
|
|
|
testSelect(t, db, cid, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("objects with parent", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderParent,
|
|
|
|
parent.ID().String(),
|
|
|
|
objectSDK.MatchStringEqual)
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(rightChild),
|
|
|
|
object.AddressOf(link),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderParent, "", objectSDK.MatchNotPresent)
|
|
|
|
testSelect(t, db, cid, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("all objects", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(small),
|
|
|
|
object.AddressOf(ts),
|
|
|
|
object.AddressOf(sg),
|
|
|
|
object.AddressOf(leftChild),
|
|
|
|
object.AddressOf(rightChild),
|
|
|
|
object.AddressOf(link),
|
|
|
|
object.AddressOf(parent),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
|
|
|
})
|
2020-11-03 14:09:59 +00:00
|
|
|
}
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
func TestDB_SelectInhume(t *testing.T) {
|
2020-11-03 14:09:59 +00:00
|
|
|
db := newDB(t)
|
|
|
|
|
2021-12-01 13:56:48 +00:00
|
|
|
cid := cidtest.ID()
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
raw1 := generateObjectWithCID(t, cid)
|
|
|
|
err := putBig(db, raw1)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
raw2 := generateObjectWithCID(t, cid)
|
|
|
|
err = putBig(db, raw2)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw1),
|
|
|
|
object.AddressOf(raw2),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2022-01-26 12:11:13 +00:00
|
|
|
tombstone := addressSDK.NewAddress()
|
2020-12-08 07:51:34 +00:00
|
|
|
tombstone.SetContainerID(cid)
|
|
|
|
tombstone.SetObjectID(testOID())
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = meta.Inhume(db, object.AddressOf(raw2), tombstone)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw1),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
2020-11-03 14:09:59 +00:00
|
|
|
}
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
func TestDB_SelectPayloadHash(t *testing.T) {
|
2020-11-03 14:24:23 +00:00
|
|
|
db := newDB(t)
|
|
|
|
|
2021-12-01 13:56:48 +00:00
|
|
|
cid := cidtest.ID()
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
raw1 := generateObjectWithCID(t, cid)
|
|
|
|
err := putBig(db, raw1)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
raw2 := generateObjectWithCID(t, cid)
|
|
|
|
err = putBig(db, raw2)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderPayloadHash,
|
|
|
|
hex.EncodeToString(raw1.PayloadChecksum().Sum()),
|
|
|
|
objectSDK.MatchStringEqual)
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
testSelect(t, db, cid, fs, object.AddressOf(raw1))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderPayloadHash,
|
|
|
|
hex.EncodeToString(raw1.PayloadChecksum().Sum()),
|
|
|
|
objectSDK.MatchStringNotEqual)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
testSelect(t, db, cid, fs, object.AddressOf(raw2))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderPayloadHash,
|
|
|
|
"",
|
|
|
|
objectSDK.MatchNotPresent)
|
|
|
|
|
|
|
|
testSelect(t, db, cid, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
}
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
func TestDB_SelectWithSlowFilters(t *testing.T) {
|
|
|
|
db := newDB(t)
|
|
|
|
|
2021-12-01 13:56:48 +00:00
|
|
|
cid := cidtest.ID()
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2021-11-10 07:08:33 +00:00
|
|
|
v20 := new(version.Version)
|
2020-12-08 07:51:34 +00:00
|
|
|
v20.SetMajor(2)
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2021-11-10 07:08:33 +00:00
|
|
|
v21 := new(version.Version)
|
2020-12-08 07:51:34 +00:00
|
|
|
v21.SetMajor(2)
|
|
|
|
v21.SetMinor(1)
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
raw1 := generateObjectWithCID(t, cid)
|
2020-12-08 07:51:34 +00:00
|
|
|
raw1.SetPayloadSize(10)
|
|
|
|
raw1.SetCreationEpoch(11)
|
|
|
|
raw1.SetVersion(v20)
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, raw1)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
raw2 := generateObjectWithCID(t, cid)
|
2020-12-08 07:51:34 +00:00
|
|
|
raw2.SetPayloadSize(20)
|
|
|
|
raw2.SetCreationEpoch(21)
|
|
|
|
raw2.SetVersion(v21)
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw2)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
t.Run("object with TZHash", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderHomomorphicHash,
|
|
|
|
hex.EncodeToString(raw1.PayloadHomomorphicHash().Sum()),
|
|
|
|
objectSDK.MatchStringEqual)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
testSelect(t, db, cid, fs, object.AddressOf(raw1))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderHomomorphicHash,
|
|
|
|
hex.EncodeToString(raw1.PayloadHomomorphicHash().Sum()),
|
|
|
|
objectSDK.MatchStringNotEqual)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
testSelect(t, db, cid, fs, object.AddressOf(raw2))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderHomomorphicHash,
|
|
|
|
"",
|
|
|
|
objectSDK.MatchNotPresent)
|
|
|
|
|
|
|
|
testSelect(t, db, cid, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("object with payload length", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderPayloadLength, "20", objectSDK.MatchStringEqual)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
testSelect(t, db, cid, fs, object.AddressOf(raw2))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderPayloadLength, "20", objectSDK.MatchStringNotEqual)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
testSelect(t, db, cid, fs, object.AddressOf(raw1))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderPayloadLength, "", objectSDK.MatchNotPresent)
|
|
|
|
|
|
|
|
testSelect(t, db, cid, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("object with creation epoch", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderCreationEpoch, "11", objectSDK.MatchStringEqual)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
testSelect(t, db, cid, fs, object.AddressOf(raw1))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderCreationEpoch, "11", objectSDK.MatchStringNotEqual)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
testSelect(t, db, cid, fs, object.AddressOf(raw2))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderCreationEpoch, "", objectSDK.MatchNotPresent)
|
|
|
|
|
|
|
|
testSelect(t, db, cid, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("object with version", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddObjectVersionFilter(objectSDK.MatchStringEqual, v21)
|
2022-03-03 14:19:05 +00:00
|
|
|
testSelect(t, db, cid, fs, object.AddressOf(raw2))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectVersionFilter(objectSDK.MatchStringNotEqual, v21)
|
2022-03-03 14:19:05 +00:00
|
|
|
testSelect(t, db, cid, fs, object.AddressOf(raw1))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectVersionFilter(objectSDK.MatchNotPresent, nil)
|
|
|
|
testSelect(t, db, cid, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDB_SelectObjectID(t *testing.T) {
|
2020-11-05 16:54:24 +00:00
|
|
|
db := newDB(t)
|
|
|
|
|
2021-12-01 13:56:48 +00:00
|
|
|
cid := cidtest.ID()
|
2020-11-05 16:54:24 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// prepare
|
2020-11-05 16:54:24 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
parent := generateObjectWithCID(t, cid)
|
2020-11-05 16:54:24 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
regular := generateObjectWithCID(t, cid)
|
2020-12-08 07:51:34 +00:00
|
|
|
regular.SetParentID(parent.ID())
|
2022-03-03 14:19:05 +00:00
|
|
|
regular.SetParent(parent)
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, regular)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
ts := generateObjectWithCID(t, cid)
|
2020-12-08 07:51:34 +00:00
|
|
|
ts.SetType(objectSDK.TypeTombstone)
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, ts)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
sg := generateObjectWithCID(t, cid)
|
2020-12-08 07:51:34 +00:00
|
|
|
sg.SetType(objectSDK.TypeStorageGroup)
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, sg)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-02-15 12:51:56 +00:00
|
|
|
lock := generateObjectWithCID(t, cid)
|
|
|
|
lock.SetType(objectSDK.TypeLock)
|
|
|
|
err = putBig(db, lock)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-02-01 21:00:40 +00:00
|
|
|
t.Run("not present", func(t *testing.T) {
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchNotPresent, nil)
|
|
|
|
testSelect(t, db, cid, fs)
|
|
|
|
})
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
t.Run("not found objects", func(t *testing.T) {
|
2022-03-03 14:19:05 +00:00
|
|
|
raw := generateObjectWithCID(t, cid)
|
2020-11-05 16:54:24 +00:00
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, raw.ID())
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
testSelect(t, db, cid, fs)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, raw.ID())
|
|
|
|
|
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(regular),
|
|
|
|
object.AddressOf(parent),
|
|
|
|
object.AddressOf(sg),
|
|
|
|
object.AddressOf(ts),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("regular objects", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, regular.ID())
|
2022-03-03 14:19:05 +00:00
|
|
|
testSelect(t, db, cid, fs, object.AddressOf(regular))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, regular.ID())
|
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(parent),
|
|
|
|
object.AddressOf(sg),
|
|
|
|
object.AddressOf(ts),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("tombstone objects", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, ts.ID())
|
2022-03-03 14:19:05 +00:00
|
|
|
testSelect(t, db, cid, fs, object.AddressOf(ts))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, ts.ID())
|
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(regular),
|
|
|
|
object.AddressOf(parent),
|
|
|
|
object.AddressOf(sg),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("storage group objects", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, sg.ID())
|
2022-03-03 14:19:05 +00:00
|
|
|
testSelect(t, db, cid, fs, object.AddressOf(sg))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, sg.ID())
|
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(regular),
|
|
|
|
object.AddressOf(parent),
|
|
|
|
object.AddressOf(ts),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
2021-02-01 21:00:40 +00:00
|
|
|
t.Run("parent objects", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, parent.ID())
|
2022-03-03 14:19:05 +00:00
|
|
|
testSelect(t, db, cid, fs, object.AddressOf(parent))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, parent.ID())
|
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(regular),
|
|
|
|
object.AddressOf(sg),
|
|
|
|
object.AddressOf(ts),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("lock objects", func(t *testing.T) {
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, lock.ID())
|
|
|
|
testSelect(t, db, cid, fs, object.AddressOf(lock))
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, lock.ID())
|
|
|
|
testSelect(t, db, cid, fs,
|
|
|
|
object.AddressOf(regular),
|
|
|
|
object.AddressOf(parent),
|
|
|
|
object.AddressOf(sg),
|
|
|
|
object.AddressOf(ts),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
2020-11-05 16:54:24 +00:00
|
|
|
}
|
2020-11-20 07:43:41 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
func TestDB_SelectSplitID(t *testing.T) {
|
2020-11-20 07:43:41 +00:00
|
|
|
db := newDB(t)
|
|
|
|
|
2021-12-01 13:56:48 +00:00
|
|
|
cid := cidtest.ID()
|
2020-11-20 07:43:41 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
child1 := generateObjectWithCID(t, cid)
|
|
|
|
child2 := generateObjectWithCID(t, cid)
|
|
|
|
child3 := generateObjectWithCID(t, cid)
|
2020-11-20 07:43:41 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
split1 := objectSDK.NewSplitID()
|
|
|
|
split2 := objectSDK.NewSplitID()
|
|
|
|
|
|
|
|
child1.SetSplitID(split1)
|
|
|
|
child2.SetSplitID(split1)
|
|
|
|
child3.SetSplitID(split2)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
require.NoError(t, putBig(db, child1))
|
|
|
|
require.NoError(t, putBig(db, child2))
|
|
|
|
require.NoError(t, putBig(db, child3))
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2021-02-01 21:00:40 +00:00
|
|
|
t.Run("not present", func(t *testing.T) {
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderSplitID, "", objectSDK.MatchNotPresent)
|
|
|
|
testSelect(t, db, cid, fs)
|
|
|
|
})
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
t.Run("split id", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderSplitID, split1.String(), objectSDK.MatchStringEqual)
|
2020-12-10 13:17:45 +00:00
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(child1),
|
|
|
|
object.AddressOf(child2),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
2020-11-20 07:43:41 +00:00
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs = objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderSplitID, split2.String(), objectSDK.MatchStringEqual)
|
2022-03-03 14:19:05 +00:00
|
|
|
testSelect(t, db, cid, fs, object.AddressOf(child3))
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("empty split", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderSplitID, "", objectSDK.MatchStringEqual)
|
2020-12-10 13:17:45 +00:00
|
|
|
testSelect(t, db, cid, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("unknown split id", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderSplitID,
|
|
|
|
objectSDK.NewSplitID().String(),
|
|
|
|
objectSDK.MatchStringEqual)
|
2020-12-10 13:17:45 +00:00
|
|
|
testSelect(t, db, cid, fs)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDB_SelectContainerID(t *testing.T) {
|
|
|
|
db := newDB(t)
|
|
|
|
|
2021-12-01 13:56:48 +00:00
|
|
|
cid := cidtest.ID()
|
2020-12-10 13:17:45 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
obj1 := generateObjectWithCID(t, cid)
|
|
|
|
err := putBig(db, obj1)
|
2020-12-10 13:17:45 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
obj2 := generateObjectWithCID(t, cid)
|
|
|
|
err = putBig(db, obj2)
|
2020-12-10 13:17:45 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
t.Run("same cid", func(t *testing.T) {
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectContainerIDFilter(objectSDK.MatchStringEqual, cid)
|
|
|
|
|
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(obj1),
|
|
|
|
object.AddressOf(obj2),
|
2020-12-10 13:17:45 +00:00
|
|
|
)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectContainerIDFilter(objectSDK.MatchStringNotEqual, cid)
|
|
|
|
|
|
|
|
testSelect(t, db, cid, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(obj1),
|
|
|
|
object.AddressOf(obj2),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectContainerIDFilter(objectSDK.MatchNotPresent, cid)
|
|
|
|
|
|
|
|
testSelect(t, db, cid, fs)
|
2020-12-10 13:17:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("not same cid", func(t *testing.T) {
|
2021-12-01 13:56:48 +00:00
|
|
|
newCID := cidtest.ID()
|
2020-12-10 13:17:45 +00:00
|
|
|
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectContainerIDFilter(objectSDK.MatchStringEqual, newCID)
|
|
|
|
|
|
|
|
testSelect(t, db, cid, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
2020-11-20 07:43:41 +00:00
|
|
|
}
|