Add glob support

This commit is contained in:
Jingfang Liu
2018-06-21 15:58:37 -07:00
parent c25ed7f7bc
commit 6392e6629f
8 changed files with 147 additions and 10 deletions

View File

@@ -71,6 +71,18 @@ func (fs *FakeFS) ReadFile(name string) ([]byte, error) {
return nil, fmt.Errorf("cannot read file %q", name)
}
// ReadFiles looks through all files in the fake filesystem
// and find the matching files and then read content from all of them
func (fs *FakeFS) ReadFiles(name string) (map[string][]byte, error) {
result := map[string][]byte{}
for p, f := range fs.m {
if fs.pathMatch(p, name) {
result[p] = f.content
}
}
return result, nil
}
// WriteFile always succeeds and does nothing.
func (fs *FakeFS) WriteFile(name string, c []byte) error {
ff := &FakeFile{}
@@ -78,3 +90,10 @@ func (fs *FakeFS) WriteFile(name string, c []byte) error {
fs.m[name] = ff
return nil
}
func (fs *FakeFS) pathMatch(path, pattern string) bool {
if path == pattern {
return true
}
return false
}