diff options
| -rw-r--r-- | main_test.go | 21 | 
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 | 
