-
Notifications
You must be signed in to change notification settings - Fork 2
/
client_int_test.go
78 lines (67 loc) · 1.46 KB
/
client_int_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
//go:build integration
package pulsar
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewClient(t *testing.T) {
cases := map[string]struct {
serverURL string
expectedURL string
}{
"full": {
serverURL: "pulsar://example.com:12345",
expectedURL: "example.com:12345",
},
"host and port": {
serverURL: "example.com:12345",
expectedURL: "example.com:12345",
},
"host only": {
serverURL: "example.com",
expectedURL: "example.com:6650",
},
"port only": {
// valid because this will connect to the local host
serverURL: ":12345",
expectedURL: ":12345",
},
"empty": {
serverURL: "",
expectedURL: ":6650",
},
}
for name, c := range cases {
t.Run(name, func(t *testing.T) {
client, err := NewClient(c.serverURL)
require.NoError(t, err)
assert.Equal(t, c.expectedURL, client.host)
})
}
}
func TestClientTopics(t *testing.T) {
client := setup(t)
defer func() {
assert.NoError(t, client.Close())
}()
topic := randomTopicName()
prodConf := ProducerConfig{
Topic: topic,
Name: "test-producer",
}
ctx := context.Background()
_, err := client.NewProducer(ctx, prodConf)
require.NoError(t, err)
topics, err := client.Topics(DefaultNamespace)
require.NoError(t, err)
var found bool
for _, t := range topics {
if t.LocalName == topic {
found = true
break
}
}
assert.True(t, found, "topic not found in list")
}