Skip to content

Commit

Permalink
Merge pull request #3096 from ipfs/feat/test-cover-unixfs-mod
Browse files Browse the repository at this point in the history
test: reach 80% coverage of unixfs/mod
  • Loading branch information
whyrusleeping authored Aug 18, 2016
2 parents 1a4361e + c56e720 commit 6bb8a1f
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions unixfs/mod/dagmodifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,10 @@ func TestReadAndSeek(t *testing.T) {
writeBuf := []byte{0, 1, 2, 3, 4, 5, 6, 7}
dagmod.Write(writeBuf)

if !dagmod.HasChanges() {
t.Fatal("there are changes, this should be true")
}

readBuf := make([]byte, 4)
offset, err := dagmod.Seek(0, os.SEEK_SET)
if offset != 0 {
Expand Down Expand Up @@ -693,6 +697,37 @@ func TestReadAndSeek(t *testing.T) {

}

func TestCtxRead(t *testing.T) {
dserv := getMockDagServ(t)

_, n := getNode(t, dserv, 0)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

dagmod, err := NewDagModifier(ctx, n, dserv, sizeSplitterGen(512))
if err != nil {
t.Fatal(err)
}

_, err = dagmod.Write([]byte{0, 1, 2, 3, 4, 5, 6, 7})
if err != nil {
t.Fatal(err)
}
dagmod.Seek(0, os.SEEK_SET)

readBuf := make([]byte, 4)
_, err = dagmod.CtxReadFull(ctx, readBuf)
if err != nil {
t.Fatal(err)
}
err = arrComp(readBuf, []byte{0, 1, 2, 3})
if err != nil {
t.Fatal(err)
}
// TODO(Kubuxu): context cancel case, I will do it after I figure out dagreader tests,
// because this is exacelly the same.
}

func BenchmarkDagmodWrite(b *testing.B) {
b.StopTimer()
dserv := getMockDagServ(b)
Expand Down

0 comments on commit 6bb8a1f

Please sign in to comment.