-
Notifications
You must be signed in to change notification settings - Fork 6
/
scenarios_test.go
38 lines (32 loc) · 946 Bytes
/
scenarios_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
package pathlib
import "fmt"
// The following functions provide different "scenarios"
// that you might encounter in a filesystem tree.
func HelloWorld(root *Path) error {
hello := root.Join("hello.txt")
return hello.WriteFile([]byte("hello world"))
}
func OneFile(root *Path, name string, content string) error {
file := root.Join(name)
return file.WriteFile([]byte(content))
}
func NFiles(root *Path, n int) error {
for i := 0; i < n; i++ {
if err := OneFile(root, fmt.Sprintf("file%d.txt", i), fmt.Sprintf("file%d contents", i)); err != nil {
return err
}
}
return nil
}
// TwoFilesAtRootTwoInSubdir creates two files in the root dir,
// a directory, and creates two files inside that new directory.
func TwoFilesAtRootTwoInSubdir(root *Path) error {
if err := NFiles(root, 2); err != nil {
return err
}
subdir := root.Join("subdir")
if err := subdir.Mkdir(); err != nil {
return err
}
return NFiles(subdir, 2)
}