-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
64 lines (61 loc) · 2.03 KB
/
utils_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package emitter
import (
"testing"
)
func TestMatchTopicPattern(t *testing.T) {
tests := []struct {
pattern string
subject string
want bool
}{
// Exact matches
{"event.some.thing.run", "event.some.thing.run", true},
// Single node wildcard matches
{"event.some.*.*", "event.some.thing.run", true},
{"event.some.*.*", "event.some.thing.do", true},
{"event.*", "event.some", true},
{"event.*", "event.some.thing", false},
{"event.some.*.run", "event.some.thing.run", true},
// Single node wildcard non-matches
{"event.some.*.run", "event.some.thing.do", false},
{"event.*.thing.run", "event.some.thing.do", false},
{"*.some.thing.run", "event.some.thing.do", false},
{"event.some.*.run", "event.some.thing", false},
// Multi-node wildcard matches
{"event.some.**", "event.some.thing.run", true},
{"event.some.**", "event.some.thing.do", true},
{"**.thing.run", "event.some.thing.run", true},
{"event.**", "event.some.thing.run", true},
{"event.**.run", "event.some.thing.run", true},
{"**", "event.some.thing.run", true},
{"**", "event", true},
{"**", "", true},
// Multi-node wildcard non-matches
{"event.**", "event", false},
{"event.**.run", "event.some.thing.do", false},
{"event.some.thing.**", "event.some.other.thing.run", false},
{"**.thing.run", "event.some.thing.do", false},
// Edge cases
{"*", "", true},
{"*", "event", true},
{"*", "event.some", false},
{"*", "event.some.thing", false},
{"event.*", "event", false},
{"event.*", "event.some", true},
{"event.*", "event.some.thing", false},
{"**", "", true},
{"**", "event.some", true},
{"**", "event.some.thing", true},
{"**", "event.some.thing.do", true},
{"**", "event", true},
{"event.**", "event.some", true},
{"event.**", "event.some.thing", true},
}
for _, tt := range tests {
t.Run(tt.pattern+"_"+tt.subject, func(t *testing.T) {
if got := matchTopicPattern(tt.pattern, tt.subject); got != tt.want {
t.Errorf("matchTopicPattern(%q, %q) = %v, want %v", tt.pattern, tt.subject, got, tt.want)
}
})
}
}