commit 418ddacedb1be0d07bb58845af2c5594a0dcaea0
parent bd05b065a0165778d8b25f906af6e8f0e6a3e30e
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Tue,  9 Jan 2024 16:01:24 +0900
add test for directory reading
Diffstat:
1 file changed, 30 insertions(+), 0 deletions(-)
diff --git a/server_test.go b/server_test.go
@@ -555,10 +555,40 @@ func testSRead(t *testing.T, pathname string, c *conn, tc, rc chan *request) {
 		t.Fatal(err)
 	}
 	if fi.IsDir() {
+		fid, err := c.fPool.add(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
+		}
+		c.fPool.delete(0)
+		b := rread.Data
+		cstats := make(map[string]*Stat, len(f.children))
+		for len(b) != 0 {
+			st := NewStat(b)
+			b = b[2+st.Size():]
+			cstats[st.Name] = st
+		}
 		for _, child := range f.children {
+			if !reflect.DeepEqual(cstats[child.stat.Name], &child.stat) {
+				t.Errorf("readdir returned wrong stat:\n\twant: %v\n\tgot:  %v",
+					child.stat, cstats[child.stat.Name])
+			}
+			delete(cstats, child.stat.Name)
 			cpath := path.Join(pathname, child.stat.Name)
 			testSRead(t, cpath, c, tc, rc)
 		}
+		if len(cstats) != 0 {
+			t.Errorf("readdir returned unexistent stats: %v", cstats)
+		}
 	} else {
 		fid, err := c.fPool.add(0)
 		defer c.fPool.delete(0)