Some checks failed
ci/woodpecker/push/pre-commit Pipeline failed
Move testing utils from tests in local_object_storage package to unified testutil package Signed-off-by: Airat Arifullin <aarifullin@yadro.com>
68 lines
1.9 KiB
Go
68 lines
1.9 KiB
Go
package meta_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDB_StorageID(t *testing.T) {
|
|
db := newDB(t)
|
|
|
|
raw1 := testutil.GenerateObject()
|
|
raw2 := testutil.GenerateObject()
|
|
|
|
storageID := []byte{1, 2, 3, 4}
|
|
|
|
// check StorageID from empty database
|
|
fetchedStorageID, err := metaStorageID(db, object.AddressOf(raw1))
|
|
require.NoError(t, err)
|
|
require.Nil(t, fetchedStorageID)
|
|
|
|
// put one object with storageID
|
|
err = metaPut(db, raw1, storageID)
|
|
require.NoError(t, err)
|
|
|
|
// put one object without storageID
|
|
err = putBig(db, raw2)
|
|
require.NoError(t, err)
|
|
|
|
// check StorageID for object without storageID
|
|
fetchedStorageID, err = metaStorageID(db, object.AddressOf(raw2))
|
|
require.NoError(t, err)
|
|
require.Nil(t, fetchedStorageID)
|
|
|
|
// check StorageID for object with storageID
|
|
fetchedStorageID, err = metaStorageID(db, object.AddressOf(raw1))
|
|
require.NoError(t, err)
|
|
require.Equal(t, storageID, fetchedStorageID)
|
|
|
|
t.Run("update", func(t *testing.T) {
|
|
require.NoError(t, metaUpdateStorageID(db, object.AddressOf(raw2), storageID))
|
|
|
|
fetchedStorageID, err = metaStorageID(db, object.AddressOf(raw2))
|
|
require.NoError(t, err)
|
|
require.Equal(t, storageID, fetchedStorageID)
|
|
})
|
|
}
|
|
|
|
func metaUpdateStorageID(db *meta.DB, addr oid.Address, id []byte) error {
|
|
var sidPrm meta.UpdateStorageIDPrm
|
|
sidPrm.SetAddress(addr)
|
|
sidPrm.SetStorageID(id)
|
|
|
|
_, err := db.UpdateStorageID(sidPrm)
|
|
return err
|
|
}
|
|
|
|
func metaStorageID(db *meta.DB, addr oid.Address) ([]byte, error) {
|
|
var sidPrm meta.StorageIDPrm
|
|
sidPrm.SetAddress(addr)
|
|
|
|
r, err := db.StorageID(sidPrm)
|
|
return r.StorageID(), err
|
|
}
|