提交 c64add19 作者: Jeromy

clean up ipns test and add more asserts

上级 5423a008
package ipns package ipns
import ( import (
"bytes"
"crypto/rand" "crypto/rand"
"io/ioutil"
"os" "os"
"testing" "testing"
...@@ -29,6 +31,7 @@ func TestIpnsBasicIO(t *testing.T) { ...@@ -29,6 +31,7 @@ func TestIpnsBasicIO(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer mnt.Close()
data := randBytes(12345) data := randBytes(12345)
fi, err := os.Create(mnt.Dir + "/local/testfile") fi, err := os.Create(mnt.Dir + "/local/testfile")
...@@ -54,16 +57,14 @@ func TestIpnsBasicIO(t *testing.T) { ...@@ -54,16 +57,14 @@ func TestIpnsBasicIO(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
rbuf := make([]byte, len(data)) rbuf, err := ioutil.ReadAll(fi)
n, err = fi.Read(rbuf)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
fi.Close()
if n != len(rbuf) { if !bytes.Equal(rbuf, data) {
t.Fatal("Failed to read correct amount!") t.Fatal("Incorrect Read!")
} }
fi.Close()
} }
...@@ -2,7 +2,6 @@ package ipns ...@@ -2,7 +2,6 @@ package ipns
import ( import (
"bytes" "bytes"
"fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
...@@ -294,10 +293,6 @@ func (s *Node) ReadAll(intr fs.Intr) ([]byte, fuse.Error) { ...@@ -294,10 +293,6 @@ func (s *Node) ReadAll(intr fs.Intr) ([]byte, fuse.Error) {
log.Error("[%s] Readall error: %s", s.name, err) log.Error("[%s] Readall error: %s", s.name, err)
return nil, err return nil, err
} }
if len(b) > 4 {
log.Debug("ReadAll trailing bytes: %v", b[len(b)-4:])
}
fmt.Println(b)
return b, nil return b, nil
} }
...@@ -342,7 +337,7 @@ func (n *Node) Flush(req *fuse.FlushRequest, intr fs.Intr) fuse.Error { ...@@ -342,7 +337,7 @@ func (n *Node) Flush(req *fuse.FlushRequest, intr fs.Intr) fuse.Error {
} }
n.Nd = newNode n.Nd = newNode
//TEMP /*/TEMP
dr, err := mdag.NewDagReader(n.Nd, n.Ipfs.DAG) dr, err := mdag.NewDagReader(n.Nd, n.Ipfs.DAG)
if err != nil { if err != nil {
log.Critical("Verification read failed.") log.Critical("Verification read failed.")
...@@ -355,7 +350,7 @@ func (n *Node) Flush(req *fuse.FlushRequest, intr fs.Intr) fuse.Error { ...@@ -355,7 +350,7 @@ func (n *Node) Flush(req *fuse.FlushRequest, intr fs.Intr) fuse.Error {
fmt.Printf("READ %d BYTES\n", len(b)) fmt.Printf("READ %d BYTES\n", len(b))
fmt.Println(string(b)) fmt.Println(string(b))
fmt.Println(b) fmt.Println(b)
// //*/
n.writerBuf = nil n.writerBuf = nil
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论