Commit ace251fd authored by Kevin Atkinson's avatar Kevin Atkinson

Refactor tests to make testing additional shard functions easier.

Also fix bug when only the Prefix function was being tested in most cases.
parent 96522942
...@@ -30,6 +30,11 @@ func tempdir(t testing.TB) (path string, cleanup func()) { ...@@ -30,6 +30,11 @@ func tempdir(t testing.TB) (path string, cleanup func()) {
return path, cleanup return path, cleanup
} }
func tryAllShardFuncs(t *testing.T, testFunc func(mkShardFunc, *testing.T)) {
t.Run("prefix", func(t *testing.T) { testFunc(flatfs.Prefix, t) })
t.Run("suffix", func(t *testing.T) { testFunc(flatfs.Suffix, t) })
}
func TestPutBadValueType(t *testing.T) { func TestPutBadValueType(t *testing.T) {
temp, cleanup := tempdir(t) temp, cleanup := tempdir(t)
defer cleanup() defer cleanup()
...@@ -62,10 +67,7 @@ func testPut(dirFunc mkShardFunc, t *testing.T) { ...@@ -62,10 +67,7 @@ func testPut(dirFunc mkShardFunc, t *testing.T) {
} }
} }
func TestPut(t *testing.T) { func TestPut(t *testing.T) { tryAllShardFuncs(t, testPut) }
t.Run("prefix", func(t *testing.T) { testPut(flatfs.Prefix, t) })
t.Run("suffix", func(t *testing.T) { testPut(flatfs.Prefix, t) })
}
func testGet(dirFunc mkShardFunc, t *testing.T) { func testGet(dirFunc mkShardFunc, t *testing.T) {
temp, cleanup := tempdir(t) temp, cleanup := tempdir(t)
...@@ -95,10 +97,7 @@ func testGet(dirFunc mkShardFunc, t *testing.T) { ...@@ -95,10 +97,7 @@ func testGet(dirFunc mkShardFunc, t *testing.T) {
} }
} }
func TestGet(t *testing.T) { func TestGet(t *testing.T) { tryAllShardFuncs(t, testGet) }
t.Run("prefix", func(t *testing.T) { testGet(flatfs.Prefix, t) })
t.Run("suffix", func(t *testing.T) { testGet(flatfs.Prefix, t) })
}
func testPutOverwrite(dirFunc mkShardFunc, t *testing.T) { func testPutOverwrite(dirFunc mkShardFunc, t *testing.T) {
temp, cleanup := tempdir(t) temp, cleanup := tempdir(t)
...@@ -132,10 +131,7 @@ func testPutOverwrite(dirFunc mkShardFunc, t *testing.T) { ...@@ -132,10 +131,7 @@ func testPutOverwrite(dirFunc mkShardFunc, t *testing.T) {
} }
} }
func TestPutOverwrite(t *testing.T) { func TestPutOverwrite(t *testing.T) { tryAllShardFuncs(t, testPutOverwrite) }
t.Run("prefix", func(t *testing.T) { testPutOverwrite(flatfs.Prefix, t) })
t.Run("suffix", func(t *testing.T) { testPutOverwrite(flatfs.Prefix, t) })
}
func testGetNotFoundError(dirFunc mkShardFunc, t *testing.T) { func testGetNotFoundError(dirFunc mkShardFunc, t *testing.T) {
temp, cleanup := tempdir(t) temp, cleanup := tempdir(t)
...@@ -152,10 +148,7 @@ func testGetNotFoundError(dirFunc mkShardFunc, t *testing.T) { ...@@ -152,10 +148,7 @@ func testGetNotFoundError(dirFunc mkShardFunc, t *testing.T) {
} }
} }
func TestGetNotFoundError(t *testing.T) { func TestGetNotFoundError(t *testing.T) { tryAllShardFuncs(t, testGetNotFoundError) }
t.Run("prefix", func(t *testing.T) { testGetNotFoundError(flatfs.Prefix, t) })
t.Run("suffix", func(t *testing.T) { testGetNotFoundError(flatfs.Prefix, t) })
}
type params struct { type params struct {
what string what string
...@@ -257,10 +250,7 @@ func testHasNotFound(dirFunc mkShardFunc, t *testing.T) { ...@@ -257,10 +250,7 @@ func testHasNotFound(dirFunc mkShardFunc, t *testing.T) {
} }
} }
func TestHasNotFound(t *testing.T) { func TestHasNotFound(t *testing.T) { tryAllShardFuncs(t, testHasNotFound) }
t.Run("prefix", func(t *testing.T) { testHasNotFound(flatfs.Prefix, t) })
t.Run("suffix", func(t *testing.T) { testHasNotFound(flatfs.Prefix, t) })
}
func testHasFound(dirFunc mkShardFunc, t *testing.T) { func testHasFound(dirFunc mkShardFunc, t *testing.T) {
temp, cleanup := tempdir(t) temp, cleanup := tempdir(t)
...@@ -284,10 +274,7 @@ func testHasFound(dirFunc mkShardFunc, t *testing.T) { ...@@ -284,10 +274,7 @@ func testHasFound(dirFunc mkShardFunc, t *testing.T) {
} }
} }
func TestHasFound(t *testing.T) { func TestHasFound(t *testing.T) { tryAllShardFuncs(t, testHasFound) }
t.Run("prefix", func(t *testing.T) { testHasFound(flatfs.Prefix, t) })
t.Run("suffix", func(t *testing.T) { testHasFound(flatfs.Prefix, t) })
}
func testDeleteNotFound(dirFunc mkShardFunc, t *testing.T) { func testDeleteNotFound(dirFunc mkShardFunc, t *testing.T) {
temp, cleanup := tempdir(t) temp, cleanup := tempdir(t)
...@@ -304,10 +291,7 @@ func testDeleteNotFound(dirFunc mkShardFunc, t *testing.T) { ...@@ -304,10 +291,7 @@ func testDeleteNotFound(dirFunc mkShardFunc, t *testing.T) {
} }
} }
func TestDeleteNotFound(t *testing.T) { func TestDeleteNotFound(t *testing.T) { tryAllShardFuncs(t, testDeleteNotFound) }
t.Run("prefix", func(t *testing.T) { testDeleteNotFound(flatfs.Prefix, t) })
t.Run("suffix", func(t *testing.T) { testDeleteNotFound(flatfs.Prefix, t) })
}
func testDeleteFound(dirFunc mkShardFunc, t *testing.T) { func testDeleteFound(dirFunc mkShardFunc, t *testing.T) {
temp, cleanup := tempdir(t) temp, cleanup := tempdir(t)
...@@ -334,10 +318,7 @@ func testDeleteFound(dirFunc mkShardFunc, t *testing.T) { ...@@ -334,10 +318,7 @@ func testDeleteFound(dirFunc mkShardFunc, t *testing.T) {
} }
} }
func TestDeleteFound(t *testing.T) { func TestDeleteFound(t *testing.T) { tryAllShardFuncs(t, testDeleteFound) }
t.Run("prefix", func(t *testing.T) { testDeleteFound(flatfs.Prefix, t) })
t.Run("suffix", func(t *testing.T) { testDeleteFound(flatfs.Prefix, t) })
}
func testQuerySimple(dirFunc mkShardFunc, t *testing.T) { func testQuerySimple(dirFunc mkShardFunc, t *testing.T) {
temp, cleanup := tempdir(t) temp, cleanup := tempdir(t)
...@@ -380,10 +361,7 @@ func testQuerySimple(dirFunc mkShardFunc, t *testing.T) { ...@@ -380,10 +361,7 @@ func testQuerySimple(dirFunc mkShardFunc, t *testing.T) {
} }
} }
func TestQuerySimple(t *testing.T) { func TestQuerySimple(t *testing.T) { tryAllShardFuncs(t, testQuerySimple) }
t.Run("prefix", func(t *testing.T) { testQuerySimple(flatfs.Prefix, t) })
t.Run("suffix", func(t *testing.T) { testQuerySimple(flatfs.Prefix, t) })
}
func testBatchPut(dirFunc mkShardFunc, t *testing.T) { func testBatchPut(dirFunc mkShardFunc, t *testing.T) {
temp, cleanup := tempdir(t) temp, cleanup := tempdir(t)
...@@ -397,10 +375,7 @@ func testBatchPut(dirFunc mkShardFunc, t *testing.T) { ...@@ -397,10 +375,7 @@ func testBatchPut(dirFunc mkShardFunc, t *testing.T) {
dstest.RunBatchTest(t, fs) dstest.RunBatchTest(t, fs)
} }
func TestBatchPut(t *testing.T) { func TestBatchPut(t *testing.T) { tryAllShardFuncs(t, testBatchPut) }
t.Run("prefix", func(t *testing.T) { testBatchPut(flatfs.Prefix, t) })
t.Run("suffix", func(t *testing.T) { testBatchPut(flatfs.Prefix, t) })
}
func testBatchDelete(dirFunc mkShardFunc, t *testing.T) { func testBatchDelete(dirFunc mkShardFunc, t *testing.T) {
temp, cleanup := tempdir(t) temp, cleanup := tempdir(t)
...@@ -414,10 +389,7 @@ func testBatchDelete(dirFunc mkShardFunc, t *testing.T) { ...@@ -414,10 +389,7 @@ func testBatchDelete(dirFunc mkShardFunc, t *testing.T) {
dstest.RunBatchDeleteTest(t, fs) dstest.RunBatchDeleteTest(t, fs)
} }
func TestBatchDelete(t *testing.T) { func TestBatchDelete(t *testing.T) { tryAllShardFuncs(t, testBatchDelete) }
t.Run("prefix", func(t *testing.T) { testBatchDelete(flatfs.Prefix, t) })
t.Run("suffix", func(t *testing.T) { testBatchDelete(flatfs.Prefix, t) })
}
func BenchmarkConsecutivePut(b *testing.B) { func BenchmarkConsecutivePut(b *testing.B) {
r := rand.New() r := rand.New()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment