-
Notifications
You must be signed in to change notification settings - Fork 18
/
client_group_test.go
74 lines (71 loc) · 2.17 KB
/
client_group_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
package healer
import (
"errors"
"fmt"
"testing"
"github.com/bytedance/mockey"
"github.com/smartystreets/goconvey/convey"
)
func TestListGroups(t *testing.T) {
brokers := &Brokers{}
c := &Client{
clientID: "test",
brokers: brokers,
}
mockey.PatchConvey("TestListGroupsNil", t, func() {
mockey.Mock((*Brokers).BrokersInfo).Return(nil).Build()
groups, err := c.ListGroups()
convey.So(err, convey.ShouldBeNil)
convey.So(groups, convey.ShouldBeEmpty)
})
mockey.PatchConvey("TestListGroupsEmpty", t, func() {
mockey.Mock((*Brokers).BrokersInfo).Return(map[int32]*BrokerInfo{}).Build()
groups, err := c.ListGroups()
convey.So(err, convey.ShouldBeNil)
convey.So(groups, convey.ShouldBeEmpty)
})
mockey.PatchConvey("TestListGroups", t, func() {
errMock := errors.New("mock error")
broker := BrokerInfo{}
mockey.Mock((*Brokers).BrokersInfo).Return(map[int32]*BrokerInfo{
1: &broker,
}).Build()
mockey.Mock((*Brokers).GetBroker).Return(nil, errMock).Build()
groups, err := c.ListGroups()
convey.So(err, convey.ShouldEqual, errMock)
convey.So(groups, convey.ShouldBeEmpty)
})
mockey.PatchConvey("TestListGroups", t, func() {
errMock := errors.New("mock error")
mockey.Mock((*Brokers).BrokersInfo).Return(map[int32]*BrokerInfo{
1: {},
}).Build()
mockey.Mock((*Brokers).GetBroker).Return(&Broker{}, nil).Build()
mockey.Mock((*Broker).RequestListGroups).Return(nil, errMock).Build()
groups, err := c.ListGroups()
convey.So(err, convey.ShouldEqual, errMock)
convey.So(groups, convey.ShouldBeEmpty)
})
mockey.PatchConvey("TestListGroups", t, func() {
brokerID := int32(1)
mockey.Mock((*Brokers).BrokersInfo).Return(map[int32]*BrokerInfo{
brokerID: {NodeID: brokerID},
}).Build()
mockey.Mock((*Brokers).GetBroker).Return(&Broker{nodeID: brokerID}, nil).Build()
mockey.Mock((*Broker).RequestListGroups).Return(&ListGroupsResponse{
Groups: []*Group{
{
GroupID: "test1",
},
{
GroupID: "test2",
},
},
}, nil).Build()
groups, err := c.ListGroups()
convey.So(err, convey.ShouldBeNil)
convey.So(len(groups), convey.ShouldEqual, 1)
fmt.Println(groups)
convey.So(len(groups[1]), convey.ShouldEqual, 2)
})
}