1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2025-03-09 13:53:03 +00:00

fs: test both fd and path-based implementation

This commit is contained in:
Michael Eischer 2024-11-29 23:17:19 +01:00
parent 9a0259cd0f
commit 088bfac903
2 changed files with 43 additions and 5 deletions

View file

@ -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"

View file

@ -11,6 +11,10 @@ import (
)
func TestFSLocalMetadataUnix(t *testing.T) {
testHandleVariants(t, testFSLocalMetadataUnix)
}
func testFSLocalMetadataUnix(t *testing.T) {
for _, test := range []fsLocalMetadataTestcase{
{
name: "socket",