-
Notifications
You must be signed in to change notification settings - Fork 1
/
matcher_test.go
79 lines (61 loc) · 1.64 KB
/
matcher_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package gopl
import "testing"
func TestDefaultURLMatcher_Match(t *testing.T) {
pack := NewDataFrame()
pack.setTopic("/gms/test/topic")
matcher, err := NewDefaultURLMatcher("/gms/test/topic")
if nil != err {
t.Fatalf("Failed to create url matcher")
panic(err)
}
if !matcher.Match(pack) {
t.Fatalf("Not match")
}
}
func TestDefaultURLMatcher_Match2(t *testing.T) {
pack := NewDataFrame()
pack.setTopic("gms://test.com/topic")
matcher, err := NewDefaultURLMatcher("gms://test.com/topic")
if nil != err {
t.Fatalf("Failed to create url matcher")
panic(err)
}
if !matcher.Match(pack) {
t.Fatalf("Not match")
}
}
func TestDefaultURLMatcher_MatchHeaders(t *testing.T) {
pack := NewDataFrame()
pack.setTopic("/gms/test/topic")
pack.SetHeader("version", "2018")
pack.SetDataFrameType("test.pack.type")
matcher, err := NewDefaultURLMatcher("/gms/test/topic?version=2018&pack.type=test.pack.type")
if nil != err {
t.Fatalf("Failed to create url matcher")
panic(err)
}
if !matcher.Match(pack) {
t.Fatalf("Not match with headers")
}
}
func BenchmarkNewDefaultURLMatcher(b *testing.B) {
for i := 0; i < b.N; i++ {
NewDefaultURLMatcher("/gms/test/topic?version=2018")
}
}
func BenchmarkAnyMatcher_Match(b *testing.B) {
pack := NewDataFrame()
pack.setTopic("/gms/test/topic")
pack.SetHeader("version", "2018")
pack.SetDataFrameType("test.pack.type")
matcher, err := NewDefaultURLMatcher("/gms/test/topic?version=2018&pack.type=test.pack.type")
if nil != err {
b.Fatalf("Failed to create url matcher")
panic(err)
}
for i := 0; i < b.N; i++ {
if !matcher.Match(pack) {
b.Fatalf("Not match with headers")
}
}
}