lib9p

Go 9P library.
Log | Files | Refs | LICENSE

commit c949290b6a88b4867ea9be8881a20efa951f58b6
parent f6980e26d2d95b490f1f4018b6ef086e496212d9
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Sat, 13 Jan 2024 15:02:43 +0900

flush unko

Diffstat:
Mclient/client_test.go | 8++++----
Mclient/fs2_test.go | 2+-
Mserver.go | 2+-
Mserver_test.go | 125++++++++++++++++++++++++++++++++++++++++---------------------------------------
Mtestdata/fs.go | 2+-
5 files changed, 71 insertions(+), 68 deletions(-)

diff --git a/client/client_test.go b/client/client_test.go @@ -74,7 +74,7 @@ func TestVersion(t *testing.T) { &lib9p.TVersion{Tag: lib9p.NOTAG, Msize: 1024, Version: "9P2000"}, &lib9p.RVersion{Tag: lib9p.NOTAG, Msize: 1024, Version: "9P2000"}}, {"1", - &lib9p.TVersion{Tag: lib9p.NOTAG, Msize: 1024, Version: "unko"}, + &lib9p.TVersion{Tag: lib9p.NOTAG, Msize: 1024, Version: "hoge"}, &lib9p.RVersion{Tag: lib9p.NOTAG, Msize: 1024, Version: "unknown"}}, } for _, test := range tests { @@ -509,7 +509,7 @@ func TestRead(t *testing.T) { }{ {"0", &lib9p.TRead{Fid: 0, Offset: 0, Count: 1000}, - &lib9p.RRead{Count: 4, Data: []byte("unko")}}, + &lib9p.RRead{Count: 4, Data: []byte("hoge")}}, {"1", &lib9p.TRead{Fid: 0, Offset: 0, Count: 1000}, &lib9p.RError{Ename: errors.New("not open")}}, @@ -571,10 +571,10 @@ func TestWrite(t *testing.T) { rmsg lib9p.Msg }{ {"0", - &lib9p.TWrite{Fid: 0, Offset: 0, Count: 4, Data: []byte("unko")}, + &lib9p.TWrite{Fid: 0, Offset: 0, Count: 4, Data: []byte("hoge")}, &lib9p.RWrite{Count: 4}}, {"1", - &lib9p.TWrite{Fid: 0, Offset: 0, Count: 4, Data: []byte("unko")}, + &lib9p.TWrite{Fid: 0, Offset: 0, Count: 4, Data: []byte("hoge")}, &lib9p.RError{Ename: errors.New("not open")}}, } for _, test := range tests { diff --git a/client/fs2_test.go b/client/fs2_test.go @@ -15,7 +15,7 @@ func TestCleanPath(t *testing.T) { name string want string }{ - {"../../../unko", "unko"}, + {"../../../hoge", "hoge"}, {"..", "."}, {".", "."}, {"/", "."}, diff --git a/server.go b/server.go @@ -279,7 +279,7 @@ func sAuth(ctx context.Context, c *conn, rc <-chan *request) { setError(r, r.err) } else { c.s.Auth(ctx, r) - // TODO: move this code to c.s.Auth + // TODO: should move this code to c.s.Auth? if rauth, ok := r.ofcall.(*RAuth); ok { r.afid.qidpath = rauth.Aqid.Path } diff --git a/server_test.go b/server_test.go @@ -148,7 +148,7 @@ func TestSVersion(t *testing.T) { &RVersion{Msize: 564, Version: "9P2000"}}, {&TVersion{Msize: 8 * 1024, Version: "9P2000"}, &RVersion{Msize: 1024, Version: "9P2000"}}, - {&TVersion{Msize: 1024, Version: "unko"}, + {&TVersion{Msize: 1024, Version: "hoge"}, &RVersion{Msize: 1024, Version: "unknown"}}, } c, rc := setupConn(nil) @@ -195,7 +195,7 @@ func TestSAuth(t *testing.T) { r.ofcall = &RAuth{Tag: 0, Aqid: Qid{0, 1, 2}} }}, } - for _, test := range tests { + for i, test := range tests { func() { c, rc := setupConn(nil) tc := make(chan *request) @@ -209,54 +209,33 @@ func TestSAuth(t *testing.T) { case *RAuth: gotmsg, ok := ofcall.(*RAuth) if !ok { - t.Errorf("unexpected message: %v", ofcall) + t.Errorf("%d: unexpected message: %v", i, ofcall) return } if !reflect.DeepEqual(wantmsg, gotmsg) { - t.Errorf("want: %v,\n\tgot: %v", wantmsg, gotmsg) + t.Errorf("%d: want: %v,\n\tgot: %v", i, wantmsg, gotmsg) return } case *RError: _, ok := ofcall.(*RError) if !ok { - t.Errorf("unexpected message: %v", ofcall) + t.Errorf("%d: unexpected message: %v", i, ofcall) return } default: - t.Fatalf("unexpected message: %v", wantmsg) + t.Fatalf("%d: unexpected message: %v", i, wantmsg) } }() } } -func TestSFlush(t *testing.T) { - rp := newReqPool() - tests := []struct { - input *request - }{ - {&request{ifcall: &TFlush{}, - oldreq: &request{pool: rp, done: make(chan struct{})}}}, - } - c, rc := setupConn(nil) - tc := make(chan *request) - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - go sFlush(ctx, c, tc) - for _, test := range tests { - tc <- test.input - if gotmsg, ok := (<-rc).ofcall.(*RFlush); !ok { - t.Errorf("unexpected message: %v", gotmsg) - } - if _, ok := <-test.input.oldreq.done; ok { - t.Errorf("done channel not closed") - } - } -} - +// TestSAttach tests sAttach. +// It prepares a conn and adds an AuthFile to the FidPool with fid 0. +// It also sets c.fsmap["fs"] to test a Tattach message with Aname other than "". func TestSAttach(t *testing.T) { tests := []struct { input *TAttach - auth bool + needAuth bool authOK bool want Msg }{ @@ -272,7 +251,7 @@ func TestSAttach(t *testing.T) { {&TAttach{Fid: 2, Afid: 0, Uname: "kenji", Aname: ""}, true, false, &RError{}}, // not authOK - {&TAttach{Fid: 2, Afid: 0, Uname: "unko", Aname: ""}, + {&TAttach{Fid: 2, Afid: 0, Uname: "glenda", Aname: ""}, true, true, &RError{}}, // wrong user {&TAttach{Fid: 2, Afid: 0, Uname: "kenji", Aname: ""}, @@ -305,7 +284,7 @@ func TestSAttach(t *testing.T) { for i, test := range tests { af.AuthOK = test.authOK af.Aname = test.input.Aname - if test.auth { + if test.needAuth { c.s.Auth = dammyAuth } else { c.s.Auth = nil @@ -332,6 +311,30 @@ func TestSAttach(t *testing.T) { } } +func TestSFlush(t *testing.T) { + rp := newReqPool() + tests := []struct { + input *request + }{ + {&request{ifcall: &TFlush{}, + oldreq: &request{pool: rp, done: make(chan struct{})}}}, + } + c, rc := setupConn(nil) + tc := make(chan *request) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + go sFlush(ctx, c, tc) + for _, test := range tests { + tc <- test.input + if gotmsg, ok := (<-rc).ofcall.(*RFlush); !ok { + t.Errorf("unexpected message: %v", gotmsg) + } + if _, ok := <-test.input.oldreq.done; ok { + t.Errorf("done channel not closed") + } + } +} + func TestSWalk(t *testing.T) { tests := []struct { input Msg @@ -344,12 +347,12 @@ func TestSWalk(t *testing.T) { 1, nil}, {&TWalk{Fid: 0, Newfid: 3, Wnames: []string{"dir", "file"}}, 2, nil}, - {&TWalk{Fid: 0, Newfid: 4, Wnames: []string{"dir", "unko"}}, + {&TWalk{Fid: 0, Newfid: 4, Wnames: []string{"dir", "hoge"}}, 1, nil}, // short walk // 9P document says: // If the first element cant be walked for any reason, // RError is returned. - {&TWalk{Fid: 0, Newfid: 5, Wnames: []string{"unko", "unko"}}, + {&TWalk{Fid: 0, Newfid: 5, Wnames: []string{"hoge", "hoge"}}, 0, errors.New("not found")}, } c, rc := setupConn(testfs) @@ -616,7 +619,7 @@ func TestSWrite(t *testing.T) { pathname string data []byte }{ - {"c", []byte("unko")}, + {"c", []byte("hoge")}, } c, rc := setupConn(testfs) tc := make(chan *request) @@ -759,15 +762,15 @@ func TestSRemove(t *testing.T) { want Msg }{ // ok. - {0, "unko", "glenda", OREAD, 0777, "glenda", &TRemove{Fid: 0}, &RRemove{}}, + {0, "hoge", "glenda", OREAD, 0777, "glenda", &TRemove{Fid: 0}, &RRemove{}}, // unknown fid. - {0, "unko", "glenda", OREAD, 0777, "glenda", &TRemove{Fid: 1}, &RError{}}, + {0, "hoge", "glenda", OREAD, 0777, "glenda", &TRemove{Fid: 1}, &RError{}}, // permission denied. - {0, "unko", "glenda", OREAD, 0777, "kenji", &TRemove{Fid: 0}, &RError{}}, + {0, "hoge", "glenda", OREAD, 0777, "kenji", &TRemove{Fid: 0}, &RError{}}, // ok. - {0, "dir/unko", "glenda", OREAD, 0000, "rob", &TRemove{Fid: 0}, &RRemove{}}, + {0, "dir/hoge", "glenda", OREAD, 0000, "rob", &TRemove{Fid: 0}, &RRemove{}}, // permission denied. - {0, "dir/unko", "glenda", OREAD, 0777, "glenda", &TRemove{Fid: 0}, &RError{}}, + {0, "dir/hoge", "glenda", OREAD, 0777, "glenda", &TRemove{Fid: 0}, &RError{}}, } c, rc := setupConn(testfs) tc := make(chan *request) @@ -877,123 +880,123 @@ func TestSWstat(t *testing.T) { want Msg }{ // 0 ok: rename by owner of the directory. - {0, "./d/unko", "glenda", &Stat{Name: "unko"}, + {0, "./d/hoge", "glenda", &Stat{Name: "hoge"}, &TWstat{ Fid: 0, Stat: &Stat{Name: "oppai"}, }, &RWstat{}}, // 1 ok: rename by group member of the directory. - {0, "./d/unko", "ken", &Stat{Name: "unko"}, + {0, "./d/hoge", "ken", &Stat{Name: "hoge"}, &TWstat{ Fid: 0, Stat: &Stat{Name: "oppai"}, }, &RWstat{}}, // 2 permission denied: rename by other. - {0, "./d/unko", "kenji", &Stat{Name: "unko"}, + {0, "./d/hoge", "kenji", &Stat{Name: "hoge"}, &TWstat{ Fid: 0, Stat: &Stat{Name: "oppai"}, }, &RError{Ename: ErrPerm}}, // 3 ok: length change by owner with write permission - {0, "unko", "glenda", &Stat{Uid: "glenda", Mode: 0700, Length: 10}, + {0, "hoge", "glenda", &Stat{Uid: "glenda", Mode: 0700, Length: 10}, &TWstat{ Fid: 0, Stat: &Stat{Uid: "glenda", Mode: 0700, Length: 20}, }, &RWstat{}}, // 4 permission denied: length change by owner without write permission - {0, "unko", "glenda", &Stat{Uid: "glenda", Mode: 0000, Length: 10}, + {0, "hoge", "glenda", &Stat{Uid: "glenda", Mode: 0000, Length: 10}, &TWstat{ Fid: 0, Stat: &Stat{Uid: "glenda", Mode: 0700, Length: 20}, }, &RError{Ename: ErrPerm}}, // 5 operation not permitted: length change of a directory to other than 0 - {0, "unko", "glenda", &Stat{Uid: "glenda", Mode: fs.ModeDir | 0700, Length: 10}, + {0, "hoge", "glenda", &Stat{Uid: "glenda", Mode: fs.ModeDir | 0700, Length: 10}, &TWstat{ Fid: 0, Stat: &Stat{Uid: "glenda", Mode: fs.ModeDir | 0700, Length: 20}, }, &RError{}}, /* // TODO: change directory length to 0. - {0, "unko", "glenda", &Stat{Uid: "glenda", Mode: fs.ModeDir | 0700, Length: 10}, + {0, "hoge", "glenda", &Stat{Uid: "glenda", Mode: fs.ModeDir | 0700, Length: 10}, &TWstat{ Fid: 0, Stat: &Stat{Uid: "glenda", Mode: fs.ModeDir | 0700, Length:0}, }, &RWstat{}}, */ // 6 ok: change mode by owner - {0, "unko", "glenda", &Stat{Uid: "glenda", Mode: fs.ModeDir | 0700}, + {0, "hoge", "glenda", &Stat{Uid: "glenda", Mode: fs.ModeDir | 0700}, &TWstat{ Fid: 0, Stat: &Stat{Uid: "glenda", Mode: fs.ModeDir | 0755}, }, &RWstat{}}, // 7 ok: change mode by the leader - {0, "unko", "glenda", &Stat{Gid: "bell", Mode: fs.ModeDir | 0700}, + {0, "hoge", "glenda", &Stat{Gid: "bell", Mode: fs.ModeDir | 0700}, &TWstat{ Fid: 0, Stat: &Stat{Gid: "glenda", Mode: fs.ModeDir | 0755}, }, &RWstat{}}, // 8 permission denied: change mode by a non-leader member - {0, "unko", "ken", &Stat{Gid: "bell", Mode: fs.ModeDir | 0700}, + {0, "hoge", "ken", &Stat{Gid: "bell", Mode: fs.ModeDir | 0700}, &TWstat{ Fid: 0, Stat: &Stat{Gid: "glenda", Mode: fs.ModeDir | 0755}, }, &RError{}}, // 9 ok: change mtime by owner - {0, "unko", "glenda", &Stat{Uid: "glenda", Mtime: 1}, + {0, "hoge", "glenda", &Stat{Uid: "glenda", Mtime: 1}, &TWstat{ Fid: 0, Stat: &Stat{Uid: "glenda", Mtime: 0}, }, &RWstat{}}, // 10 ok: change mtime by the leader - {0, "unko", "glenda", &Stat{Gid: "bell", Mtime: 1}, + {0, "hoge", "glenda", &Stat{Gid: "bell", Mtime: 1}, &TWstat{ Fid: 0, Stat: &Stat{Gid: "bell", Mtime: 0}, }, &RWstat{}}, // 11 permission denied: change mtime by a non-leader member - {0, "unko", "ken", &Stat{Gid: "bell", Mtime: 0}, + {0, "hoge", "ken", &Stat{Gid: "bell", Mtime: 0}, &TWstat{ Fid: 0, Stat: &Stat{Gid: "bel", Mtime: 1}, }, &RError{}}, // 12 operation not permitted: change directory bit. - {0, "unko", "glenda", &Stat{Uid: "glenda", Mode: fs.ModeDir}, + {0, "hoge", "glenda", &Stat{Uid: "glenda", Mode: fs.ModeDir}, &TWstat{ Fid: 0, Stat: &Stat{Uid: "glenda"}, }, &RError{}}, // 13 ok: change gid by the owner, also a member of new group. - {0, "unko", "glenda", &Stat{Uid: "glenda", Gid: "kessoku"}, + {0, "hoge", "glenda", &Stat{Uid: "glenda", Gid: "kessoku"}, &TWstat{ Fid: 0, Stat: &Stat{Uid: "glenda", Gid: "bell"}, }, &RWstat{}}, // 14 ok: change gid by the leader, also the leader of new group. - {0, "unko", "glenda", &Stat{Uid: "ken", Gid: "glenda"}, + {0, "hoge", "glenda", &Stat{Uid: "ken", Gid: "glenda"}, &TWstat{ Fid: 0, Stat: &Stat{Uid: "ken", Gid: "bell"}, }, &RWstat{}}, // 15 permission denied: change gid by the leader, non-member of new group. - {0, "unko", "ken", &Stat{Uid: "glenda", Gid: "ken"}, + {0, "hoge", "ken", &Stat{Uid: "glenda", Gid: "ken"}, &TWstat{ Fid: 0, Stat: &Stat{Uid: "glenda", Gid: "kessoku"}, }, &RError{}}, // 16 permission denied: change gid by the owner, non-member of new group. - {0, "unko", "ken", &Stat{Uid: "glenda", Gid: "ken"}, + {0, "hoge", "ken", &Stat{Uid: "glenda", Gid: "ken"}, &TWstat{ Fid: 0, Stat: &Stat{Uid: "glenda", Gid: "kessoku"}, }, &RError{}}, // 17 operation not permitted: change uid - {0, "unko", "ken", &Stat{Uid: "glenda"}, + {0, "hoge", "ken", &Stat{Uid: "glenda"}, &TWstat{ Fid: 0, Stat: &Stat{Uid: "ken"}, }, &RError{}}, // 18 ok: change mode and gid. - {0, "unko", "glenda", &Stat{Gid: "bell", Mode: 0777}, + {0, "hoge", "glenda", &Stat{Gid: "bell", Mode: 0777}, &TWstat{ Fid: 0, Stat: &Stat{Gid: "glenda", Mode: 0755}, diff --git a/testdata/fs.go b/testdata/fs.go @@ -16,7 +16,7 @@ var FileTree = []struct { {"c", 0644, "glenda", "glenda", "glenda", ""}, {"d", fs.ModeDir | 0770, "glenda", "bell", "glenda", ""}, {"dir", fs.ModeDir | 0755, "rob", "rob", "rob", ""}, - {"dir/file", 0666, "brian", "brian", "dennis", "unko\n"}, + {"dir/file", 0666, "brian", "brian", "dennis", "hogehoge\n"}, } var Groups = []struct {