commit 8d89e48215955e21c4e96b81bd4be23b4bf89615
parent e30188740f264f2efb22933054fd87310a8a7924
Author: Matsuda Kenji <info@mtkn.jp>
Date: Tue, 17 Oct 2023 08:11:51 +0900
update test
Diffstat:
2 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/client_test.go b/client_test.go
@@ -135,12 +135,6 @@ func TestClient2(t *testing.T) {
root := fs.Root()
t.Log(root)
- c, err := root.Child()
- if err != nil {
- t.Errorf("child: %v", err)
- }
- t.Log(c)
-
a, err := fs.walkFile("a")
if err != nil {
t.Errorf("walkfile: %v", err)
diff --git a/test_fs.go b/test_fs.go
@@ -3,6 +3,7 @@ package lib9p
import (
"bytes"
"fmt"
+ "io/fs"
"strings"
"path/filepath"
)
@@ -45,6 +46,14 @@ func (f *testFile) ReadAt(b []byte, off int64) (n int, err error) {
return f.reader.ReadAt(b, off)
}
+func (f *testFile) ReadDir(n int) ([]*DirEntry, error) {
+ de := make([]*DirEntry, len(f.children))
+ for i, c := range f.children {
+ de[i], _ = c.Stat()
+ }
+ return de, nil
+}
+
func (f *testFile) WriteAt(p []byte, off int64) (int, error) {
if f.reader == nil {
return 0, fmt.Errorf("not open")
@@ -72,10 +81,15 @@ func (fs *testFS) Root() File {
return fs.root
}
-func (fs *testFS) Open(path string) (File, error) {
+func (fs *testFS) Open(path string, omode OpenMode, perm fs.FileMode) (File, error) {
path = clean9path(path)
wnames := split9path(path)
- return fs.walk(wnames)
+ f, err := fs.walk(wnames)
+ if err != nil {
+ return nil, fmt.Errorf("walk: %v", err)
+ }
+ f.reader = bytes.NewReader(f.content)
+ return f, nil
}
func (fs *testFS) walk(wnames []string) (*testFile, error) {