lib9p

Go 9P library.
Log | Files | Refs | LICENSE

commit 7d3a3ab52e32bb16b3c2136234fdf3ac49a72d35
parent f5144a4c74f5b87e94660e24a2284ec804b1fa15
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Tue,  2 Jan 2024 16:03:52 +0900

add TestSWrite

Diffstat:
Mfs_test.go | 1+
Mserver_test.go | 47+++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/fs_test.go b/fs_test.go @@ -202,6 +202,7 @@ func init() { {".", fs.ModeDir | 0755, "glenda", "glenda", "glenda", ""}, {"a", 0644, "glenda", "glenda", "glenda", "a\n"}, {"b", 0600, "ken", "ken", "ken", "b\n"}, + {"c", 0644, "glenda", "glenda", "glenda", ""}, {"dir", fs.ModeDir | 0755, "rob", "rob", "rob", ""}, {"dir/file", 0666, "brian", "brian", "dennis", "unko\n"}, } diff --git a/server_test.go b/server_test.go @@ -569,4 +569,51 @@ func testSRead(t *testing.T, pathname string, c *conn, tc, rc chan *request) { return } } +} + +func TestSWrite(t *testing.T) { + tests := []struct{ + pathname string + data []byte + }{ + {"c", []byte("unko")}, + } + c, tc, rc := setupConn(testfs) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + go sWrite(ctx, c, tc) + for i, test := range tests{ + func() { + c.fPool.delete(0) + fid, err := c.fPool.add(0) + if err != nil { + t.Error(err) + return + } + fid.omode = ORDWR + fid.path = test.pathname + ff, err := testfs.OpenFile(test.pathname, ORDWR) + if err != nil { + t.Error(err) + return + } + defer ff.Close() + f := ff.(*testFile) + fid.file = f + tc <- &request{ifcall: &TWrite{Count: uint32(len(test.data)), Data: test.data}} + ofcall := (<-rc).ofcall + switch ofcall := ofcall.(type) { + case *RWrite: + if !bytes.Equal(f.content, test.data) { + t.Errorf("%d: content mismatch: want: %v, got: %v", + i, test.data, f.content) + } + case *RError: + t.Error(ofcall.Ename) + default: + t.Errorf("%d: unexpected message: %v", i, ofcall) + } + f.content = []byte("") + }() + } } \ No newline at end of file