commit fe57e966d3d7d1de3a6485a4c9eaf83b6394acbb
parent 8fb09c72847ef13ab02fafb2c266684f36ae0bc2
Author: Matsuda Kenji <info@mtkn.jp>
Date: Thu, 21 Sep 2023 10:05:52 +0900
move fsys to global
Diffstat:
| M | client_test.go | | | 70 | +++++++++++++++++++++++++++++++--------------------------------------- |
1 file changed, 31 insertions(+), 39 deletions(-)
diff --git a/client_test.go b/client_test.go
@@ -6,6 +6,30 @@ import (
"testing"
)
+var fsys *testFS
+
+func init() {
+ fsys = &testFS{
+ root: &testFile{
+ name: "root",
+ omode: -1,
+ isDir: true,
+ children: []*testFile{
+ &testFile{
+ name: "unko",
+ omode: -1,
+ isDir: false,
+ content: []byte("unko\n"),
+ },
+ },
+ },
+ }
+ fsys.root.fsys = fsys
+ fsys.root.parent = fsys.root
+ fsys.root.children[0].fsys = fsys
+ fsys.root.children[0].parent = fsys.root
+}
+
func newReq(s *Server, msg Msg) (*Req, error) {
r, err := s.rPool.add(msg.Tag())
if err != nil {
@@ -49,48 +73,26 @@ func handleReq(s *Server, r *Req) {
}
func TestWalk(t *testing.T) {
- fsys := &testFS{
- root: &testFile{
- name: "root",
- omode: -1,
- isDir: true,
- children: []*testFile{
- &testFile{
- name: "unko",
- omode: -1,
- isDir: false,
- content: []byte("unko\n"),
- },
- },
- },
- }
- fsys.root.fsys = fsys
- fsys.root.parent = fsys.root
- fsys.root.children[0].fsys = fsys
- fsys.root.children[0].parent = fsys.root
-
f, err := fsys.Open(".")
if err != nil {
t.Errorf("open: %v", err)
- } else {
- t.Logf("file: %s", f.(*testFile).name)
+ } else if f != fsys.root {
+ t.Errorf("open %p != %p", f, fsys.root)
}
f, err = fsys.Open("unko")
if err != nil {
t.Errorf("open: %v", err)
- } else {
- t.Logf("file: %s", f.(*testFile).name)
+ } else if f != fsys.root.children[0] {
+ t.Errorf("open %p != %p", f, fsys.root.children[0])
}
f, err = fsys.Open("chinko")
- if err != nil {
- t.Logf("open: %v", err)
- } else {
- t.Errorf("file: %s", f.(*testFile).name)
+ if err == nil {
+ t.Errorf("open non-existent file")
}
}
-func TestSVersion(t *testing.T) {
+func TestServer(t *testing.T) {
sr, _ := io.Pipe()
cr, sw := io.Pipe()
msg := []Msg{
@@ -107,16 +109,6 @@ func TestSVersion(t *testing.T) {
aname: "",
},
}
- fsys := &testFS{
- root: &testFile{
- omode: -1,
- name: "root",
- children: nil,
- content: nil,
- },
- }
- fsys.root.fsys = fsys
- fsys.root.parent = fsys.root
s := NewServer(fsys, 1024, sr, sw)