summaryrefslogtreecommitdiff
path: root/main_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-09-30 23:42:18 +0200
committerJakob Unterwurzacher2015-09-30 23:42:18 +0200
commit3fef613591b6831d0ebc8bd2aff4264346a1d047 (patch)
treeac4659e9e56357b84fb248b334f03fe97e20b450 /main_test.go
parentb835f83fd54944de0aa87a4e53073c1204450fda (diff)
tests: Add append test
Diffstat (limited to 'main_test.go')
-rw-r--r--main_test.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/main_test.go b/main_test.go
index 8d216ac..4f51d00 100644
--- a/main_test.go
+++ b/main_test.go
@@ -1,6 +1,7 @@
package main
import (
+ "bytes"
"crypto/md5"
"encoding/hex"
"fmt"
@@ -145,6 +146,38 @@ func TestTruncate(t *testing.T) {
}
}
+func TestAppend(t *testing.T) {
+ fn := plainDir + "append"
+ file, err := os.Create(fn)
+ if err != nil {
+ t.FailNow()
+ }
+ data := []byte("testdata123456789") // length 17
+ var buf bytes.Buffer
+ var hashWant string
+ for i := 0; i <= 500; i++ {
+ file.Write(data)
+ buf.Write(data)
+ bin := md5.Sum(buf.Bytes())
+ hashWant = hex.EncodeToString(bin[:])
+ hashActual := md5fn(fn)
+ if hashWant != hashActual {
+ t.FailNow()
+ }
+ }
+
+ // Overwrite with the same data
+ // Hash must stay the same
+ file.Seek(0, 0)
+ for i := 0; i <= 500; i++ {
+ file.Write(data)
+ hashActual := md5fn(fn)
+ if hashWant != hashActual {
+ t.FailNow()
+ }
+ }
+}
+
func BenchmarkStreamWrite(t *testing.B) {
buf := make([]byte, 1024*1024)
t.SetBytes(int64(len(buf)))