2020-12-08 07:51:34 +00:00
|
|
|
package meta_test
|
2020-10-30 13:42:24 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-12-08 07:51:34 +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"
|
2020-10-30 13:42:24 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
func TestDB_PutBlobovnicaUpdate(t *testing.T) {
|
|
|
|
db := newDB(t)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
raw1 := generateRawObject(t)
|
|
|
|
blobovniczaID := blobovnicza.ID{1, 2, 3, 4}
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// put one object with blobovniczaID
|
2020-12-08 09:56:14 +00:00
|
|
|
err := meta.Put(db, raw1.Object(), &blobovniczaID)
|
2020-10-30 13:42:24 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
fetchedBlobovniczaID, err := meta.IsSmall(db, raw1.Object().Address())
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, &blobovniczaID, fetchedBlobovniczaID)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
t.Run("update blobovniczaID", func(t *testing.T) {
|
|
|
|
newID := blobovnicza.ID{5, 6, 7, 8}
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
err := meta.Put(db, raw1.Object(), &newID)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
fetchedBlobovniczaID, err := meta.IsSmall(db, raw1.Object().Address())
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, &newID, fetchedBlobovniczaID)
|
|
|
|
})
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
t.Run("update blobovniczaID on bad object", func(t *testing.T) {
|
|
|
|
raw2 := generateRawObject(t)
|
2020-12-08 09:56:14 +00:00
|
|
|
err := putBig(db, raw2.Object())
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2020-12-08 09:56:14 +00:00
|
|
|
fetchedBlobovniczaID, err := meta.IsSmall(db, raw2.Object().Address())
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, fetchedBlobovniczaID)
|
|
|
|
})
|
2020-10-30 13:42:24 +00:00
|
|
|
}
|