aboutsummaryrefslogtreecommitdiff
path: root/main_test.go
diff options
context:
space:
mode:
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)))