-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathglob_test.go
37 lines (30 loc) · 1003 Bytes
/
glob_test.go
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
package mergefs
import (
"io/fs"
"testing"
"testing/fstest"
"github.com/stretchr/testify/require"
)
func TestGlob(t *testing.T) {
var aFS fs.GlobFS = fstest.MapFS{
"testdata": &fstest.MapFile{Mode: fs.ModeDir},
"testdata/a": &fstest.MapFile{Mode: fs.ModeDir},
"testdata/a/y": &fstest.MapFile{Mode: fs.ModeDir},
"testdata/a/y/foo.conf": &fstest.MapFile{Data: []byte("bar")},
}
var bFS fs.GlobFS = fstest.MapFS{
"testdata": &fstest.MapFile{Mode: fs.ModeDir},
"testdata/b": &fstest.MapFile{Mode: fs.ModeDir},
"testdata/b/y": &fstest.MapFile{Mode: fs.ModeDir},
"testdata/b/y/bar.conf": &fstest.MapFile{Data: []byte("bar")},
}
mfs := Merge(aFS, bFS)
matches, err := fs.Glob(mfs, "testdata/*/*/*.conf")
require.NoError(t, err)
require.Len(t, matches, 2)
gmfs, ok := mfs.(fs.GlobFS)
require.True(t, ok)
matches, err = gmfs.Glob("testdata/*/*/*.conf")
require.NoError(t, err)
require.Len(t, matches, 2)
}