MCPcopy Create free account
hub / github.com/docker/secrets-engine / TestParsePattern

Function TestParsePattern

x/secrets/pattern_test.go:25–55  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestParsePattern(t *testing.T) {
26 tests := []struct {
27 name string
28 input string
29 expected error
30 }{
31 {"valid pattern with single component", "foo", nil},
32 {"valid pattern with multiple components", "foo/bar/baz", nil},
33 {"valid pattern only with asterisk", "*", nil},
34 {"valid pattern only with double asterisk", "**", nil},
35 {"valid pattern starting with asterisk", "*/bar", nil},
36 {"valid pattern ending with asterisk", "foo/*/baz", nil},
37 {"valid pattern starting with double asterisk", "**/bar", nil},
38 {"valid pattern ending with double asterisk", "foo/**/baz", nil},
39 {"valid pattern with mix of components and wildcards", "foo/*/baz/**/*", nil},
40 {"invalid pattern with mix of asterisks and allowed characters v1", "*a*", ErrInvalidPattern},
41 {"invalid pattern with mix of asterisks and allowed characters v2", "*a", ErrInvalidPattern},
42 {"invalid pattern with leading slash", "/foo/bar", ErrInvalidPattern},
43 {"invalid pattern with trailing slash", "foo/bar/", ErrInvalidPattern},
44 {"invalid pattern with empty component", "foo//bar", ErrInvalidPattern},
45 {"invalid empty pattern", "", ErrInvalidPattern},
46 {"invalid pattern only with slash", "/", ErrInvalidPattern},
47 {"invalid pattern with components and a mix of asterisks and allowed characters", "foo/*a*/baz", ErrInvalidPattern},
48 }
49 for _, tc := range tests {
50 t.Run(tc.name, func(t *testing.T) {
51 _, err := ParsePattern(tc.input)
52 assert.ErrorIs(t, err, tc.expected)
53 })
54 }
55}
56
57func TestPatternComparable(t *testing.T) {
58 a := MustParsePattern("foo")

Callers

nothing calls this directly

Calls 2

ParsePatternFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected