@@ -54,8 +54,8 @@ func TestFirstAvailableNode(t *testing.T) {
54
54
{
55
55
name : "Returns client successfully" ,
56
56
nodes : []string {"node-1" },
57
- cc : func (ctx context.Context , endpoints [] string ) (* etcd.Client , error ) {
58
- return & etcd.Client {Endpoint : endpoints [ 0 ] }, nil
57
+ cc : func (ctx context.Context , endpoint string ) (* etcd.Client , error ) {
58
+ return & etcd.Client {Endpoint : endpoint }, nil
59
59
},
60
60
expectedClient : etcd.Client {Endpoint : "etcd-node-1" },
61
61
},
@@ -68,20 +68,20 @@ func TestFirstAvailableNode(t *testing.T) {
68
68
{
69
69
name : "Returns error from client" ,
70
70
nodes : []string {"node-1" , "node-2" },
71
- cc : func (ctx context.Context , endpoints [] string ) (* etcd.Client , error ) {
71
+ cc : func (ctx context.Context , endpoint string ) (* etcd.Client , error ) {
72
72
return nil , errors .New ("something went wrong" )
73
73
},
74
74
expectedErr : "could not establish a connection to any etcd node: something went wrong" ,
75
75
},
76
76
{
77
77
name : "Returns client when some of the nodes are down but at least one node is up" ,
78
78
nodes : []string {"node-down-1" , "node-down-2" , "node-up" },
79
- cc : func (ctx context.Context , endpoints [] string ) (* etcd.Client , error ) {
80
- if strings .Contains (endpoints [ 0 ] , "node-down" ) {
79
+ cc : func (ctx context.Context , endpoint string ) (* etcd.Client , error ) {
80
+ if strings .Contains (endpoint , "node-down" ) {
81
81
return nil , errors .New ("node down" )
82
82
}
83
83
84
- return & etcd.Client {Endpoint : endpoints [ 0 ] }, nil
84
+ return & etcd.Client {Endpoint : endpoint }, nil
85
85
},
86
86
expectedClient : etcd.Client {Endpoint : "etcd-node-up" },
87
87
},
@@ -117,9 +117,9 @@ func TestForLeader(t *testing.T) {
117
117
{
118
118
name : "Returns client for leader successfully" ,
119
119
nodes : []string {"node-1" , "node-leader" },
120
- cc : func (ctx context.Context , endpoints [] string ) (* etcd.Client , error ) {
120
+ cc : func (ctx context.Context , endpoint string ) (* etcd.Client , error ) {
121
121
return & etcd.Client {
122
- Endpoint : endpoints [ 0 ] ,
122
+ Endpoint : endpoint ,
123
123
LeaderID : 1729 ,
124
124
EtcdClient : & etcdfake.FakeEtcdClient {
125
125
MemberListResponse : & clientv3.MemberListResponse {
@@ -146,12 +146,12 @@ func TestForLeader(t *testing.T) {
146
146
{
147
147
name : "Returns client for leader even when one or more nodes are down" ,
148
148
nodes : []string {"node-down-1" , "node-down-2" , "node-leader" },
149
- cc : func (ctx context.Context , endpoints [] string ) (* etcd.Client , error ) {
150
- if strings .Contains (endpoints [ 0 ] , "node-down" ) {
149
+ cc : func (ctx context.Context , endpoint string ) (* etcd.Client , error ) {
150
+ if strings .Contains (endpoint , "node-down" ) {
151
151
return nil , errors .New ("node down" )
152
152
}
153
153
return & etcd.Client {
154
- Endpoint : endpoints [ 0 ] ,
154
+ Endpoint : endpoint ,
155
155
LeaderID : 1729 ,
156
156
EtcdClient : & etcdfake.FakeEtcdClient {
157
157
MemberListResponse : & clientv3.MemberListResponse {
@@ -182,9 +182,9 @@ func TestForLeader(t *testing.T) {
182
182
{
183
183
name : "Returns error when the leader does not have a corresponding node" ,
184
184
nodes : []string {"node-1" },
185
- cc : func (ctx context.Context , endpoints [] string ) (* etcd.Client , error ) {
185
+ cc : func (ctx context.Context , endpoint string ) (* etcd.Client , error ) {
186
186
return & etcd.Client {
187
- Endpoint : endpoints [ 0 ] ,
187
+ Endpoint : endpoint ,
188
188
LeaderID : 1729 ,
189
189
EtcdClient : & etcdfake.FakeEtcdClient {
190
190
MemberListResponse : & clientv3.MemberListResponse {
@@ -201,7 +201,7 @@ func TestForLeader(t *testing.T) {
201
201
{
202
202
name : "Returns error when all nodes are down" ,
203
203
nodes : []string {"node-down-1" , "node-down-2" , "node-down-3" },
204
- cc : func (ctx context.Context , endpoints [] string ) (* etcd.Client , error ) {
204
+ cc : func (ctx context.Context , endpoint string ) (* etcd.Client , error ) {
205
205
return nil , errors .New ("node down" )
206
206
},
207
207
expectedErr : "could not establish a connection to the etcd leader: [could not establish a connection to any etcd node: node down, failed to connect to etcd node]" ,
0 commit comments