From 59325e323ee4a98b628c2e449a7b48ffe64e4e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20L=C3=B3pez?= <1953782+julio-lopez@users.noreply.github.com> Date: Wed, 18 Feb 2026 22:33:18 -0800 Subject: [PATCH] test(providers): update injected error message (#5165) * test(providers): update injected error message * test(provider): minor cleanups in fs_storage_test.go --- .../filesystem/filesystem_storage_test.go | 39 +++++-------------- .../filesystem/osinterface_mock_other_test.go | 2 +- .../filesystem/osinterface_mock_unix_test.go | 2 +- 3 files changed, 12 insertions(+), 31 deletions(-) diff --git a/repo/blob/filesystem/filesystem_storage_test.go b/repo/blob/filesystem/filesystem_storage_test.go index 273e72c7f..2b06a5696 100644 --- a/repo/blob/filesystem/filesystem_storage_test.go +++ b/repo/blob/filesystem/filesystem_storage_test.go @@ -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{})) diff --git a/repo/blob/filesystem/osinterface_mock_other_test.go b/repo/blob/filesystem/osinterface_mock_other_test.go index f75e59872..d24317004 100644 --- a/repo/blob/filesystem/osinterface_mock_other_test.go +++ b/repo/blob/filesystem/osinterface_mock_other_test.go @@ -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) diff --git a/repo/blob/filesystem/osinterface_mock_unix_test.go b/repo/blob/filesystem/osinterface_mock_unix_test.go index d2ae3143a..88b7ed5ae 100644 --- a/repo/blob/filesystem/osinterface_mock_unix_test.go +++ b/repo/blob/filesystem/osinterface_mock_unix_test.go @@ -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 {