diff options
author | Jakob Unterwurzacher | 2020-02-15 21:56:08 +0100 |
---|---|---|
committer | Jakob Unterwurzacher | 2020-02-15 21:56:08 +0100 |
commit | 6eca07e36e2e58ff7495305ed7cb0fdcc36436e6 (patch) | |
tree | b8063f09fa80e0d011bab98fb0a753ecc440a400 /tests | |
parent | 97743858ceed32a975840dcdceefd1e6305759f5 (diff) |
tests: randomize data in testWriteN
Just writing zeros carries the risk of not detecting
wrongly created file holes. Write random data instead.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/matrix/matrix_test.go | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/tests/matrix/matrix_test.go b/tests/matrix/matrix_test.go index af4769a..2215ff6 100644 --- a/tests/matrix/matrix_test.go +++ b/tests/matrix/matrix_test.go @@ -16,6 +16,7 @@ import ( "flag" "fmt" "io/ioutil" + "math/rand" "os" "os/exec" "runtime" @@ -96,7 +97,7 @@ func TestMain(m *testing.M) { os.Exit(0) } -// Write "n" zero bytes to filename "fn", read again, compare hash +// Write `n` random bytes to filename `fn`, read again, compare hash func testWriteN(t *testing.T, fn string, n int) string { file, err := os.Create(test_helpers.DefaultPlainDir + "/" + fn) if err != nil { @@ -104,6 +105,10 @@ func testWriteN(t *testing.T, fn string, n int) string { } d := make([]byte, n) + for i := range d { + // Fill with pattern + d[i] = byte(rand.Int()) + } _, err = file.Write(d) if err != nil { t.Fatal(err) @@ -143,9 +148,9 @@ func TestWrite100x100(t *testing.T) { // Read and check 100 times to catch race conditions var i int for i = 0; i < 100; i++ { - hashActual := test_helpers.Md5fn(test_helpers.DefaultPlainDir + "/100") + hashActual := test_helpers.Md5fn(test_helpers.DefaultPlainDir + "/100x100") if hashActual != hashWant { - fmt.Printf("Read corruption in loop #%d\n", i) + fmt.Printf("Read corruption in loop #%d: have=%s want=%s\n", i, hashActual, hashWant) t.FailNow() } else { //fmt.Print(".") |