(t *testing.T)
| 21 | ) |
| 22 | |
| 23 | func TestNewDockerPatternMatcher(t *testing.T) { |
| 24 | tests := []struct { |
| 25 | name string |
| 26 | repoRoot string |
| 27 | patterns []string |
| 28 | expectedErr bool |
| 29 | expectedRoot string |
| 30 | expectedPat []string |
| 31 | }{ |
| 32 | { |
| 33 | name: "Basic patterns without wildcard", |
| 34 | repoRoot: "/repo", |
| 35 | patterns: []string{"dir1/", "file.txt"}, |
| 36 | expectedErr: false, |
| 37 | expectedRoot: "/repo", |
| 38 | expectedPat: []string{"/repo/dir1", "/repo/file.txt"}, |
| 39 | }, |
| 40 | { |
| 41 | name: "Patterns with exclusion", |
| 42 | repoRoot: "/repo", |
| 43 | patterns: []string{"dir1/", "!file.txt"}, |
| 44 | expectedErr: false, |
| 45 | expectedRoot: "/repo", |
| 46 | expectedPat: []string{"/repo/dir1", "!/repo/file.txt"}, |
| 47 | }, |
| 48 | { |
| 49 | name: "Wildcard with exclusion", |
| 50 | repoRoot: "/repo", |
| 51 | patterns: []string{"*", "!file.txt"}, |
| 52 | expectedErr: false, |
| 53 | expectedRoot: "/repo", |
| 54 | expectedPat: []string{"!/repo/file.txt"}, |
| 55 | }, |
| 56 | { |
| 57 | name: "No patterns", |
| 58 | repoRoot: "/repo", |
| 59 | patterns: []string{}, |
| 60 | expectedErr: false, |
| 61 | expectedRoot: "/repo", |
| 62 | expectedPat: nil, |
| 63 | }, |
| 64 | { |
| 65 | name: "Only exclusion pattern", |
| 66 | repoRoot: "/repo", |
| 67 | patterns: []string{"!file.txt"}, |
| 68 | expectedErr: false, |
| 69 | expectedRoot: "/repo", |
| 70 | expectedPat: []string{"!/repo/file.txt"}, |
| 71 | }, |
| 72 | } |
| 73 | |
| 74 | for _, tt := range tests { |
| 75 | t.Run(tt.name, func(t *testing.T) { |
| 76 | // Call the function with the test data |
| 77 | matcher, err := NewDockerPatternMatcher(tt.repoRoot, tt.patterns) |
| 78 | |
| 79 | // Check if we expect an error |
| 80 | if (err != nil) != tt.expectedErr { |
nothing calls this directly
no test coverage detected