Skip to content

Commit

Permalink
Merge pull request #1414 from ipfs/fix-verify-file
Browse files Browse the repository at this point in the history
ipns_test: fix slice bounds out of range
  • Loading branch information
jbenet committed Jun 23, 2015
2 parents 3a1c8d7 + d182960 commit 3f28663
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions fuse/ipns/ipns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,16 @@ func writeFileData(t *testing.T, data []byte, path string) []byte {
return data
}

func verifyFile(t *testing.T, path string, data []byte) {
fi, err := os.Open(path)
func verifyFile(t *testing.T, path string, wantData []byte) {
isData, err := ioutil.ReadFile(path)
if err != nil {
t.Fatal(err)
}
defer fi.Close()

buf := make([]byte, 1024)
offset := 0
for {
n, err := fi.Read(buf)
if err != nil {
t.Fatal(err)
}

if !bytes.Equal(buf[:n], data[offset:offset+n]) {
t.Fatal("Data not equal")
}

if n < len(buf) {
break
}

offset += n
if len(isData) != len(wantData) {
t.Fatal("Data not equal - length check failed")
}
if !bytes.Equal(isData, wantData) {
t.Fatal("Data not equal")
}
}

Expand Down

0 comments on commit 3f28663

Please sign in to comment.