summaryrefslogtreecommitdiff
path: root/main_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-09-08 22:03:27 +0200
committerJakob Unterwurzacher2015-09-08 22:03:27 +0200
commit1ca4fc89aac5482f1294b1ffabc1912c2fb99a82 (patch)
tree8b6f4e594286b5bd1797c670e7e7a78082fd483d /main_test.go
parentcaaad7c8d7261b944931e9baf94568aa8c12c8bf (diff)
More debug logging, improve main_test.go (do not use all-zero content)
Diffstat (limited to 'main_test.go')
-rw-r--r--main_test.go21
1 files changed, 13 insertions, 8 deletions
diff --git a/main_test.go b/main_test.go
index 70dbbe2..9e4ca73 100644
--- a/main_test.go
+++ b/main_test.go
@@ -47,7 +47,7 @@ func TestMain(m *testing.M) {
os.Exit(r)
}
-func testWriteN(t *testing.T, fn string, n int, hashWant string) {
+func testWriteN(t *testing.T, fn string, n int) string {
file, err := os.Create(plainDir + fn)
if err != nil {
t.FailNow()
@@ -66,28 +66,33 @@ func testWriteN(t *testing.T, fn string, n int, hashWant string) {
t.Fail()
}
- rawHash := md5.Sum(buf)
- hashActual := hex.EncodeToString(rawHash[:])
+ raw := md5.Sum(d)
+ hashWant := hex.EncodeToString(raw[:])
+
+ raw = md5.Sum(buf)
+ hashActual := hex.EncodeToString(raw[:])
if hashActual != hashWant {
fmt.Printf("hashWant=%s hashActual=%s\n", hashWant, hashActual)
t.Fail()
}
+
+ return hashActual
}
func TestWrite10(t *testing.T) {
- testWriteN(t, "10", 10, "a63c90cc3684ad8b0a2176a6a8fe9005")
+ testWriteN(t, "10", 10)
}
func TestWrite100(t *testing.T) {
- testWriteN(t, "100", 100, "6d0bb00954ceb7fbee436bb55a8397a9")
+ testWriteN(t, "100", 100)
}
func TestWrite1M(t *testing.T) {
- testWriteN(t, "1M", 1024*1024, "b6d81b360a5672d80c27430f39153e2c")
+ testWriteN(t, "1M", 1024*1024)
}
func TestWrite1Mx100(t *testing.T) {
- testWriteN(t, "1Mx100", 1024*1024, "b6d81b360a5672d80c27430f39153e2c")
+ hashWant := testWriteN(t, "1Mx100", 1024*1024)
// Read and check 100 times to catch race conditions
var i int
for i = 0; i < 100; i++ {
@@ -97,7 +102,7 @@ func TestWrite1Mx100(t *testing.T) {
}
rawHash := md5.Sum(buf)
hashActual := hex.EncodeToString(rawHash[:])
- if hashActual != "b6d81b360a5672d80c27430f39153e2c" {
+ if hashActual != hashWant {
fmt.Printf("Read corruption in loop # %d\n", i)
t.FailNow()
} else {