Skip to content
This repository has been archived by the owner on Oct 14, 2021. It is now read-only.

Commit

Permalink
appender: Add test for append a exists file (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongjiwei authored Jul 27, 2021
1 parent aaff270 commit 058a824
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions appender.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,13 @@ func TestAppender(t *testing.T, store types.Storager) {

size := rand.Int63n(4 * 1024 * 1024) // Max file size is 4MB
content, _ := ioutil.ReadAll(io.LimitReader(randbytes.NewRand(), size))
r := bytes.NewReader(content)

_, err = ap.WriteAppend(o, r, size)
_, err = ap.WriteAppend(o, bytes.NewReader(content), size)
if err != nil {
t.Error(err)
}

_, err = ap.WriteAppend(o, bytes.NewReader(content), size)
if err != nil {
t.Error(err)
}
Expand All @@ -162,13 +166,13 @@ func TestAppender(t *testing.T, store types.Storager) {
})

var buf bytes.Buffer
_, err = store.Read(path, &buf, pairs.WithSize(size))
_, err = store.Read(path, &buf, pairs.WithSize(size*2))

Convey("Read error should be nil", func() {
So(err, ShouldBeNil)
})
Convey("The content should be match", func() {
So(sha256.Sum256(buf.Bytes()), ShouldResemble, sha256.Sum256(content))
So(sha256.Sum256(buf.Bytes()), ShouldResemble, sha256.Sum256(bytes.Repeat(content, 2)))
})
})
})
Expand Down

0 comments on commit 058a824

Please sign in to comment.