summaryrefslogtreecommitdiff
path: root/main_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-10-31 23:08:40 +0100
committerJakob Unterwurzacher2015-11-01 01:36:19 +0100
commitb3ea1498cfdbd3a2a788b7871f49db5b6a0ca9ae (patch)
tree45fe22b0e8bc1b81f2b85bf9f54d3deebf8b772d /main_test.go
parent8b7c986bdf29b6bc4f7bf3c2e655552ab4ef4bd3 (diff)
tests: verify file size in testWriteN
Diffstat (limited to 'main_test.go')
-rw-r--r--main_test.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/main_test.go b/main_test.go
index 4d21dde..2d4f578 100644
--- a/main_test.go
+++ b/main_test.go
@@ -85,6 +85,7 @@ func TestMain(m *testing.M) {
os.Exit(r)
}
+// Write "n" zero bytes to filename "fn", read again, compare hash
func testWriteN(t *testing.T, fn string, n int) string {
file, err := os.Create(plainDir + fn)
if err != nil {
@@ -99,13 +100,23 @@ func testWriteN(t *testing.T, fn string, n int) string {
}
file.Close()
+ fi, err := os.Stat(plainDir + fn)
+ if err != nil {
+ t.Errorf("Stat on file %s failed: %v", fn, err)
+ } else {
+ if fi.Size() != int64(n) {
+ t.Errorf("Wrong file fize, got=%d want=%d", fi.Size(), n)
+ }
+ }
+
+
bin := md5.Sum(d)
hashWant := hex.EncodeToString(bin[:])
hashActual := md5fn(plainDir + fn)
if hashActual != hashWant {
- fmt.Printf("hashWant=%s hashActual=%s\n", hashWant, hashActual)
+ fmt.Printf("Content corruption in file %s: hashWant=%s hashActual=%s\n", fn, hashWant, hashActual)
t.Fail()
}