8 func TestFilterReadOnly(t *testing.T) {
9 fs := &ReadOnlyFs{source: &MemMapFs{}}
10 _, err := fs.Create("/file.txt")
12 t.Errorf("Did not fail to create file")
14 // t.Logf("ERR=%s", err)
17 func TestFilterReadonlyRemoveAndRead(t *testing.T) {
19 fh, err := mfs.Create("/file.txt")
20 fh.Write([]byte("content here"))
23 fs := NewReadOnlyFs(mfs)
24 err = fs.Remove("/file.txt")
26 t.Errorf("Did not fail to remove file")
29 fh, err = fs.Open("/file.txt")
31 t.Errorf("Failed to open file: %s", err)
34 buf := make([]byte, len("content here"))
37 if string(buf) != "content here" {
38 t.Errorf("Failed to read file: %s", err)
41 err = mfs.Remove("/file.txt")
43 t.Errorf("Failed to remove file")
46 fh, err = fs.Open("/file.txt")
49 t.Errorf("File still present")
53 func TestFilterRegexp(t *testing.T) {
54 fs := NewRegexpFs(&MemMapFs{}, regexp.MustCompile(`\.txt$`))
55 _, err := fs.Create("/file.html")
58 t.Errorf("Did not fail to create file")
60 // t.Logf("ERR=%s", err)
63 func TestFilterRORegexpChain(t *testing.T) {
64 rofs := &ReadOnlyFs{source: &MemMapFs{}}
65 fs := &RegexpFs{re: regexp.MustCompile(`\.txt$`), source: rofs}
66 _, err := fs.Create("/file.txt")
68 t.Errorf("Did not fail to create file")
70 // t.Logf("ERR=%s", err)
73 func TestFilterRegexReadDir(t *testing.T) {
75 fs1 := &RegexpFs{re: regexp.MustCompile(`\.txt$`), source: mfs}
76 fs := &RegexpFs{re: regexp.MustCompile(`^a`), source: fs1}
78 mfs.MkdirAll("/dir/sub", 0777)
79 for _, name := range []string{"afile.txt", "afile.html", "bfile.txt"} {
80 for _, dir := range []string{"/dir/", "/dir/sub/"} {
81 fh, _ := mfs.Create(dir + name)
86 files, _ := ReadDir(fs, "/dir")
87 if len(files) != 2 { // afile.txt, sub
88 t.Errorf("Got wrong number of files: %#v", files)
91 f, _ := fs.Open("/dir/sub")
92 names, _ := f.Readdirnames(-1)
94 t.Errorf("Got wrong number of names: %v", names)