commit 9312bcb425b344829c365fd66cff151159689102
parent 29c2f9532ad09c19741d40b0b8d4f4175337b865
Author: Matsuda Kenji <info@mtkn.jp>
Date: Tue, 2 Jan 2024 15:35:22 +0900
add TestSRead
Diffstat:
1 file changed, 48 insertions(+), 0 deletions(-)
diff --git a/server_test.go b/server_test.go
@@ -523,3 +523,50 @@ remove:
}
}
}
+
+func TestSRead(t *testing.T) {
+ c, tc, rc := setupConn(testfs)
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+ go sRead(ctx, c, tc)
+ testSRead(t, ".", c, tc, rc)
+}
+
+func testSRead(t *testing.T, pathname string, c *conn, tc, rc chan *request) {
+ ff, err := testfs.OpenFile(pathname, OREAD)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer ff.Close()
+ f := ff.(*testFile)
+ fi, err := f.Stat()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if fi.IsDir() {
+ for _, child := range f.children {
+ cpath := path.Join(pathname, child.stat.Name)
+ testSRead(t, cpath, c, tc, rc)
+ }
+ } else {
+ fid, err := c.fPool.add(0)
+ defer c.fPool.delete(0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ fid.omode = OREAD
+ fid.file = f
+ fid.path = pathname
+ tc <- &request{ifcall: &TRead{Fid: 0, Offset: 0, Count: 1000}}
+ ofcall := (<-rc).ofcall
+ rread, ok := ofcall.(*RRead)
+ if !ok {
+ t.Errorf("unexpected message: %v", ofcall)
+ return
+ }
+ if !bytes.Equal(rread.Data, f.content) {
+ t.Errorf("content mismatch: want: %v, got: %v", f.content, rread.Data)
+ return
+ }
+ }
+}
+\ No newline at end of file