master
go 81 lines 1.81 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package pipeline
4
5 import (
6 "testing"
7
8 "github.com/stretchr/testify/assert"
9 )
10
11 func Test_funcMatchAny(t *testing.T) {
12 tests := map[string]struct {
13 typ string
14 patterns []string
15 value string
16 wantMatch bool
17 }{
18 "dstar: one param, matches": {
19 wantMatch: true,
20 typ: "dstar",
21 patterns: []string{"*"},
22 value: "value",
23 },
24 "dstar: one param, matches with *": {
25 wantMatch: true,
26 typ: "dstar",
27 patterns: []string{"**/value"},
28 value: "/one/two/three/value",
29 },
30 "dstar: one param, not matches": {
31 wantMatch: false,
32 typ: "dstar",
33 patterns: []string{"Value"},
34 value: "value",
35 },
36 "dstar: several params, last one matches": {
37 wantMatch: true,
38 typ: "dstar",
39 patterns: []string{"not", "matches", "*"},
40 value: "value",
41 },
42 "dstar: several params, no matches": {
43 wantMatch: false,
44 typ: "dstar",
45 patterns: []string{"not", "matches", "really"},
46 value: "value",
47 },
48 "re: one param, matches": {
49 wantMatch: true,
50 typ: "re",
51 patterns: []string{"^value$"},
52 value: "value",
53 },
54 "re: one param, not matches": {
55 wantMatch: false,
56 typ: "re",
57 patterns: []string{"^Value$"},
58 value: "value",
59 },
60 "re: several params, last one matches": {
61 wantMatch: true,
62 typ: "re",
63 patterns: []string{"not", "matches", "va[lue]{3}"},
64 value: "value",
65 },
66 "re: several params, no matches": {
67 wantMatch: false,
68 typ: "re",
69 patterns: []string{"not", "matches", "val[^l]ue"},
70 value: "value",
71 },
72 }
73
74 for name, test := range tests {
75 t.Run(name, func(t *testing.T) {
76 ok := funcMatchAny(test.typ, test.value, test.patterns[0], test.patterns[1:]...)
77
78 assert.Equal(t, test.wantMatch, ok)
79 })
80 }
81 }