lib9p

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

commit 34710a5171c50c7142098894d994242d4054904c
parent 2e7b49d195caaf38417c59d4b24e03c1f077622e
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Sat, 23 Dec 2023 09:49:22 +0900

rename testfs structs and variables

Diffstat:
Mclient/client_test.go | 4++--
Mreq_test.go | 4++--
Mserver_test.go | 8++++----
Mtestfs/fs.go | 68++++++++++++++++++++++++++++++++++----------------------------------
Muid_test.go | 2+-
5 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/client/client_test.go b/client/client_test.go @@ -100,7 +100,7 @@ func TestClientVersion(t *testing.T) { func TestTransaction(t *testing.T) { cr, sw := io.Pipe() sr, cw := io.Pipe() - server := lib9p.NewServer(testfs.FS, mSize, sr, sw) + server := lib9p.NewServer(testfs.Fsys, mSize, sr, sw) //server.Chatty() client := NewClient(mSize, uname, cr, cw) tPool := newTagPool() @@ -145,7 +145,7 @@ func TestClient2(t *testing.T) { cr, sw := io.Pipe() sr, cw := io.Pipe() - server := lib9p.NewServer(testfs.FS, mSize, sr, sw) + server := lib9p.NewServer(testfs.Fsys, mSize, sr, sw) //server.Chatty() go server.Serve(context.Background()) diff --git a/req_test.go b/req_test.go @@ -14,8 +14,8 @@ func TestFlush(t *testing.T) { mSize = 8 * 1024 uname = "kenji" ) - testfs.FS.Slow = true - defer func() { testfs.FS.Slow = false }() + testfs.Fsys.Slow = true + defer func() { testfs.Fsys.Slow = false }() conn := setupTestConn() defer conn.close() ctx := context.Background() diff --git a/server_test.go b/server_test.go @@ -30,7 +30,7 @@ func setupTestConn() *testConn { cr, sw := io.Pipe() sr, cw := io.Pipe() // TODO: fix the inconsistency of server and client api. - s := lib9p.NewServer(testfs.FS, mSize, sr, sw) + s := lib9p.NewServer(testfs.Fsys, mSize, sr, sw) c := client.NewClient(mSize, uname, cr, cw) ctx, cancel := context.WithCancel(context.Background()) go s.Serve(ctx) @@ -55,7 +55,7 @@ func (conn *testConn) close() { } // This function does the actual work for TestWalk(). -func testWalk(t *testing.T, fs *testfs.TestFS, pathname string, file *testfs.TestFile) { +func testWalk(t *testing.T, fs *testfs.FS, pathname string, file *testfs.File) { t.Logf("walk %s", pathname) f, err := fs.Walk(strings.Split(pathname, "/")) if err != nil { @@ -74,7 +74,7 @@ func testWalk(t *testing.T, fs *testfs.TestFS, pathname string, file *testfs.Tes // checks if all files can be opened without error and if // the opened file is the same as the file accessed via testFS.child func TestWalk(t *testing.T) { - testWalk(t, testfs.FS, ".", testfs.FS.Root) + testWalk(t, testfs.Fsys, ".", testfs.Fsys.Root) } // TODO: I don't know what this test acturally tests. @@ -155,7 +155,7 @@ func TestServer(t *testing.T) { } ctx, cancel := context.WithCancel(context.Background()) defer cancel() - s := lib9p.NewServer(testfs.FS, 1024, sr, sw) + s := lib9p.NewServer(testfs.Fsys, 1024, sr, sw) go s.Serve(ctx) for _, m := range msg { buf := lib9p.MarshalMsg(m) diff --git a/testfs/fs.go b/testfs/fs.go @@ -12,39 +12,39 @@ import ( const SleepTime = 10 * time.Millisecond -type TestFile struct { - Fsys *TestFS - Parent *TestFile - Children []*TestFile +type File struct { + Fsys *FS + Parent *File + Children []*File Content []byte Reader *bytes.Reader St lib9p.Stat } -func (f *TestFile) Stat() (fs.FileInfo, error) { +func (f *File) Stat() (fs.FileInfo, error) { return &lib9p.FileInfo{Stat: f.St}, nil } -func (f *TestFile) Close() error { +func (f *File) Close() error { f.Reader = nil return nil } -func (f *TestFile) Read(b []byte) (int, error) { +func (f *File) Read(b []byte) (int, error) { if f.Fsys.Slow { time.Sleep(SleepTime) } return f.Reader.Read(b) } -func (f *TestFile) ReadAt(b []byte, off int64) (n int, err error) { +func (f *File) ReadAt(b []byte, off int64) (n int, err error) { if f.Fsys.Slow { time.Sleep(SleepTime) } return f.Reader.ReadAt(b, off) } -func (f *TestFile) ReadDir(n int) ([]fs.DirEntry, error) { +func (f *File) ReadDir(n int) ([]fs.DirEntry, error) { de := make([]fs.DirEntry, len(f.Children)) for i, c := range f.Children { st, _ := c.Stat() @@ -53,7 +53,7 @@ func (f *TestFile) ReadDir(n int) ([]fs.DirEntry, error) { return de, nil } -func (f *TestFile) WriteAt(p []byte, off int64) (int, error) { +func (f *File) WriteAt(p []byte, off int64) (int, error) { if f.Fsys.Slow { time.Sleep(SleepTime) } @@ -73,18 +73,18 @@ func (f *TestFile) WriteAt(p []byte, off int64) (int, error) { return len(p), nil } -type TestFS struct { - Root *TestFile +type FS struct { + Root *File Slow bool - groups map[string]testGroup + groups map[string]group } -type testGroup struct { +type group struct { leader string members map[string]bool } -func (fs *TestFS) OpenFile(path string, omode lib9p.OpenMode) (lib9p.File, error) { +func (fs *FS) OpenFile(path string, omode lib9p.OpenMode) (lib9p.File, error) { wnames := strings.Split(path, "/") f, err := fs.Walk(wnames) if err != nil { @@ -94,23 +94,23 @@ func (fs *TestFS) OpenFile(path string, omode lib9p.OpenMode) (lib9p.File, error return f, nil } -func (fs *TestFS) IsGroupLeader(group, uid string) bool { - g, ok := fs.groups[group] +func (fs *FS) IsGroupLeader(gid, uid string) bool { + g, ok := fs.groups[gid] if !ok { return false } return g.leader == uid } -func (fs *TestFS) IsGroupMember(group, uid string) bool { - g, ok := fs.groups[group] +func (fs *FS) IsGroupMember(gid, uid string) bool { + g, ok := fs.groups[gid] if !ok { return false } return g.members[uid] } -func (fs *TestFS) Walk(wnames []string) (*TestFile, error) { +func (fs *FS) Walk(wnames []string) (*File, error) { if len(wnames) == 1 && (wnames[0] == "." || wnames[0] == "") { return fs.Root, nil } @@ -128,11 +128,11 @@ L: return cwd, nil } -var FS *TestFS +var Fsys *FS func init() { - FS = &TestFS{ - Root: &TestFile{ + Fsys = &FS{ + Root: &File{ St: lib9p.Stat{ Qid: lib9p.Qid{Path: 0, Type: lib9p.QTDIR}, Mode: lib9p.FileMode(fs.ModeDir | 0755), @@ -141,8 +141,8 @@ func init() { Gid: "glenda", Muid: "glenda", }, - Children: []*TestFile{ - &TestFile{ + Children: []*File{ + &File{ Content: []byte("a\n"), St: lib9p.Stat{ Qid: lib9p.Qid{Path: 1, Type: lib9p.QTFILE}, @@ -153,7 +153,7 @@ func init() { Muid: "glenda", }, }, - &TestFile{ + &File{ Content: []byte("b\n"), St: lib9p.Stat{ Qid: lib9p.Qid{Path: 2, Type: lib9p.QTFILE}, @@ -164,7 +164,7 @@ func init() { Muid: "ken", }, }, - &TestFile{ + &File{ St: lib9p.Stat{ Qid: lib9p.Qid{Path: 3, Type: lib9p.QTDIR}, Mode: lib9p.FileMode(fs.ModeDir | 0755), @@ -173,8 +173,8 @@ func init() { Gid: "rob", Muid: "rob", }, - Children: []*TestFile{ - &TestFile{ + Children: []*File{ + &File{ Content: []byte("unko\n"), St: lib9p.Stat{ Qid: lib9p.Qid{Path: 4, Type: lib9p.QTFILE}, @@ -189,8 +189,8 @@ func init() { }, }, }, - groups: map[string]testGroup{ - "bell": testGroup{ + groups: map[string]group{ + "bell": group{ leader: "glenda", members: map[string]bool{ "glenda": true, @@ -200,7 +200,7 @@ func init() { "rob": true, }, }, - "kessoku": testGroup{ + "kessoku": group{ leader: "ijichi", members: map[string]bool{ "ijichi": true, @@ -211,12 +211,12 @@ func init() { }, }, } - SetFsysAndParent(FS, nil) + 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. -func SetFsysAndParent(fsys *TestFS, file *TestFile) { +func SetFsysAndParent(fsys *FS, file *File) { if file == nil { file = fsys.Root file.Parent = fsys.Root diff --git a/uid_test.go b/uid_test.go @@ -20,7 +20,7 @@ func TestHasPerm(t *testing.T) { {lib9p.Stat{Mode: 0000, Uid: "gotoh", Gid: "kessoku"}, "gotoh", 04, false}, } for i, test := range tests { - if got := lib9p.HasPerm(testfs.FS, &lib9p.FileInfo{test.st}, test.uid, test.perm); got != test.want { + if got := lib9p.HasPerm(testfs.Fsys, &lib9p.FileInfo{test.st}, test.uid, test.perm); got != test.want { t.Errorf("hasPerm(pfs, file[%d], %s, 0%o) == %t\n", i, test.uid, test.perm, got) continue