MCPcopy
hub / github.com/akuity/kargo / TestParseNamePattern

Function TestParseNamePattern

pkg/pattern/matcher_test.go:9–86  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestParseNamePattern(t *testing.T) {
10 tests := []struct {
11 name string
12 pattern string
13 assertions func(*testing.T, Matcher, error)
14 }{
15 {
16 name: "exact pattern",
17 pattern: "exact",
18 assertions: func(t *testing.T, matcher Matcher, err error) {
19 assert.NoError(t, err)
20 assert.NotNil(t, matcher)
21 assert.IsType(t, &ExactMatcher{}, matcher)
22 assert.Equal(t, "exact", matcher.String())
23 },
24 },
25 {
26 name: "glob pattern",
27 pattern: "glob:*.txt",
28 assertions: func(t *testing.T, matcher Matcher, err error) {
29 assert.NoError(t, err)
30 assert.NotNil(t, matcher)
31 assert.IsType(t, &GlobMatcher{}, matcher)
32 assert.Equal(t, "*.txt", matcher.String())
33 },
34 },
35 {
36 name: "glob pattern with invalid syntax",
37 pattern: "glob:[",
38 assertions: func(t *testing.T, matcher Matcher, err error) {
39 assert.Error(t, err)
40 assert.Nil(t, matcher)
41 },
42 },
43 {
44 name: "regex pattern",
45 pattern: "regex:^dev-[a-zA-Z0-9]*",
46 assertions: func(t *testing.T, matcher Matcher, err error) {
47 assert.NoError(t, err)
48 assert.NotNil(t, matcher)
49 assert.IsType(t, &RegexpMatcher{}, matcher)
50 assert.Equal(t, "^dev-[a-zA-Z0-9]*", matcher.String())
51 },
52 },
53 {
54 name: "regex pattern with invalid syntax",
55 pattern: "regex:[a-z",
56 assertions: func(t *testing.T, matcher Matcher, err error) {
57 assert.Error(t, err)
58 assert.Nil(t, matcher)
59 },
60 },
61 {
62 name: "regexp pattern",
63 pattern: "regexp:^dev-[a-zA-Z0-9]*",
64 assertions: func(t *testing.T, matcher Matcher, err error) {
65 assert.NoError(t, err)
66 assert.NotNil(t, matcher)

Callers

nothing calls this directly

Calls 4

ParseNamePatternFunction · 0.85
StringMethod · 0.65
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected