mirror of
https://github.com/restic/restic.git
synced 2025-03-09 21:57:08 +00:00
fs: test both fd and path-based implementation
This commit is contained in:
parent
9a0259cd0f
commit
088bfac903
2 changed files with 43 additions and 5 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"slices"
|
"slices"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -18,6 +19,25 @@ type fsLocalMetadataTestcase struct {
|
||||||
nodeType restic.NodeType
|
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) {
|
func TestFSLocalMetadata(t *testing.T) {
|
||||||
for _, test := range []fsLocalMetadataTestcase{
|
for _, test := range []fsLocalMetadataTestcase{
|
||||||
{
|
{
|
||||||
|
@ -51,7 +71,9 @@ func TestFSLocalMetadata(t *testing.T) {
|
||||||
nodeType: restic.NodeTypeFile,
|
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) {
|
func TestFSLocalRead(t *testing.T) {
|
||||||
testFSLocalRead(t, false)
|
testHandleVariants(t, func(t *testing.T) {
|
||||||
testFSLocalRead(t, true)
|
testFSLocalRead(t, false)
|
||||||
|
testFSLocalRead(t, true)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testFSLocalRead(t *testing.T, makeReadable bool) {
|
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) {
|
func TestFSLocalReaddir(t *testing.T) {
|
||||||
testFSLocalReaddir(t, false)
|
testHandleVariants(t, func(t *testing.T) {
|
||||||
testFSLocalReaddir(t, true)
|
testFSLocalReaddir(t, false)
|
||||||
|
testFSLocalReaddir(t, true)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testFSLocalReaddir(t *testing.T, makeReadable bool) {
|
func testFSLocalReaddir(t *testing.T, makeReadable bool) {
|
||||||
|
@ -159,6 +185,10 @@ func testFSLocalReaddir(t *testing.T, makeReadable bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFSLocalReadableRace(t *testing.T) {
|
func TestFSLocalReadableRace(t *testing.T) {
|
||||||
|
testHandleVariants(t, testFSLocalReadableRace)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testFSLocalReadableRace(t *testing.T) {
|
||||||
tmp := t.TempDir()
|
tmp := t.TempDir()
|
||||||
path := filepath.Join(tmp, "item")
|
path := filepath.Join(tmp, "item")
|
||||||
testdata := "example"
|
testdata := "example"
|
||||||
|
@ -185,6 +215,10 @@ func TestFSLocalReadableRace(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFSLocalTypeChange(t *testing.T) {
|
func TestFSLocalTypeChange(t *testing.T) {
|
||||||
|
testHandleVariants(t, testFSLocalTypeChange)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testFSLocalTypeChange(t *testing.T) {
|
||||||
tmp := t.TempDir()
|
tmp := t.TempDir()
|
||||||
path := filepath.Join(tmp, "item")
|
path := filepath.Join(tmp, "item")
|
||||||
testdata := "example"
|
testdata := "example"
|
||||||
|
|
|
@ -11,6 +11,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFSLocalMetadataUnix(t *testing.T) {
|
func TestFSLocalMetadataUnix(t *testing.T) {
|
||||||
|
testHandleVariants(t, testFSLocalMetadataUnix)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testFSLocalMetadataUnix(t *testing.T) {
|
||||||
for _, test := range []fsLocalMetadataTestcase{
|
for _, test := range []fsLocalMetadataTestcase{
|
||||||
{
|
{
|
||||||
name: "socket",
|
name: "socket",
|
||||||
|
|
Loading…
Add table
Reference in a new issue