forked from TrueCloudLab/frostfs-node
[#139] test: Add test storage implementation
This aims to reduce the usage of chmod hackery to induce or simulate OS-related failures. Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
This commit is contained in:
parent
e843e7f090
commit
341fe1688f
20 changed files with 617 additions and 208 deletions
|
@ -2,11 +2,11 @@ package blobstor
|
|||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
objectCore "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/teststore"
|
||||
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
||||
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
||||
|
@ -20,8 +20,10 @@ func TestExists(t *testing.T) {
|
|||
|
||||
const smallSizeLimit = 512
|
||||
|
||||
b := New(
|
||||
WithStorages(defaultStorages(dir, smallSizeLimit)))
|
||||
storages, _, largeFileStorage := defaultTestStorages(dir, smallSizeLimit)
|
||||
|
||||
b := New(WithStorages(storages))
|
||||
|
||||
require.NoError(t, b.Open(false))
|
||||
require.NoError(t, b.Init())
|
||||
|
||||
|
@ -33,7 +35,7 @@ func TestExists(t *testing.T) {
|
|||
for i := range objects {
|
||||
var prm common.PutPrm
|
||||
prm.Object = objects[i]
|
||||
_, err = b.Put(prm)
|
||||
_, err := b.Put(prm)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
@ -51,20 +53,10 @@ func TestExists(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.False(t, res.Exists)
|
||||
|
||||
t.Run("corrupt direcrory", func(t *testing.T) {
|
||||
var bigDir string
|
||||
de, err := os.ReadDir(dir)
|
||||
require.NoError(t, err)
|
||||
for i := range de {
|
||||
if de[i].Name() != blobovniczaDir {
|
||||
bigDir = filepath.Join(dir, de[i].Name())
|
||||
break
|
||||
}
|
||||
}
|
||||
require.NotEmpty(t, bigDir)
|
||||
|
||||
require.NoError(t, os.Chmod(dir, 0))
|
||||
t.Cleanup(func() { require.NoError(t, os.Chmod(dir, 0777)) })
|
||||
t.Run("corrupt directory", func(t *testing.T) {
|
||||
largeFileStorage.SetOption(teststore.WithExists(func(common.ExistsPrm) (common.ExistsRes, error) {
|
||||
return common.ExistsRes{}, teststore.ErrDiskExploded
|
||||
}))
|
||||
|
||||
// Object exists, first error is logged.
|
||||
prm.Address = objectCore.AddressOf(objects[0])
|
||||
|
@ -76,6 +68,7 @@ func TestExists(t *testing.T) {
|
|||
prm.Address = objectCore.AddressOf(objects[1])
|
||||
_, err = b.Exists(prm)
|
||||
require.Error(t, err)
|
||||
require.ErrorIs(t, err, teststore.ErrDiskExploded)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue