1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
14 func TestOpenRoot(t *testing.T) {
15 fs := New(map[string]string{
16 "foo/bar/three.txt": "a",
25 {"/foo/bar/three.txt", "a"},
26 {"foo/bar/three.txt", "a"},
30 {"other-top.txt", "d"},
31 {"/other-top.txt", "d"},
33 for _, tt := range tests {
34 rsc, err := fs.Open(tt.path)
36 t.Errorf("Open(%q) = %v", tt.path, err)
39 slurp, err := ioutil.ReadAll(rsc)
43 if string(slurp) != tt.want {
44 t.Errorf("Read(%q) = %q; want %q", tt.path, tt.want, slurp)
49 _, err := fs.Open("/xxxx")
50 if !os.IsNotExist(err) {
51 t.Errorf("ReadDir /xxxx = %v; want os.IsNotExist error", err)
55 func TestReaddir(t *testing.T) {
56 fs := New(map[string]string{
57 "foo/bar/three.txt": "333",
59 "top.txt": "top.txt file",
60 "other-top.txt": "other-top.txt file",
69 mapFI{name: "foo", dir: true},
70 mapFI{name: "other-top.txt", size: len("other-top.txt file")},
71 mapFI{name: "top.txt", size: len("top.txt file")},
77 mapFI{name: "bar", dir: true},
78 mapFI{name: "bar.txt", size: 2},
84 mapFI{name: "bar", dir: true},
85 mapFI{name: "bar.txt", size: 2},
91 mapFI{name: "three.txt", size: 3},
95 for _, tt := range tests {
96 fis, err := fs.ReadDir(tt.dir)
98 t.Errorf("ReadDir(%q) = %v", tt.dir, err)
101 if !reflect.DeepEqual(fis, tt.want) {
102 t.Errorf("ReadDir(%q) = %#v; want %#v", tt.dir, fis, tt.want)
107 _, err := fs.ReadDir("/xxxx")
108 if !os.IsNotExist(err) {
109 t.Errorf("ReadDir /xxxx = %v; want os.IsNotExist error", err)