| 186 | } |
| 187 | |
| 188 | func 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) { |