-
Notifications
You must be signed in to change notification settings - Fork 2
/
topic_test.go
59 lines (53 loc) · 1.14 KB
/
topic_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
package pulsar
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewTopic(t *testing.T) {
tests := []struct {
name string
error string
completeName string
}{
{
name: "topic-1",
completeName: "persistent://public/default/topic-1",
},
{
name: "property/namespace/topic-1",
completeName: "persistent://property/namespace/topic-1",
},
{
name: "namespace/topic-1",
error: "invalid topic short name format",
},
{
name: "://tenant://namespace",
error: "invalid topic domain format",
},
{
name: "://tenant/namespace",
error: "invalid topic domain",
},
{
name: "persistent://property/namespace/topic/1",
error: "invalid topic name format",
},
}
for _, test := range tests {
topic, err := NewTopic(test.name)
if err == nil {
if test.error != "" {
t.Errorf("%v: unexpected error '%v'", test.name, err)
}
} else {
if test.error != err.Error() {
t.Errorf("%v: expected error '%v' but got '%v'", test.name, test.error, err)
}
}
if topic == nil {
continue
}
assert.Equal(t, test.completeName, topic.CompleteName)
}
}