(t *testing.T)
| 412 | } |
| 413 | |
| 414 | func TestURLPatterns(t *testing.T) { |
| 415 | tests := []struct { |
| 416 | input string |
| 417 | wantLen int |
| 418 | shouldMatch []string |
| 419 | shouldntMatch []string |
| 420 | }{ |
| 421 | {input: "", wantLen: 0}, |
| 422 | {input: "*.jpg,*.png", wantLen: 2}, |
| 423 | { |
| 424 | input: "image*.jpg", |
| 425 | wantLen: 1, |
| 426 | shouldMatch: []string{"image123.jpg"}, |
| 427 | shouldntMatch: []string{"photo.jpg"}, |
| 428 | }, |
| 429 | { |
| 430 | input: "images/*/photo.jpg", |
| 431 | wantLen: 1, |
| 432 | shouldMatch: []string{"images/vacation/photo.jpg"}, |
| 433 | shouldntMatch: []string{"images/a/b/photo.jpg"}, |
| 434 | }, |
| 435 | } |
| 436 | |
| 437 | for _, tt := range tests { |
| 438 | t.Run(tt.input, func(t *testing.T) { |
| 439 | t.Setenv(testVar, tt.input) |
| 440 | desc := env.URLPatterns(testVar) |
| 441 | |
| 442 | var result []*regexp.Regexp |
| 443 | require.NoError(t, desc.Parse(&result)) |
| 444 | |
| 445 | assert.Len(t, result, tt.wantLen) |
| 446 | if len(result) > 0 { |
| 447 | for _, match := range tt.shouldMatch { |
| 448 | assert.True(t, result[0].MatchString(match)) |
| 449 | } |
| 450 | for _, noMatch := range tt.shouldntMatch { |
| 451 | assert.False(t, result[0].MatchString(noMatch)) |
| 452 | } |
| 453 | } |
| 454 | }) |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | func TestHexSlice(t *testing.T) { |
| 459 | tests := []struct { |
nothing calls this directly
no test coverage detected