lib9p

Go 9P library.
Log | Files | Refs

commit b1e1696468d13344458d15b0fe2ded76b2024ffa
parent a70936223a38d2cf2fc3f42ebac099fffbab3b3d
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Wed,  6 Sep 2023 07:34:36 +0900

add test for message parsing

Diffstat:
Afcall_test.go | 44++++++++++++++++++++++++++++++++++++++++++++
Atest.raw | 0
2 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/fcall_test.go b/fcall_test.go @@ -0,0 +1,43 @@ +package lib9p + +import ( + "bytes" + "io" + "os" + "testing" +) + +// TestParse parses 9P message and marshals it back, and +// checks whether they are identical. +func TestParse(t *testing.T) { + var raws [][]byte + var msgs []Msg + + rawFile, err := os.Open("raw") + if err != nil { + t.Fatalf("open file: %v", err) + } + for { + mb, err := read9PMsg(rawFile) + if err == io.EOF { + break + } else if err != nil { + t.Errorf("read msg: %v", err) + continue + } + raws = append(raws, mb) + + m, err := unmarshal(mb) + if err != nil { + t.Errorf("unmarshal: %v", err) + continue + } + msgs = append(msgs, m) + t.Log(m) + } + for i := 0; i < len(raws); i++ { + if !bytes.Equal(msgs[i].marshal(), raws[i]) { + t.Errorf("data mismatch: %v, %v != %v", msgs[i], msgs[i].marshal(), raws[i]) + } + } +} +\ No newline at end of file diff --git a/test.raw b/test.raw Binary files differ.