-
Notifications
You must be signed in to change notification settings - Fork 8
/
tree_handler_programmably_mkdir_test.go
92 lines (87 loc) · 1.92 KB
/
tree_handler_programmably_mkdir_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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package gtree_test
import (
"context"
"fmt"
"testing"
"github.com/ddddddO/gtree"
tu "github.com/ddddddO/gtree/testutil"
)
func TestMkdirProgrammably(t *testing.T) {
tests := []struct {
name string
root *gtree.Node
options []gtree.Option
wantErr error
}{
{
name: "case(succeeded)",
root: tu.Prepare(),
},
{
name: "case(succeeded/massive)",
root: tu.Prepare_a(),
options: []gtree.Option{gtree.WithMassive(context.Background())},
},
{
name: "case(not root)",
root: tu.PrepareNotRoot(),
wantErr: gtree.ErrNotRoot,
},
{
name: "case(nil node)",
root: tu.PrepareNilNode(),
wantErr: gtree.ErrNilNode,
},
{
name: "case(succeeded)",
root: tu.PrepareMultiNode(),
},
{
name: "case(dry run/invalid node name)",
root: tu.PrepareInvalidNodeName(),
options: []gtree.Option{
gtree.WithDryRun(),
},
wantErr: fmt.Errorf("invalid node name: %s", "chi/ld 4"),
},
{
name: "case(dry run/succeeded)",
root: tu.PrepareMultiNode(),
options: []gtree.Option{
gtree.WithDryRun(),
},
wantErr: nil,
},
{
name: "case(dry run/specified file/succeeded)",
root: tu.PrepareMultiNode(),
options: []gtree.Option{
gtree.WithDryRun(),
gtree.WithFileExtensions([]string{"child 3", "child 5", "child 7", "child 8"}),
},
wantErr: nil,
},
{
name: "case(not dry run/invalid node name)",
root: tu.PrepareInvalidNodeName(),
wantErr: fmt.Errorf("invalid node name: %s", "chi/ld 4"),
},
{
name: "case(root already exists)",
root: tu.PrepareExistRoot(t),
wantErr: gtree.ErrExistPath,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
gotErr := gtree.MkdirProgrammably(tt.root, tt.options...)
if gotErr != nil {
if gotErr.Error() != tt.wantErr.Error() {
t.Errorf("\ngotErr: \n%v\nwantErr: \n%v", gotErr, tt.wantErr)
}
}
})
}
}