From 088bfac90302bd3f35793175fab3cdff9cc3b011 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 29 Nov 2024 23:17:19 +0100 Subject: [PATCH] fs: test both fd and path-based implementation --- internal/fs/fs_local_test.go | 44 +++++++++++++++++++++++++++---- internal/fs/fs_local_unix_test.go | 4 +++ 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/internal/fs/fs_local_test.go b/internal/fs/fs_local_test.go index 83f5b6365..9e6f7fcae 100644 --- a/internal/fs/fs_local_test.go +++ b/internal/fs/fs_local_test.go @@ -4,6 +4,7 @@ import ( "io" "os" "path/filepath" + "runtime" "slices" "testing" @@ -18,6 +19,25 @@ type fsLocalMetadataTestcase struct { nodeType restic.NodeType } +func testHandleVariants(t *testing.T, test func(t *testing.T)) { + testVariant(t, "path-based", false, test) + + if runtime.GOOS == "linux" || runtime.GOOS == "windows" || runtime.GOOS == "darwin" { + testVariant(t, "fd-based", true, test) + } +} + +func testVariant(t *testing.T, name string, useFd bool, test func(t *testing.T)) { + t.Run(name, func(t *testing.T) { + testOverwriteUseFd = &useFd + defer func() { + testOverwriteUseFd = nil + }() + + test(t) + }) +} + func TestFSLocalMetadata(t *testing.T) { for _, test := range []fsLocalMetadataTestcase{ { @@ -51,7 +71,9 @@ func TestFSLocalMetadata(t *testing.T) { nodeType: restic.NodeTypeFile, }, } { - runFSLocalTestcase(t, test) + testHandleVariants(t, func(t *testing.T) { + runFSLocalTestcase(t, test) + }) } } @@ -104,8 +126,10 @@ func assertFIEqual(t *testing.T, want os.FileInfo, got *ExtendedFileInfo) { } func TestFSLocalRead(t *testing.T) { - testFSLocalRead(t, false) - testFSLocalRead(t, true) + testHandleVariants(t, func(t *testing.T) { + testFSLocalRead(t, false) + testFSLocalRead(t, true) + }) } func testFSLocalRead(t *testing.T, makeReadable bool) { @@ -136,8 +160,10 @@ func openReadable(t *testing.T, path string, useMakeReadable bool) File { } func TestFSLocalReaddir(t *testing.T) { - testFSLocalReaddir(t, false) - testFSLocalReaddir(t, true) + testHandleVariants(t, func(t *testing.T) { + testFSLocalReaddir(t, false) + testFSLocalReaddir(t, true) + }) } func testFSLocalReaddir(t *testing.T, makeReadable bool) { @@ -159,6 +185,10 @@ func testFSLocalReaddir(t *testing.T, makeReadable bool) { } func TestFSLocalReadableRace(t *testing.T) { + testHandleVariants(t, testFSLocalReadableRace) +} + +func testFSLocalReadableRace(t *testing.T) { tmp := t.TempDir() path := filepath.Join(tmp, "item") testdata := "example" @@ -185,6 +215,10 @@ func TestFSLocalReadableRace(t *testing.T) { } func TestFSLocalTypeChange(t *testing.T) { + testHandleVariants(t, testFSLocalTypeChange) +} + +func testFSLocalTypeChange(t *testing.T) { tmp := t.TempDir() path := filepath.Join(tmp, "item") testdata := "example" diff --git a/internal/fs/fs_local_unix_test.go b/internal/fs/fs_local_unix_test.go index 5bcb5efd0..3e67a1d1f 100644 --- a/internal/fs/fs_local_unix_test.go +++ b/internal/fs/fs_local_unix_test.go @@ -11,6 +11,10 @@ import ( ) func TestFSLocalMetadataUnix(t *testing.T) { + testHandleVariants(t, testFSLocalMetadataUnix) +} + +func testFSLocalMetadataUnix(t *testing.T) { for _, test := range []fsLocalMetadataTestcase{ { name: "socket",