commit 25e63b5b1f07973b3030f5cc7d3c6ae37f5df3d2
parent 3041961b3a5e57f9d179e29fe45abdf7d717a5cc
Author: Matsuda Kenji <info@mtkn.jp>
Date: Thu, 19 Oct 2023 10:26:11 +0900
update testFS
Diffstat:
| M | server_test.go | | | 64 | ---------------------------------------------------------------- |
| M | test_fs.go | | | 78 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- |
2 files changed, 64 insertions(+), 78 deletions(-)
diff --git a/server_test.go b/server_test.go
@@ -7,70 +7,6 @@ import (
"testing"
)
-var fsys *testFS
-
-func init() {
- fsys = &testFS{
- root: &testFile{
- stat: Stat{
- Qid: Qid{Path: 0, Type: QTDIR},
- Mode: FileMode(DMDIR | 0755),
- Name: "root",
- Uid: "glenda",
- Gid: "glenda",
- Muid: "glenda",
- },
- children: []*testFile{
- &testFile{
- content: []byte("a\n"),
- stat: Stat{
- Qid: Qid{Path: 1, Type: QTFILE},
- Mode: FileMode(0644),
- Name: "a",
- Uid: "glenda",
- Gid: "glenda",
- Muid: "glenda",
- },
- },
- &testFile{
- content: []byte("b\n"),
- stat: Stat{
- Qid: Qid{Path: 2, Type: QTFILE},
- Mode: FileMode(0400),
- Name: "b",
- Uid: "ken",
- Gid: "ken",
- Muid: "ken",
- },
- },
- &testFile{
- stat: Stat{
- Qid: Qid{Path: 3, Type: QTDIR},
- Mode: FileMode(DMDIR | 0755),
- Name: "dir",
- Uid: "rob",
- Gid: "rob",
- Muid: "rob",
- },
- children: []*testFile{
- &testFile{
- content: []byte("unko\n"),
- stat: Stat{
- Qid: Qid{Path: 4, Type: QTFILE},
- Mode: FileMode(0666),
- Name: "file",
- Uid: "brian",
- Gid: "brian",
- Muid: "dennis",
- },
- },
- },
- },
- },
- },
- }
- setFsysAndParent(fsys, nil)
-}
// SetFsysAndParent sets file.fsys and file.parent for every file in the fsys.
// Pass nil as file to setup entire file system.
diff --git a/test_fs.go b/test_fs.go
@@ -18,21 +18,7 @@ type testFile struct {
stat Stat
}
-func (f *testFile) Parent() (File, error) { return f.parent, nil }
-func (f *testFile) Child() ([]File, error) {
- child := make([]File, len(f.children))
- for i, c := range f.children {
- child[i] = c
- }
- return child, nil
-}
func (f *testFile) Stat() (*FileInfo, error) { return &FileInfo{Stat: f.stat}, nil }
-func (f *testFile) Qid() Qid { return f.stat.Qid }
-func (f *testFile) Open(mode OpenMode) error {
- f.reader = bytes.NewReader(f.content)
- return nil
-}
-
func (f *testFile) Close() error {
f.reader = nil
return nil
@@ -119,3 +105,67 @@ func split9path(path string) []string {
}
return strings.Split(path, "/")
}
+
+var fsys *testFS
+func init() {
+ fsys = &testFS{
+ root: &testFile{
+ stat: Stat{
+ Qid: Qid{Path: 0, Type: QTDIR},
+ Mode: FileMode(DMDIR | 0755),
+ Name: "root",
+ Uid: "glenda",
+ Gid: "glenda",
+ Muid: "glenda",
+ },
+ children: []*testFile{
+ &testFile{
+ content: []byte("a\n"),
+ stat: Stat{
+ Qid: Qid{Path: 1, Type: QTFILE},
+ Mode: FileMode(0644),
+ Name: "a",
+ Uid: "glenda",
+ Gid: "glenda",
+ Muid: "glenda",
+ },
+ },
+ &testFile{
+ content: []byte("b\n"),
+ stat: Stat{
+ Qid: Qid{Path: 2, Type: QTFILE},
+ Mode: FileMode(0400),
+ Name: "b",
+ Uid: "ken",
+ Gid: "ken",
+ Muid: "ken",
+ },
+ },
+ &testFile{
+ stat: Stat{
+ Qid: Qid{Path: 3, Type: QTDIR},
+ Mode: FileMode(DMDIR | 0755),
+ Name: "dir",
+ Uid: "rob",
+ Gid: "rob",
+ Muid: "rob",
+ },
+ children: []*testFile{
+ &testFile{
+ content: []byte("unko\n"),
+ stat: Stat{
+ Qid: Qid{Path: 4, Type: QTFILE},
+ Mode: FileMode(0666),
+ Name: "file",
+ Uid: "brian",
+ Gid: "brian",
+ Muid: "dennis",
+ },
+ },
+ },
+ },
+ },
+ },
+ }
+ setFsysAndParent(fsys, nil)
+}