-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsub_test.go
49 lines (43 loc) · 1.12 KB
/
sub_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
38
39
40
41
42
43
44
45
46
47
48
49
package hackpadfs_test
import (
"path"
"testing"
"github.com/hack-pad/hackpadfs"
"github.com/hack-pad/hackpadfs/fstest"
"github.com/hack-pad/hackpadfs/internal/assert"
"github.com/hack-pad/hackpadfs/mem"
)
func TestSub(t *testing.T) {
t.Parallel()
options := fstest.FSOptions{
Name: "sub",
Setup: fstest.TestSetupFunc(setupSubFS),
}
data := fstest.FS(t, options)
assert.Zero(t, data.Skips)
options.Constraints = fstest.Constraints{
AllowErrPathPrefix: true,
}
data = fstest.File(t, options)
assert.Zero(t, data.Skips)
}
func setupSubFS(tb testing.TB) (fstest.SetupFS, func() hackpadfs.FS) {
memRoot, err := mem.NewFS()
requireNoError(tb, err)
return memRoot, func() hackpadfs.FS {
const subDir = "subfs-subdir"
requireNoError(tb, memRoot.Mkdir(subDir, 0o700))
dirEntries, err := hackpadfs.ReadDir(memRoot, ".")
requireNoError(tb, err)
for _, entry := range dirEntries {
if entry.Name() == subDir {
continue
}
err := memRoot.Rename(entry.Name(), path.Join(subDir, entry.Name()))
requireNoError(tb, err)
}
fs, err := hackpadfs.Sub(memRoot, subDir)
requireNoError(tb, err)
return fs
}
}