lib9p

Go 9P library.
Log | Files | Refs

commit ee1b3758df2258daf51be5af2152ad2dffaabafc
parent f09e41112c9833fbf6645fdfc8303d2a119c46f2
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Wed,  6 Sep 2023 08:48:28 +0900

implment test for fcall and its parsing

Diffstat:
Mfcall_test.go | 17+++++++++++++----
Mfs.go | 6+++---
Mserver.go | 2+-
Atest_Rmsg.dat | 0
Rtest.raw -> test_Tmsg.dat | 0
5 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/fcall_test.go b/fcall_test.go @@ -9,33 +9,42 @@ import ( // TestParse parses 9P message and marshals it back, and // checks whether they are identical. -func TestParse(t *testing.T) { +func TestFcallParse(t *testing.T) { var raws [][]byte var msgs []Msg - rawFile, err := os.Open("test.raw") + tFile, err := os.Open("test_Tmsg.dat") if err != nil { t.Fatalf("open file: %v", err) } + rFile, err := os.Open("test_Rmsg.dat") + if err != nil { + t.Fatalf("open file: %v", err) + } + rawFile := io.MultiReader(tFile, rFile) for { mb, err := read9PMsg(rawFile) if err == io.EOF { break } else if err != nil { t.Errorf("read msg: %v", err) - continue + mb = []byte{} } raws = append(raws, mb) m, err := unmarshal(mb) if err != nil { t.Errorf("unmarshal: %v", err) - continue + m = nil } msgs = append(msgs, m) t.Log(m) } for i := 0; i < len(raws); i++ { + if msgs[i] == nil { + t.Errorf("nil message: %v", raws[i]) + continue + } if !bytes.Equal(msgs[i].marshal(), raws[i]) { t.Errorf("data mismatch: %v, %v != %v", msgs[i], msgs[i].marshal(), raws[i]) } diff --git a/fs.go b/fs.go @@ -9,8 +9,8 @@ type FS interface { Open(string) (File, error) } -func walk(fsys FS, root string, wnames []string) ([]*Qid, error) { - wqids := make([]*Qid, len(wnames)) +func walk(fsys FS, root string, wnames []string) ([]Qid, error) { + wqids := make([]Qid, len(wnames)) curName := root for i, name := range wnames { curName = path.Join(curName, name) @@ -19,7 +19,7 @@ func walk(fsys FS, root string, wnames []string) ([]*Qid, error) { return wqids, err } qid := f.Qid() - wqids[i] = &qid + wqids[i] = qid } return wqids, nil } diff --git a/server.go b/server.go @@ -381,7 +381,7 @@ func sStat(s *Server, r *Req) { ofcall := &RStat{ tag: ifcall.Tag(), - info: fileInfo, + stat: fileInfo.Sys().(*Stat), } r.ofcall = ofcall diff --git a/test_Rmsg.dat b/test_Rmsg.dat Binary files differ. diff --git a/test.raw b/test_Tmsg.dat Binary files differ.