commit 1796a15e227dac66761bdc47bf9a5096b391febe
parent da2d9eee90cb2f7fab51da1204496f293a4f9c8c
Author: Matsuda Kenji <info@mtkn.jp>
Date: Wed, 20 Dec 2023 08:30:35 +0900
update testfs
Diffstat:
1 file changed, 37 insertions(+), 3 deletions(-)
diff --git a/testfs/fs.go b/testfs/fs.go
@@ -19,7 +19,7 @@ type TestFile struct {
Content []byte
Reader *bytes.Reader
- St lib9p.Stat
+ St lib9p.Stat
}
func (f *TestFile) Stat() (fs.FileInfo, error) {
@@ -74,8 +74,14 @@ func (f *TestFile) WriteAt(p []byte, off int64) (int, error) {
}
type TestFS struct {
- Root *TestFile
- Slow bool
+ Root *TestFile
+ Slow bool
+ groups map[string]testGroup
+}
+
+type testGroup struct {
+ leader string
+ members map[string]bool
}
func (fs *TestFS) OpenFile(path string, omode lib9p.OpenMode) (lib9p.File, error) {
@@ -88,6 +94,22 @@ 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]
+ if !ok {
+ return false
+ }
+ return g.leader == uid
+}
+
+func (fs *TestFS) IsGroupMember(group, uid string) bool {
+ g, ok := fs.groups[group]
+ if !ok {
+ return false
+ }
+ return g.members[uid]
+}
+
func (fs *TestFS) Walk(wnames []string) (*TestFile, error) {
if len(wnames) == 1 && (wnames[0] == "." || wnames[0] == "") {
return fs.Root, nil
@@ -167,6 +189,18 @@ func init() {
},
},
},
+ groups: map[string]testGroup{
+ "bell": testGroup{
+ leader: "glenda",
+ members: map[string]bool{
+ "glenda": true,
+ "ken": true,
+ "dennis": true,
+ "brian": true,
+ "rob": true,
+ },
+ },
+ },
}
SetFsysAndParent(FS, nil)
}