aboutsummaryrefslogtreecommitdiff
path: root/main_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-10-31 23:17:19 +0100
committerJakob Unterwurzacher2015-11-01 01:36:19 +0100
commit3f8b22d6ac2f70ad3dc8a7c936b2ebbeef4d36de (patch)
tree9ed5d9788d91e02692d96c261d4ed9d4c7c152fb /main_test.go
parentb3ea1498cfdbd3a2a788b7871f49db5b6a0ca9ae (diff)
tests: additionally verify the file size by reading the whole file
Diffstat (limited to 'main_test.go')
-rw-r--r--main_test.go21
1 files changed, 18 insertions, 3 deletions
diff --git a/main_test.go b/main_test.go
index 2d4f578..0927a58 100644
--- a/main_test.go
+++ b/main_test.go
@@ -41,6 +41,7 @@ func unmount() error {
return fu.Run()
}
+// Return md5 string for file "filename"
func md5fn(filename string) string {
buf, err := ioutil.ReadFile(filename)
if err != nil {
@@ -50,12 +51,22 @@ func md5fn(filename string) string {
return md5hex(buf)
}
+// Return md5 string for "buf"
func md5hex(buf []byte) string {
rawHash := md5.Sum(buf)
hash := hex.EncodeToString(rawHash[:])
return hash
}
+// Read the whole file and return number of bytes read
+func readSize(fn string) int {
+ buf, err := ioutil.ReadFile(fn)
+ if err != nil {
+ fmt.Printf("ReadFile: %v\n", err)
+ }
+ return len(buf)
+}
+
// This is the entry point for the tests
func TestMain(m *testing.M) {
@@ -105,10 +116,15 @@ func testWriteN(t *testing.T, fn string, n int) string {
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)
+ t.Errorf("Wrong stat file size, got=%d want=%d", fi.Size(), n)
}
}
+ rs := readSize(plainDir + fn)
+ if rs != n {
+ t.Errorf("Wrong read file fize, got=%d want=%d", rs, n)
+ }
+
bin := md5.Sum(d)
hashWant := hex.EncodeToString(bin[:])
@@ -116,8 +132,7 @@ func testWriteN(t *testing.T, fn string, n int) string {
hashActual := md5fn(plainDir + fn)
if hashActual != hashWant {
- fmt.Printf("Content corruption in file %s: hashWant=%s hashActual=%s\n", fn, hashWant, hashActual)
- t.Fail()
+ t.Errorf("Wrong content, hashWant=%s hashActual=%s\n", hashWant, hashActual)
}
return hashActual