-
Notifications
You must be signed in to change notification settings - Fork 41
/
kafka_test.go
49 lines (41 loc) · 1.15 KB
/
kafka_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
package kafka
import "testing"
var noopts = map[string]string{}
func Test_read_route_address(t *testing.T) {
address := "broker1:9092,broker2:9092"
brokers := readBrokers(address)
if len(brokers) != 2 {
t.Fatal("expected two broker addrs")
}
if brokers[0] != "broker1:9092" {
t.Errorf("broker1 addr should not be %s", brokers[0])
}
if brokers[1] != "broker2:9092" {
t.Errorf("broker2 addr should not be %s", brokers[1])
}
}
func Test_read_route_address_with_a_slash_topic(t *testing.T) {
address := "broker/hello"
brokers := readBrokers(address)
if len(brokers) != 1 {
t.Fatal("expected a broker addr")
}
topic := readTopic(address, noopts)
if topic != "hello" {
t.Errorf("topic should not be %s", topic)
}
}
func Test_read_topic_option(t *testing.T) {
opts := map[string]string{"topic": "hello"}
topic := readTopic("", opts)
if topic != "hello" {
t.Errorf("topic should not be %s", topic)
}
}
func Test_read_route_address_with_a_slash_topic_trumps_a_topic_option(t *testing.T) {
opts := map[string]string{"topic": "trumped"}
topic := readTopic("broker/hello", opts)
if topic != "hello" {
t.Errorf("topic should not be %s", topic)
}
}