Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
100 lines (92 loc) · 2.88 KB

File metadata and controls

100 lines (92 loc) · 2.88 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
93
94
95
96
97
98
99
100
package gtree_test
import (
"fmt"
"path/filepath"
"testing"
"github.com/ddddddO/gtree"
)
func TestVerifyFromRoot(t *testing.T) {
tests := []struct {
name string
root *gtree.Node
options []gtree.Option
wantErr error
}{
{
name: "case(succeeded/massive)",
root: prepareDirectoryRoot(),
options: []gtree.Option{gtree.WithMassive(nil)},
wantErr: nil,
},
{
name: "case(succeeded/specify target dir/strict mode)",
root: prepareDirectoryFindPipe(),
options: []gtree.Option{gtree.WithTargetDir("example"), gtree.WithStrictVerify(), gtree.WithMassive(nil)},
wantErr: nil,
},
{
name: "case(error/specify target dir)",
root: prepareDirectoryFindPipeWithNoExistDirAndRequiredDir(),
options: []gtree.Option{gtree.WithTargetDir("example"), gtree.WithMassive(nil)},
wantErr: fmt.Errorf("Required paths does not exist:\n%s",
fmt.Sprintf("\t%s", filepath.Join("example", "find_pipe_programmable-gtree", "required!")),
),
},
{
name: "case(error/specify target dir/strict mode)",
root: prepareDirectoryFindPipeWithNoExistDirAndRequiredDir(),
options: []gtree.Option{gtree.WithTargetDir("example"), gtree.WithStrictVerify(), gtree.WithMassive(nil)},
wantErr: fmt.Errorf("Extra paths exist:\n%s\nRequired paths does not exist:\n%s",
fmt.Sprintf("\t%s", filepath.Join("example", "find_pipe_programmable-gtree", "main.go")),
fmt.Sprintf("\t%s", filepath.Join("example", "find_pipe_programmable-gtree", "required!")),
),
},
{
name: "case(error/no exist root)",
root: gtree.NewRoot("no_exist_root_dir"),
options: []gtree.Option{gtree.WithMassive(nil)},
wantErr: fmt.Errorf("Required paths does not exist:\n%s",
fmt.Sprintf("\t%s", "no_exist_root_dir"),
),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
gotErr := gtree.VerifyFromRoot(tt.root, tt.options...)
if gotErr != nil || tt.wantErr != nil {
if gotErr.Error() != tt.wantErr.Error() {
t.Errorf("\ngotErr: \n%s\nwantErr: \n%s", gotErr, tt.wantErr)
}
}
})
}
}
func prepareDirectoryRoot() *gtree.Node {
root := gtree.NewRoot("example")
root.Add("find_pipe_programmable-gtree").Add("main.go")
root.Add("go-list_pipe_programmable-gtree").Add("main.go")
likeCLI := root.Add("like_cli")
adapter := likeCLI.Add("adapter")
adapter.Add("executor.go")
adapter.Add("indentation.go")
likeCLI.Add("main.go")
root.Add("programmable").Add("main.go")
return root
}
func prepareDirectoryFindPipe() *gtree.Node {
root := gtree.NewRoot("find_pipe_programmable-gtree")
root.Add("go.mod")
root.Add("go.sum")
root.Add("main.go")
root.Add("README.md")
return root
}
func prepareDirectoryFindPipeWithNoExistDirAndRequiredDir() *gtree.Node {
root := gtree.NewRoot("find_pipe_programmable-gtree")
root.Add("go.mod")
root.Add("go.sum")
root.Add("required!")
root.Add("README.md")
return root
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.