|
| 1 | +package secrets |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | +) |
| 8 | + |
| 9 | +func TestParsePattern(t *testing.T) { |
| 10 | + tests := []struct { |
| 11 | + name string |
| 12 | + input string |
| 13 | + outErr bool |
| 14 | + }{ |
| 15 | + {"valid pattern with single component", "foo", false}, |
| 16 | + {"valid pattern with multiple components", "foo/bar/baz", false}, |
| 17 | + {"valid pattern only with asterisk", "*", false}, |
| 18 | + {"valid pattern only with double asterisk", "**", false}, |
| 19 | + {"valid pattern starting with asterisk", "*/bar", false}, |
| 20 | + {"valid pattern ending with asterisk", "foo/*/baz", false}, |
| 21 | + {"valid pattern starting with double asterisk", "**/bar", false}, |
| 22 | + {"valid pattern ending with double asterisk", "foo/**/baz", false}, |
| 23 | + {"valid pattern with mix of components and wildcards", "foo/*/baz/**/*", false}, |
| 24 | + {"invalid pattern with leading slash", "/foo/bar", true}, |
| 25 | + {"invalid pattern with trailing slash", "foo/bar/", true}, |
| 26 | + {"invalid pattern with empty component", "foo//bar", true}, |
| 27 | + {"invalid empty pattern", "", true}, |
| 28 | + {"invalid pattern only with slash", "/", true}, |
| 29 | + {"invalid pattern with mix of asterisks and allowed characters", "foo/*a*/baz", true}, |
| 30 | + } |
| 31 | + for _, tc := range tests { |
| 32 | + t.Run(tc.name, func(t *testing.T) { |
| 33 | + _, err := ParsePattern(tc.input) |
| 34 | + if tc.outErr { |
| 35 | + assert.Error(t, err) |
| 36 | + } else { |
| 37 | + assert.NoError(t, err) |
| 38 | + } |
| 39 | + }) |
| 40 | + } |
| 41 | +} |
0 commit comments