mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-29 01:12:24 +08:00
Merge pull request #1414 from ipfs/fix-verify-file
ipns_test: fix slice bounds out of range
This commit is contained in:
@ -68,30 +68,16 @@ func writeFileData(t *testing.T, data []byte, path string) []byte {
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
func verifyFile(t *testing.T, path string, data []byte) {
|
func verifyFile(t *testing.T, path string, wantData []byte) {
|
||||||
fi, err := os.Open(path)
|
isData, err := ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer fi.Close()
|
if len(isData) != len(wantData) {
|
||||||
|
t.Fatal("Data not equal - length check failed")
|
||||||
buf := make([]byte, 1024)
|
}
|
||||||
offset := 0
|
if !bytes.Equal(isData, wantData) {
|
||||||
for {
|
t.Fatal("Data not equal")
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user