Alejandro Lopez
ae8be495c8
Some checks failed
Vulncheck / Vulncheck (pull_request) Successful in 2m36s
Build / Build Components (1.21) (pull_request) Successful in 3m33s
DCO action / DCO (pull_request) Successful in 3m33s
Tests and linters / Staticcheck (pull_request) Successful in 4m15s
Tests and linters / Lint (pull_request) Successful in 5m31s
Build / Build Components (1.20) (pull_request) Successful in 7m2s
Tests and linters / Tests with -race (pull_request) Failing after 8m51s
Tests and linters / Tests (1.20) (pull_request) Successful in 9m55s
Tests and linters / Tests (1.21) (pull_request) Successful in 10m6s
Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
84 lines
2 KiB
Go
84 lines
2 KiB
Go
package meta_test
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
"testing"
|
|
|
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/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"
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type epochState struct{ e uint64 }
|
|
|
|
func (s epochState) CurrentEpoch() uint64 {
|
|
if s.e != 0 {
|
|
return s.e
|
|
}
|
|
|
|
return 0
|
|
}
|
|
|
|
// saves "big" object in DB.
|
|
func putBig(db *meta.DB, obj *objectSDK.Object) error {
|
|
return metaPut(db, obj, nil)
|
|
}
|
|
|
|
func testSelect(t *testing.T, db *meta.DB, cnr cid.ID, fs objectSDK.SearchFilters, exp ...oid.Address) {
|
|
res, err := metaSelect(db, cnr, fs)
|
|
require.NoError(t, err)
|
|
require.Len(t, res, len(exp))
|
|
|
|
for i := range exp {
|
|
require.Contains(t, res, exp[i])
|
|
}
|
|
}
|
|
|
|
func newDB(t testing.TB, opts ...meta.Option) *meta.DB {
|
|
bdb := meta.New(
|
|
append([]meta.Option{
|
|
meta.WithPath(filepath.Join(t.TempDir(), "metabase")),
|
|
meta.WithPermissions(0600),
|
|
meta.WithEpochState(epochState{}),
|
|
}, opts...)...,
|
|
)
|
|
|
|
require.NoError(t, bdb.Open(false))
|
|
require.NoError(t, bdb.Init())
|
|
|
|
t.Cleanup(func() {
|
|
bdb.Close()
|
|
os.Remove(bdb.DumpInfo().Path)
|
|
})
|
|
|
|
return bdb
|
|
}
|
|
|
|
func checkExpiredObjects(t *testing.T, db *meta.DB, f func(exp, nonExp *objectSDK.Object)) {
|
|
expObj := testutil.GenerateObject()
|
|
setExpiration(expObj, currEpoch-1)
|
|
|
|
require.NoError(t, metaPut(db, expObj, nil))
|
|
|
|
nonExpObj := testutil.GenerateObject()
|
|
setExpiration(nonExpObj, currEpoch)
|
|
|
|
require.NoError(t, metaPut(db, nonExpObj, nil))
|
|
|
|
f(expObj, nonExpObj)
|
|
}
|
|
|
|
func setExpiration(o *objectSDK.Object, epoch uint64) {
|
|
var attr objectSDK.Attribute
|
|
|
|
attr.SetKey(objectV2.SysAttributeExpEpoch)
|
|
attr.SetValue(strconv.FormatUint(epoch, 10))
|
|
|
|
o.SetAttributes(append(o.Attributes(), attr)...)
|
|
}
|