mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-28 17:03:58 +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,31 +68,17 @@ 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 len(isData) != len(wantData) {
|
||||
t.Fatal("Data not equal - length check failed")
|
||||
}
|
||||
|
||||
if !bytes.Equal(buf[:n], data[offset:offset+n]) {
|
||||
if !bytes.Equal(isData, wantData) {
|
||||
t.Fatal("Data not equal")
|
||||
}
|
||||
|
||||
if n < len(buf) {
|
||||
break
|
||||
}
|
||||
|
||||
offset += n
|
||||
}
|
||||
}
|
||||
|
||||
func checkExists(t *testing.T, path string) {
|
||||
|
Reference in New Issue
Block a user