2020-11-23 13:30:56 +00:00
|
|
|
package meta_test
|
|
|
|
|
|
|
|
import (
|
2020-12-03 09:31:51 +00:00
|
|
|
"errors"
|
2020-11-23 13:30:56 +00:00
|
|
|
"testing"
|
|
|
|
|
2020-11-27 07:59:47 +00:00
|
|
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
2020-11-23 13:30:56 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDB_Exists(t *testing.T) {
|
|
|
|
db := newDB(t)
|
|
|
|
defer releaseDB(db)
|
|
|
|
|
2020-11-27 07:59:47 +00:00
|
|
|
t.Run("no object", func(t *testing.T) {
|
|
|
|
nonExist := generateRawObject(t)
|
|
|
|
exists, err := db.Exists(nonExist.Object().Address())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, exists)
|
|
|
|
})
|
2020-11-23 13:30:56 +00:00
|
|
|
|
2020-11-27 07:59:47 +00:00
|
|
|
t.Run("regular object", func(t *testing.T) {
|
|
|
|
regular := generateRawObject(t)
|
|
|
|
err := db.Put(regular.Object(), nil)
|
|
|
|
require.NoError(t, err)
|
2020-11-23 13:30:56 +00:00
|
|
|
|
2020-11-27 07:59:47 +00:00
|
|
|
exists, err := db.Exists(regular.Object().Address())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, exists)
|
|
|
|
})
|
2020-11-23 13:30:56 +00:00
|
|
|
|
2020-11-27 07:59:47 +00:00
|
|
|
t.Run("tombstone object", func(t *testing.T) {
|
|
|
|
ts := generateRawObject(t)
|
|
|
|
ts.SetType(objectSDK.TypeTombstone)
|
2020-11-23 13:30:56 +00:00
|
|
|
|
2020-11-27 07:59:47 +00:00
|
|
|
err := db.Put(ts.Object(), nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
exists, err := db.Exists(ts.Object().Address())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, exists)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("storage group object", func(t *testing.T) {
|
|
|
|
sg := generateRawObject(t)
|
|
|
|
sg.SetType(objectSDK.TypeStorageGroup)
|
|
|
|
|
|
|
|
err := db.Put(sg.Object(), nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
exists, err := db.Exists(sg.Object().Address())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, exists)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("virtual object", func(t *testing.T) {
|
|
|
|
cid := testCID()
|
|
|
|
parent := generateRawObjectWithCID(t, cid)
|
|
|
|
|
|
|
|
child := generateRawObjectWithCID(t, cid)
|
|
|
|
child.SetParent(parent.Object().SDK())
|
2020-11-27 09:03:35 +00:00
|
|
|
child.SetParentID(parent.ID())
|
2020-11-27 07:59:47 +00:00
|
|
|
|
|
|
|
err := db.Put(child.Object(), nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-12-03 09:31:51 +00:00
|
|
|
_, err = db.Exists(parent.Object().Address())
|
|
|
|
|
|
|
|
var expectedErr *objectSDK.SplitInfoError
|
|
|
|
require.True(t, errors.As(err, &expectedErr))
|
2020-11-27 07:59:47 +00:00
|
|
|
})
|
2020-11-23 13:30:56 +00:00
|
|
|
}
|