forked from zpatrick/rbac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
string_test.go
48 lines (43 loc) · 783 Bytes
/
string_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package rbac
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestStringMatch(t *testing.T) {
cases := map[string]map[string]bool{
"": {
"": true,
"alpha": false,
"beta": false,
},
"alpha": {
"": false,
"alpha": true,
"beta": false,
},
"beta": {
"": false,
"alpha": false,
"beta": true,
},
"charlie": {
"": false,
"alpha": false,
"beta": false,
},
}
for pattern, inputs := range cases {
matcher := StringMatch(pattern)
for input, expected := range inputs {
name := fmt.Sprintf("%s/%s", pattern, input)
t.Run(name, func(t *testing.T) {
result, err := matcher(input)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, expected, result)
})
}
}
}