feat: Add negative initialization tests
This commit is contained in:
@@ -922,7 +922,7 @@ func runIntegrationTest(t *testing.T, name string, action func(t *testing.T, tmp
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, cfg := range stfsConfigs {
|
for _, cfg := range stfsConfigs {
|
||||||
t.Run(fmt.Sprintf(`%v config=%v`, "Initialize empty integration", stfsPermutation{
|
t.Run(fmt.Sprintf(`%v config=%v`, name, stfsPermutation{
|
||||||
cfg.recordSize,
|
cfg.recordSize,
|
||||||
cfg.readOnly,
|
cfg.readOnly,
|
||||||
|
|
||||||
@@ -965,31 +965,61 @@ var initializeEmptyTests = []struct {
|
|||||||
name string
|
name string
|
||||||
args initializeEmptyArgs
|
args initializeEmptyArgs
|
||||||
wantRoot string
|
wantRoot string
|
||||||
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"Can run integration test for empty initialization and absolute root directory /",
|
"Can run integration test for empty initialization and absolute root directory /",
|
||||||
initializeEmptyArgs{"/", os.ModePerm},
|
initializeEmptyArgs{"/", os.ModePerm},
|
||||||
"/",
|
"/",
|
||||||
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Can run integration test for empty initialization and absolute root directory /test",
|
"Can not run integration test for empty initialization and absolute root directory /test",
|
||||||
initializeEmptyArgs{"/test", os.ModePerm},
|
initializeEmptyArgs{"/test", os.ModePerm},
|
||||||
"/test",
|
"/test",
|
||||||
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Can run integration test for empty initialization and absolute root directory /test/yes",
|
"Can not run integration test for empty initialization and absolute root directory /test/yes",
|
||||||
initializeEmptyArgs{"/test/yes", os.ModePerm},
|
initializeEmptyArgs{"/test/yes", os.ModePerm},
|
||||||
"/test/yes",
|
"/test/yes",
|
||||||
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Can run integration test for empty initialization and absolute root directory test",
|
"Can not run integration test for empty initialization and absolute root directory test",
|
||||||
initializeEmptyArgs{"test", os.ModePerm},
|
initializeEmptyArgs{"test", os.ModePerm},
|
||||||
"test",
|
"test",
|
||||||
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Can run integration test for empty initialization and absolute root directory test/yes",
|
"Can not run integration test for empty initialization and absolute root directory test/yes",
|
||||||
initializeEmptyArgs{"test/yes", os.ModePerm},
|
initializeEmptyArgs{"test/yes", os.ModePerm},
|
||||||
"test/yes",
|
"test/yes",
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Can not run integration test for empty initialization and relative root directory ' '",
|
||||||
|
initializeEmptyArgs{" ", os.ModePerm},
|
||||||
|
" ",
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Can run integration test for empty initialization and relative root directory ''",
|
||||||
|
initializeEmptyArgs{"", os.ModePerm},
|
||||||
|
"",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Can run integration test for empty initialization and relative root directory .",
|
||||||
|
initializeEmptyArgs{".", os.ModePerm},
|
||||||
|
".",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Can run integration test for empty initialization and relative root directory ./",
|
||||||
|
initializeEmptyArgs{"./", os.ModePerm},
|
||||||
|
"./",
|
||||||
|
false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -997,7 +1027,7 @@ func TestSTFS_InitializeEmptyIntegration(t *testing.T) {
|
|||||||
for _, tt := range initializeEmptyTests {
|
for _, tt := range initializeEmptyTests {
|
||||||
tt := tt
|
tt := tt
|
||||||
|
|
||||||
runIntegrationTest(t, tt.name, func(t *testing.T, tmp string, cfg stfsConfig) {
|
runIntegrationTest(t, fmt.Sprintf("%v root=%v", tt.name, tt.wantRoot), func(t *testing.T, tmp string, cfg stfsConfig) {
|
||||||
drive := filepath.Join(tmp, "drive.tar")
|
drive := filepath.Join(tmp, "drive.tar")
|
||||||
metadata := filepath.Join(tmp, "metadata.sqlite")
|
metadata := filepath.Join(tmp, "metadata.sqlite")
|
||||||
|
|
||||||
@@ -1026,7 +1056,7 @@ func TestSTFS_InitializeEmptyIntegration(t *testing.T) {
|
|||||||
cfg.writeCache,
|
cfg.writeCache,
|
||||||
writeCacheDir,
|
writeCacheDir,
|
||||||
|
|
||||||
cfg.fileSystemCache,
|
config.NoneKey,
|
||||||
fileSystemCacheDir,
|
fileSystemCacheDir,
|
||||||
cfg.fileSystemCacheDuration,
|
cfg.fileSystemCacheDuration,
|
||||||
|
|
||||||
@@ -1082,9 +1112,11 @@ func TestSTFS_InitializeEmptyIntegration(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
wantFile := "/test.txt"
|
wantFileAbsolute := "/test.txt"
|
||||||
if gotFile.Name() != wantFile {
|
wantFileRelative := "test.txt"
|
||||||
t.Errorf("%v.Create() = %v, want %v", f.Name(), gotFile.Name(), wantFile)
|
wantFileRelativeDot := "./test.txt"
|
||||||
|
if !(gotFile.Name() == wantFileAbsolute || gotFile.Name() == wantFileRelative || gotFile.Name() == wantFileRelativeDot) {
|
||||||
|
t.Errorf("%v.Create() = %v, want %v", f.Name(), gotFile.Name(), []string{wantFileAbsolute, wantFileRelative, wantFileRelativeDot})
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1123,7 +1155,7 @@ func TestSTFS_InitializeEmptyIntegration(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wantChildren := 2
|
wantChildren := 2
|
||||||
if len(gotChildren) != wantChildren {
|
if len(gotChildren) != wantChildren && !tt.wantErr {
|
||||||
t.Errorf("%v.Readdir() = %v, want %v", f.Name(), len(gotChildren), wantChildren)
|
t.Errorf("%v.Readdir() = %v, want %v", f.Name(), len(gotChildren), wantChildren)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user