MCPcopy Create free account
hub / github.com/cli/cli / TestGlobPaths

Function TestGlobPaths

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

Source from the content-addressed store, hash-verified

186}
187
188func TestGlobPaths(t *testing.T) {
189 tests := []struct {
190 name string
191 os string
192 patterns []string
193 wantOut []string
194 wantErr error
195 }{
196 {
197 name: "When no patterns are passed, return an empty slice",
198 patterns: []string{},
199 wantOut: []string{},
200 wantErr: nil,
201 },
202 {
203 name: "When no files match, it returns an empty expansions array with error",
204 patterns: []string{"foo"},
205 wantOut: []string{},
206 wantErr: errors.New("no matches found for `foo`"),
207 },
208 {
209 name: "When a single pattern, '*.txt' is passed with one match, it returns that match",
210 patterns: []string{
211 "*.txt",
212 },
213 wantOut: []string{
214 "rootFile.txt",
215 },
216 wantErr: nil,
217 },
218 {
219 name: "When a single pattern, '*/*.txt' is passed with multiple matches, it returns those matches",
220 patterns: []string{
221 "*/*.txt",
222 },
223 wantOut: []string{
224 filepath.Join("subDir1", "subDir1_file.txt"),
225 filepath.Join("subDir2", "subDir2_file.txt"),
226 },
227 wantErr: nil,
228 },
229 {
230 name: "When multiple patterns, '*/*.txt' and '*/*.go', are passed with multiple matches, it returns those matches",
231 patterns: []string{
232 "*/*.txt",
233 "*/*.go",
234 },
235 wantOut: []string{
236 filepath.Join("subDir1", "subDir1_file.txt"),
237 filepath.Join("subDir2", "subDir2_file.txt"),
238 filepath.Join("subDir2", "subDir2_file.go"),
239 },
240 wantErr: nil,
241 },
242 }
243
244 for _, tt := range tests {
245 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