-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtopicscope_internal_test.go
64 lines (53 loc) · 3.02 KB
/
topicscope_internal_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 logger
import (
"reflect"
"strings"
"testing"
"github.com/stretchr/testify/suite"
)
type TopicScopeSuite struct {
suite.Suite
Name string
}
func TestTopicScopeSuite(t *testing.T) {
suite.Run(t, new(TopicScopeSuite))
}
func (suite *TopicScopeSuite) SetupSuite() {
suite.Name = strings.TrimSuffix(reflect.TypeOf(suite).Elem().Name(), "Suite")
}
func (suite *TopicScopeSuite) TestCanCreate() {
ts := newTopicscope("topic", "scope")
suite.Assert().Equal("topic", ts.Topic, "Topic should be \"topic\"")
suite.Assert().Equal("scope", ts.Scope, "Scope should be \"scope\"")
}
func (suite *TopicScopeSuite) TestCanMatchTopicsAndScopes() {
ts := newTopicscope("", "")
suite.Assert().Equal("any", ts.Topic, `Topic should be "any"`)
suite.Assert().Equal("any", ts.Scope, `Scope should be "any"`)
suite.Assert().True(ts.Match("", ""), `Should match no topic and no scope`)
suite.Assert().True(ts.Match("any", "any"), `Should match topic "any" and scope "any"`)
suite.Assert().True(ts.Match("topic", "any"), `Should match topic "topic" and scope "any"`)
suite.Assert().True(ts.Match("any", "scope"), `Should match topic "any" and scope "scope"`)
suite.Assert().True(ts.Match("topic", "scope"), `Should match topic "topic" and scope "scope"`)
ts = newTopicscope("topic", "")
suite.Assert().False(ts.Match("", ""), `Should not match no topic and no scope`)
suite.Assert().False(ts.Match("any", "any"), `Should not match topic "any" and scope "any"`)
suite.Assert().True(ts.Match("topic", "any"), `Should match topic "topic" and scope "any"`)
suite.Assert().False(ts.Match("any", "scope"), `Should not match topic "any" and scope "scope"`)
suite.Assert().True(ts.Match("topic", "scope"), `Should match topic "topic" and scope "scope"`)
suite.Assert().False(ts.Match("topic1", "scope1"), `Should not match topic "topic1" and scope "scope1"`)
ts = newTopicscope("", "scope")
suite.Assert().False(ts.Match("", ""), `Should not match no topic and no scope`)
suite.Assert().False(ts.Match("any", "any"), `Should not match topic "any" and scope "any"`)
suite.Assert().False(ts.Match("topic", "any"), `Should not match topic "topic" and scope "any"`)
suite.Assert().True(ts.Match("any", "scope"), `Should match topic "any" and scope "scope"`)
suite.Assert().True(ts.Match("topic", "scope"), `Should match topic "topic" and scope "scope"`)
suite.Assert().False(ts.Match("topic1", "scope1"), `Should not match topic "topic1" and scope "scope1"`)
ts = newTopicscope("topic", "scope")
suite.Assert().False(ts.Match("", ""), `Should not match no topic and no scope`)
suite.Assert().False(ts.Match("any", "any"), `Should not match topic "any" and scope "any"`)
suite.Assert().False(ts.Match("topic", "any"), `Should not match topic "topic" and scope "any"`)
suite.Assert().False(ts.Match("any", "scope"), `Should not match topic "any" and scope "scope"`)
suite.Assert().True(ts.Match("topic", "scope"), `Should match topic "topic" and scope "scope"`)
suite.Assert().False(ts.Match("topic1", "scope1"), `Should not match topic "topic1" and scope "scope1"`)
}