-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfs_test.go
More file actions
72 lines (68 loc) · 1.55 KB
/
fs_test.go
File metadata and controls
72 lines (68 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package cachefs_test
import (
"io/fs"
"os"
"strings"
"sync"
"testing"
"time"
"github.com/ancientlore/cachefs"
)
func TestFS(t *testing.T) {
const count = 10
fileSys := cachefs.New(os.DirFS("."), &cachefs.Config{GroupName: "TestFS", SizeInBytes: 10 * 1024 * 1024, Duration: 10 * time.Second})
var wg sync.WaitGroup
wg.Add(count)
for i := 0; i < count; i++ {
go func() {
defer wg.Done()
numEntries := 0
fs.WalkDir(fileSys, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
t.Error(err)
}
if path == "" {
t.Error("Path is empty")
}
t.Log(path, d, err)
numEntries++
if !d.IsDir() {
b, err := fs.ReadFile(fileSys, path)
if err != nil {
t.Errorf("Cannot read %q: %v", path, err)
}
if len(b) == 0 {
t.Errorf("File %q has no data", path)
}
} else {
if d.Name() == ".git" {
return fs.SkipDir
}
_, err := fs.ReadDir(fileSys, path)
if err != nil {
t.Errorf("Cannot readdir %q: %v", path, err)
}
}
fi, err := fs.Stat(fileSys, path)
if err != nil {
t.Errorf("Cannot stat %q: %v", path, err)
}
if !strings.HasSuffix(path, fi.Name()) {
t.Errorf("%q should be part of %q", fi.Name(), path)
}
if !fi.IsDir() {
if fi.Size() == 0 {
t.Errorf("Expected %q to have non-zero size", path)
}
}
if fi.ModTime().IsZero() {
t.Errorf("Expected %q to have non-zero mod time", path)
}
t.Log(fi)
return nil
})
t.Logf("saw %d entries", numEntries)
}()
}
wg.Wait()
}