mirror of
https://github.com/kopia/kopia.git
synced 2026-03-25 17:41:11 -04:00
test(providers): update injected error message (#5165)
* test(providers): update injected error message * test(provider): minor cleanups in fs_storage_test.go
This commit is contained in:
@@ -214,18 +214,15 @@ func TestFileStorage_GetMetadata_RetriesOnError(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := testlogging.Context(t)
|
||||
|
||||
dataDir := testutil.TempDirectory(t)
|
||||
|
||||
osi := newMockOS()
|
||||
|
||||
osi.statRemainingErrors.Store(1)
|
||||
|
||||
st, err := New(ctx, &Options{
|
||||
Path: dataDir,
|
||||
Options: sharded.Options{
|
||||
DirectoryShards: []int{5, 2},
|
||||
},
|
||||
osInterfaceOverride: osi,
|
||||
}, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -233,7 +230,7 @@ func TestFileStorage_GetMetadata_RetriesOnError(t *testing.T) {
|
||||
|
||||
require.NoError(t, st.PutBlob(ctx, "someblob1234567812345678", gather.FromSlice([]byte{1, 2, 3}), blob.PutOptions{}))
|
||||
|
||||
asFsImpl(t, st).osi = osi
|
||||
osi.statRemainingErrors.Store(1)
|
||||
|
||||
_, err = st.GetMetadata(ctx, "someblob1234567812345678")
|
||||
require.NoError(t, err)
|
||||
@@ -275,11 +272,10 @@ func TestFileStorage_PutBlob_RetriesOnErrors(t *testing.T) {
|
||||
Options: sharded.Options{
|
||||
DirectoryShards: []int{5, 2},
|
||||
},
|
||||
osInterfaceOverride: osi,
|
||||
}, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
asFsImpl(t, st).osi = osi
|
||||
|
||||
defer st.Close(ctx)
|
||||
|
||||
require.NoError(t, st.PutBlob(ctx, "someblob1234567812345678", gather.FromSlice([]byte{1, 2, 3}), blob.PutOptions{}))
|
||||
@@ -316,11 +312,10 @@ func TestFileStorage_DeleteBlob_ErrorHandling(t *testing.T) {
|
||||
Options: sharded.Options{
|
||||
DirectoryShards: []int{5, 2},
|
||||
},
|
||||
osInterfaceOverride: osi,
|
||||
}, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
asFsImpl(t, st).osi = osi
|
||||
|
||||
defer st.Close(ctx)
|
||||
|
||||
require.ErrorIs(t, st.DeleteBlob(ctx, "someblob1234567812345678"), errNonRetriable)
|
||||
@@ -330,14 +325,11 @@ func TestFileStorage_New_MkdirAllFailureIsIgnored(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := testlogging.Context(t)
|
||||
|
||||
dataDir := testutil.TempDirectory(t)
|
||||
|
||||
osi := newMockOS()
|
||||
osi.mkdirAllRemainingErrors.Store(1)
|
||||
|
||||
st, err := New(ctx, &Options{
|
||||
Path: dataDir,
|
||||
Path: testutil.TempDirectory(t),
|
||||
Options: sharded.Options{
|
||||
DirectoryShards: []int{5, 2},
|
||||
},
|
||||
@@ -352,15 +344,12 @@ func TestFileStorage_New_ChecksDirectoryExistence(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := testlogging.Context(t)
|
||||
|
||||
dataDir := testutil.TempDirectory(t)
|
||||
|
||||
osi := newMockOS()
|
||||
|
||||
osi.statRemainingErrors.Store(1)
|
||||
|
||||
st, err := New(ctx, &Options{
|
||||
Path: dataDir,
|
||||
Path: testutil.TempDirectory(t),
|
||||
Options: sharded.Options{
|
||||
DirectoryShards: []int{5, 2},
|
||||
},
|
||||
@@ -374,24 +363,20 @@ func TestFileStorage_ListBlobs_ErrorHandling(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := testlogging.Context(t)
|
||||
|
||||
dataDir := testutil.TempDirectory(t)
|
||||
|
||||
osi := newMockOS()
|
||||
|
||||
osi.readDirRemainingErrors.Store(3)
|
||||
osi.readDirRemainingFileDeletedDirEntry.Store(3)
|
||||
|
||||
st, err := New(ctx, &Options{
|
||||
Path: dataDir,
|
||||
Path: testutil.TempDirectory(t),
|
||||
Options: sharded.Options{
|
||||
DirectoryShards: []int{5, 2},
|
||||
},
|
||||
osInterfaceOverride: osi,
|
||||
}, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
asFsImpl(t, st).osi = osi
|
||||
|
||||
defer st.Close(ctx)
|
||||
|
||||
require.NoError(t, st.ListBlobs(ctx, "", func(bm blob.Metadata) error {
|
||||
@@ -415,21 +400,17 @@ func TestFileStorage_TouchBlob_ErrorHandling(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := testlogging.Context(t)
|
||||
|
||||
dataDir := testutil.TempDirectory(t)
|
||||
|
||||
osi := newMockOS()
|
||||
|
||||
st, err := New(ctx, &Options{
|
||||
Path: dataDir,
|
||||
Path: testutil.TempDirectory(t),
|
||||
Options: sharded.Options{
|
||||
DirectoryShards: []int{5, 2},
|
||||
},
|
||||
osInterfaceOverride: osi,
|
||||
}, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
asFsImpl(t, st).osi = osi
|
||||
|
||||
defer st.Close(ctx)
|
||||
|
||||
require.NoError(t, st.PutBlob(ctx, "someblob1234567812345678", gather.FromSlice([]byte{1, 2, 3}), blob.PutOptions{}))
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
func (osi *mockOS) Stat(fname string) (fs.FileInfo, error) {
|
||||
if osi.statRemainingErrors.Add(-1) >= 0 {
|
||||
return nil, &os.PathError{Op: "stat", Err: errors.New("underlying problem")}
|
||||
return nil, &os.PathError{Op: "stat", Err: errors.New("injected stat error")}
|
||||
}
|
||||
|
||||
return osi.osInterface.Stat(fname)
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
func (osi *mockOS) Stat(fname string) (fs.FileInfo, error) {
|
||||
if osi.statRemainingErrors.Add(-1) >= 0 {
|
||||
return nil, &os.PathError{Op: "stat", Err: errors.New("underlying problem")}
|
||||
return nil, &os.PathError{Op: "stat", Err: errors.New("injected stat error")}
|
||||
}
|
||||
|
||||
if osi.eStaleRemainingErrors.Add(-1) >= 0 {
|
||||
|
||||
Reference in New Issue
Block a user