@@ -54,8 +54,8 @@ func TestFirstAvailableNode(t *testing.T) {
5454 {
5555 name : "Returns client successfully" ,
5656 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
5959 },
6060 expectedClient : etcd.Client {Endpoint : "etcd-node-1" },
6161 },
@@ -68,20 +68,20 @@ func TestFirstAvailableNode(t *testing.T) {
6868 {
6969 name : "Returns error from client" ,
7070 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 ) {
7272 return nil , errors .New ("something went wrong" )
7373 },
7474 expectedErr : "could not establish a connection to any etcd node: something went wrong" ,
7575 },
7676 {
7777 name : "Returns client when some of the nodes are down but at least one node is up" ,
7878 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" ) {
8181 return nil , errors .New ("node down" )
8282 }
8383
84- return & etcd.Client {Endpoint : endpoints [ 0 ] }, nil
84+ return & etcd.Client {Endpoint : endpoint }, nil
8585 },
8686 expectedClient : etcd.Client {Endpoint : "etcd-node-up" },
8787 },
@@ -117,9 +117,9 @@ func TestForLeader(t *testing.T) {
117117 {
118118 name : "Returns client for leader successfully" ,
119119 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 ) {
121121 return & etcd.Client {
122- Endpoint : endpoints [ 0 ] ,
122+ Endpoint : endpoint ,
123123 LeaderID : 1729 ,
124124 EtcdClient : & etcdfake.FakeEtcdClient {
125125 MemberListResponse : & clientv3.MemberListResponse {
@@ -146,12 +146,12 @@ func TestForLeader(t *testing.T) {
146146 {
147147 name : "Returns client for leader even when one or more nodes are down" ,
148148 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" ) {
151151 return nil , errors .New ("node down" )
152152 }
153153 return & etcd.Client {
154- Endpoint : endpoints [ 0 ] ,
154+ Endpoint : endpoint ,
155155 LeaderID : 1729 ,
156156 EtcdClient : & etcdfake.FakeEtcdClient {
157157 MemberListResponse : & clientv3.MemberListResponse {
@@ -182,9 +182,9 @@ func TestForLeader(t *testing.T) {
182182 {
183183 name : "Returns error when the leader does not have a corresponding node" ,
184184 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 ) {
186186 return & etcd.Client {
187- Endpoint : endpoints [ 0 ] ,
187+ Endpoint : endpoint ,
188188 LeaderID : 1729 ,
189189 EtcdClient : & etcdfake.FakeEtcdClient {
190190 MemberListResponse : & clientv3.MemberListResponse {
@@ -201,7 +201,7 @@ func TestForLeader(t *testing.T) {
201201 {
202202 name : "Returns error when all nodes are down" ,
203203 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 ) {
205205 return nil , errors .New ("node down" )
206206 },
207207 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