forked from TrueCloudLab/frostfs-node
64 lines
2 KiB
Go
64 lines
2 KiB
Go
package blobovniczatree
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/internal/blobstortest"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger/test"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestExistsInvalidStorageID(t *testing.T) {
|
|
dir := t.TempDir()
|
|
b := NewBlobovniczaTree(
|
|
WithLogger(test.NewLogger(t, true)),
|
|
WithObjectSizeLimit(1024),
|
|
WithBlobovniczaShallowWidth(2),
|
|
WithBlobovniczaShallowDepth(2),
|
|
WithRootPath(dir),
|
|
WithBlobovniczaSize(1<<20))
|
|
require.NoError(t, b.Open(false))
|
|
require.NoError(t, b.Init())
|
|
t.Cleanup(func() { _ = b.Close() })
|
|
|
|
obj := blobstortest.NewObject(1024)
|
|
addr := object.AddressOf(obj)
|
|
d, err := obj.Marshal()
|
|
require.NoError(t, err)
|
|
|
|
putRes, err := b.Put(context.Background(), common.PutPrm{Address: addr, RawData: d, DontCompress: true})
|
|
require.NoError(t, err)
|
|
|
|
t.Run("valid but wrong storage id", func(t *testing.T) {
|
|
// "0/X/Y" <-> "1/X/Y"
|
|
storageID := bytes.Clone(putRes.StorageID)
|
|
if storageID[0] == '0' {
|
|
storageID[0]++
|
|
} else {
|
|
storageID[0]--
|
|
}
|
|
|
|
res, err := b.Exists(context.Background(), common.ExistsPrm{Address: addr, StorageID: storageID})
|
|
require.NoError(t, err)
|
|
require.False(t, res.Exists)
|
|
})
|
|
|
|
t.Run("valid id but corrupted file", func(t *testing.T) {
|
|
relBadFileDir := filepath.Join("9", "0")
|
|
badFileName := "0"
|
|
|
|
// An invalid boltdb file is created so that it returns an error when opened
|
|
require.NoError(t, os.MkdirAll(filepath.Join(dir, relBadFileDir), os.ModePerm))
|
|
require.NoError(t, os.WriteFile(filepath.Join(dir, relBadFileDir, badFileName), []byte("not a boltdb file content"), 0o777))
|
|
|
|
res, err := b.Exists(context.Background(), common.ExistsPrm{Address: addr, StorageID: []byte(filepath.Join(relBadFileDir, badFileName))})
|
|
require.Error(t, err)
|
|
require.False(t, res.Exists)
|
|
})
|
|
}
|