-
Notifications
You must be signed in to change notification settings - Fork 18
/
config_test.go
57 lines (49 loc) · 2.05 KB
/
config_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
package healer
import (
"testing"
"github.com/bytedance/mockey"
"github.com/smartystreets/goconvey/convey"
)
func TestCreateConsumerConfig(t *testing.T) {
mockey.PatchConvey("TestNil", t, func() {
concumerConfig, err := createConsumerConfig(nil)
convey.So(err, convey.ShouldBeNil)
convey.So(concumerConfig, convey.ShouldResemble, defaultConsumerConfig)
convey.So(defaultConsumerConfig.BootstrapServers, convey.ShouldEqual, "")
})
mockey.PatchConvey("TestMap", t, func() {
configMap := map[string]interface{}{
"bootstrap.servers": "localhost:9092",
"group.id": "test",
"mechanism": "plain",
"sasl": map[string]interface{}{
"mechanism": "plain",
},
}
concumerConfig, err := createConsumerConfig(configMap)
convey.So(err, convey.ShouldBeNil)
convey.So(concumerConfig.BootstrapServers, convey.ShouldEqual, "localhost:9092")
convey.So(concumerConfig.GroupID, convey.ShouldEqual, "test")
convey.So(concumerConfig.RetryBackOffMS, convey.ShouldEqual, 100)
convey.So(concumerConfig.Sasl.Mechanism, convey.ShouldEqual, "plain")
convey.So(defaultConsumerConfig.BootstrapServers, convey.ShouldEqual, "")
})
mockey.PatchConvey("TestStruct", t, func() {
configMap := ConsumerConfig{
BootstrapServers: "localhost:9092",
}
concumerConfig, err := createConsumerConfig(configMap)
convey.So(err, convey.ShouldBeNil)
convey.So(concumerConfig.BootstrapServers, convey.ShouldEqual, "localhost:9092")
convey.So(concumerConfig.GroupID, convey.ShouldEqual, "")
convey.So(concumerConfig.RetryBackOffMS, convey.ShouldEqual, 0)
convey.So(defaultConsumerConfig.BootstrapServers, convey.ShouldEqual, "")
})
mockey.PatchConvey("TestTypeDefault", t, func() {
configMap := make(map[string]string)
concumerConfig, err := createConsumerConfig(configMap)
convey.So(err.Error(), convey.ShouldEqual, "consumer only accept config from map[string]interface{} or ConsumerConfig")
convey.So(concumerConfig.BootstrapServers, convey.ShouldEqual, "")
convey.So(defaultConsumerConfig.BootstrapServers, convey.ShouldEqual, "")
})
}