Skip to content

Commit b4d3f5c

Browse files
committed
feat: add TestMatchStringWithMask
1 parent 8d9b44b commit b4d3f5c

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

internal/provider/utils_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package provider
2+
3+
import "testing"
4+
5+
func TestMatchStringWithMask(t *testing.T) {
6+
t.Parallel()
7+
8+
testCases := []struct {
9+
target string
10+
mask string
11+
expected bool
12+
}{
13+
{
14+
target: "sk-my-secret-key",
15+
mask: "sk-my-secret-key",
16+
expected: true,
17+
},
18+
{
19+
target: "sk-my-secret-key",
20+
mask: "sk-my-se************************************************************key",
21+
expected: true,
22+
},
23+
{
24+
target: "sk-my-secret-key",
25+
mask: "sk-my-*-key",
26+
expected: true,
27+
},
28+
{
29+
target: "sk-my-secret-key",
30+
mask: "sk-my-secret-key-2",
31+
expected: false,
32+
},
33+
{
34+
target: "sk-my-secret-key",
35+
mask: "sk-my-*-key-2",
36+
expected: false,
37+
},
38+
}
39+
40+
for _, tc := range testCases {
41+
t.Run(tc.target, func(t *testing.T) {
42+
actual := MatchStringWithMask(tc.target, tc.mask)
43+
if actual != tc.expected {
44+
t.Errorf("expected %v, got %v", tc.expected, actual)
45+
}
46+
})
47+
}
48+
}

0 commit comments

Comments
 (0)