@cryptotaxi247 / kubo / commits / d18296045

ipns_test: fix slice bounds out of range

License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>

Christian Couder committed Jun 22, 2015 at 21:09 UTC d18296045edee56f742a69ca4b506756dd699514
1 file changed +7 -21
fuse/ipns/ipns_test.go
+7 -21
@@ -68,30 +68,16 @@ func writeFileData(t *testing.T, data []byte, path string) []byte {
68 return data
69 }
70
71 -func verifyFile(t *testing.T, path string, data []byte) {
72 - fi, err := os.Open(path)
71 +func verifyFile(t *testing.T, path string, wantData []byte) {
72 + isData, err := ioutil.ReadFile(path)
73 if err != nil {
74 t.Fatal(err)
75 }
76 - defer fi.Close()
77 -
78 - buf := make([]byte, 1024)
79 - offset := 0
80 - for {
81 - n, err := fi.Read(buf)
82 - if err != nil {
83 - t.Fatal(err)
84 - }
85 -
86 - if !bytes.Equal(buf[:n], data[offset:offset+n]) {
87 - t.Fatal("Data not equal")
88 - }
89 -
90 - if n < len(buf) {
91 - break
92 - }
93 -
94 - offset += n
76 + if len(isData) != len(wantData) {
77 + t.Fatal("Data not equal - length check failed")
78 + }
79 + if !bytes.Equal(isData, wantData) {
80 + t.Fatal("Data not equal")
81 }
82 }
83