2020-11-23 13:30:56 +00:00
|
|
|
package meta_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
2020-11-23 13:30:56 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
2020-12-08 09:56:14 +00:00
|
|
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
2022-07-12 14:42:55 +00:00
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2020-11-23 13:30:56 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDB_IsSmall(t *testing.T) {
|
|
|
|
db := newDB(t)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
raw1 := generateObject(t)
|
|
|
|
raw2 := generateObject(t)
|
2020-11-23 13:30:56 +00:00
|
|
|
|
|
|
|
blobovniczaID := blobovnicza.ID{1, 2, 3, 4}
|
|
|
|
|
|
|
|
// check IsSmall from empty database
|
2022-07-12 14:42:55 +00:00
|
|
|
fetchedBlobovniczaID, err := metaIsSmall(db, object.AddressOf(raw1))
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, fetchedBlobovniczaID)
|
|
|
|
|
|
|
|
// put one object with blobovniczaID
|
2022-07-12 14:42:55 +00:00
|
|
|
err = metaPut(db, raw1, &blobovniczaID)
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// put one object without blobovniczaID
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw2)
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// check IsSmall for object without blobovniczaID
|
2022-07-12 14:42:55 +00:00
|
|
|
fetchedBlobovniczaID, err = metaIsSmall(db, object.AddressOf(raw2))
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, fetchedBlobovniczaID)
|
|
|
|
|
|
|
|
// check IsSmall for object with blobovniczaID
|
2022-07-12 14:42:55 +00:00
|
|
|
fetchedBlobovniczaID, err = metaIsSmall(db, object.AddressOf(raw1))
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-27 09:03:35 +00:00
|
|
|
require.Equal(t, &blobovniczaID, fetchedBlobovniczaID)
|
2020-11-23 13:30:56 +00:00
|
|
|
}
|
2022-07-12 14:42:55 +00:00
|
|
|
|
|
|
|
func metaIsSmall(db *meta.DB, addr oid.Address) (*blobovnicza.ID, error) {
|
|
|
|
var isSmallPrm meta.IsSmallPrm
|
|
|
|
isSmallPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
r, err := db.IsSmall(isSmallPrm)
|
|
|
|
return r.BlobovniczaID(), err
|
|
|
|
}
|