commit 44459189bd0cc96547ebcd3cddba7b4f499e05c9
parent 529c62c9b81f88f07d060489c8d09c3634e55c64
Author: Matsuda Kenji <info@mtkn.jp>
Date: Fri, 20 Oct 2023 11:17:35 +0900
add slow option for testFS
Diffstat:
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/test_fs.go b/test_fs.go
@@ -6,8 +6,11 @@ import (
"io/fs"
"path"
"strings"
+ "time"
)
+const sleepTime = 100 * time.Second
+
type testFile struct {
fsys *testFS
parent *testFile
@@ -18,21 +21,35 @@ type testFile struct {
stat Stat
}
-func (f *testFile) Stat() (*FileInfo, error) { return &FileInfo{Stat: f.stat}, nil }
+func (f *testFile) Stat() (*FileInfo, error) {
+ if f.fsys.slow {
+ time.Sleep(sleepTime)
+ }
+ return &FileInfo{Stat: f.stat}, nil
+}
func (f *testFile) Close() error {
f.reader = nil
return nil
}
func (f *testFile) 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) {
+ if f.fsys.slow {
+ time.Sleep(sleepTime)
+ }
return f.reader.ReadAt(b, off)
}
func (f *testFile) ReadDir(n int) ([]*DirEntry, error) {
+ if f.fsys.slow {
+ time.Sleep(sleepTime)
+ }
de := make([]*DirEntry, len(f.children))
for i, c := range f.children {
de[i], _ = c.Stat()
@@ -41,6 +58,9 @@ func (f *testFile) ReadDir(n int) ([]*DirEntry, error) {
}
func (f *testFile) WriteAt(p []byte, off int64) (int, error) {
+ if f.fsys.slow {
+ time.Sleep(sleepTime)
+ }
if f.reader == nil {
return 0, fmt.Errorf("not open")
}
@@ -53,7 +73,6 @@ func (f *testFile) WriteAt(p []byte, off int64) (int, error) {
copy(newcon, f.content)
f.content = newcon
}
-
copy(f.content[off:], p)
f.reader.Reset(f.content)
return len(p), nil
@@ -61,9 +80,13 @@ func (f *testFile) WriteAt(p []byte, off int64) (int, error) {
type testFS struct {
root *testFile
+ slow bool
}
func (fs *testFS) OpenFile(path string, omode OpenMode, perm fs.FileMode) (File, error) {
+ if fs.slow {
+ time.Sleep(sleepTime)
+ }
path = clean9path(path)
wnames := split9path(path)
f, err := fs.walk(wnames)