MCPcopy
hub / github.com/cli/cli / TestGlobPaths

Function TestGlobPaths

pkg/cmdutil/args_test.go:123–193  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

121}
122
123func TestGlobPaths(t *testing.T) {
124 tests := []struct {
125 name string
126 os string
127 patterns []string
128 wantOut []string
129 wantErr error
130 }{
131 {
132 name: "When no patterns are passed, return an empty slice",
133 patterns: []string{},
134 wantOut: []string{},
135 wantErr: nil,
136 },
137 {
138 name: "When no files match, it returns an empty expansions array with error",
139 patterns: []string{"foo"},
140 wantOut: []string{},
141 wantErr: errors.New("no matches found for `foo`"),
142 },
143 {
144 name: "When a single pattern, '*.txt' is passed with one match, it returns that match",
145 patterns: []string{
146 "*.txt",
147 },
148 wantOut: []string{
149 "rootFile.txt",
150 },
151 wantErr: nil,
152 },
153 {
154 name: "When a single pattern, '*/*.txt' is passed with multiple matches, it returns those matches",
155 patterns: []string{
156 "*/*.txt",
157 },
158 wantOut: []string{
159 filepath.Join("subDir1", "subDir1_file.txt"),
160 filepath.Join("subDir2", "subDir2_file.txt"),
161 },
162 wantErr: nil,
163 },
164 {
165 name: "When multiple patterns, '*/*.txt' and '*/*.go', are passed with multiple matches, it returns those matches",
166 patterns: []string{
167 "*/*.txt",
168 "*/*.go",
169 },
170 wantOut: []string{
171 filepath.Join("subDir1", "subDir1_file.txt"),
172 filepath.Join("subDir2", "subDir2_file.txt"),
173 filepath.Join("subDir2", "subDir2_file.go"),
174 },
175 wantErr: nil,
176 },
177 }
178
179 for _, tt := range tests {
180 t.Run(tt.name, func(t *testing.T) {

Callers

nothing calls this directly

Calls 6

createTestDirFunction · 0.85
GlobPathsFunction · 0.85
JoinMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected