@@ -19,7 +19,7 @@ import (
19
19
"github.com/linode/cluster-api-provider-linode/mock"
20
20
)
21
21
22
- func TestCreateNodeBalancer (t * testing.T ) {
22
+ func TestEnsureNodeBalancer (t * testing.T ) {
23
23
t .Parallel ()
24
24
tests := []struct {
25
25
name string
@@ -50,8 +50,7 @@ func TestCreateNodeBalancer(t *testing.T) {
50
50
},
51
51
},
52
52
expects : func (mockClient * mock.MockLinodeClient ) {
53
- mockClient .EXPECT ().ListNodeBalancers (gomock .Any (), gomock .Any ()).Return ([]linodego.NodeBalancer {}, nil )
54
- mockClient .EXPECT ().CreateNodeBalancer (gomock .Any (), gomock .Any ()).Return (& linodego.NodeBalancer {
53
+ mockClient .EXPECT ().GetNodeBalancer (gomock .Any (), gomock .Any ()).Return (& linodego.NodeBalancer {
55
54
ID : 1234 ,
56
55
}, nil )
57
56
},
@@ -60,7 +59,7 @@ func TestCreateNodeBalancer(t *testing.T) {
60
59
},
61
60
},
62
61
{
63
- name : "Success - List NodeBalancers returns one nodebalancer and we return that" ,
62
+ name : "Success - Get NodeBalancers returns one nodebalancer and we return that" ,
64
63
clusterScope : & scope.ClusterScope {
65
64
LinodeCluster : & infrav1alpha2.LinodeCluster {
66
65
ObjectMeta : metav1.ObjectMeta {
@@ -75,12 +74,10 @@ func TestCreateNodeBalancer(t *testing.T) {
75
74
},
76
75
},
77
76
expects : func (mockClient * mock.MockLinodeClient ) {
78
- mockClient .EXPECT ().ListNodeBalancers (gomock .Any (), gomock .Any ()).Return ([]linodego.NodeBalancer {
79
- {
80
- ID : 1234 ,
81
- Label : ptr .To ("test" ),
82
- Tags : []string {"test-uid" },
83
- },
77
+ mockClient .EXPECT ().GetNodeBalancer (gomock .Any (), gomock .Any ()).Return (& linodego.NodeBalancer {
78
+ ID : 1234 ,
79
+ Label : ptr .To ("test" ),
80
+ Tags : []string {"test-uid" },
84
81
}, nil )
85
82
},
86
83
expectedNodeBalancer : & linodego.NodeBalancer {
@@ -90,38 +87,7 @@ func TestCreateNodeBalancer(t *testing.T) {
90
87
},
91
88
},
92
89
{
93
- name : "Error - List NodeBalancers returns one nodebalancer but there is a nodebalancer conflict" ,
94
- clusterScope : & scope.ClusterScope {
95
- LinodeCluster : & infrav1alpha2.LinodeCluster {
96
- ObjectMeta : metav1.ObjectMeta {
97
- Name : "test-cluster" ,
98
- UID : "test-uid" ,
99
- },
100
- Spec : infrav1alpha2.LinodeClusterSpec {
101
- Network : infrav1alpha2.NetworkSpec {
102
- NodeBalancerID : ptr .To (1234 ),
103
- },
104
- },
105
- },
106
- },
107
- expects : func (mockClient * mock.MockLinodeClient ) {
108
- mockClient .EXPECT ().ListNodeBalancers (gomock .Any (), gomock .Any ()).Return ([]linodego.NodeBalancer {
109
- {
110
- ID : 1234 ,
111
- Label : ptr .To ("test" ),
112
- Tags : []string {"test" },
113
- },
114
- }, nil )
115
- },
116
- expectedNodeBalancer : & linodego.NodeBalancer {
117
- ID : 1234 ,
118
- Label : ptr .To ("test" ),
119
- Tags : []string {"test" },
120
- },
121
- expectedError : fmt .Errorf ("NodeBalancer conflict" ),
122
- },
123
- {
124
- name : "Error - List NodeBalancers returns an error" ,
90
+ name : "Error - Get NodeBalancer returns an error" ,
125
91
clusterScope : & scope.ClusterScope {
126
92
LinodeCluster : & infrav1alpha2.LinodeCluster {
127
93
ObjectMeta : metav1.ObjectMeta {
@@ -136,9 +102,9 @@ func TestCreateNodeBalancer(t *testing.T) {
136
102
},
137
103
},
138
104
expects : func (mockClient * mock.MockLinodeClient ) {
139
- mockClient .EXPECT ().ListNodeBalancers (gomock .Any (), gomock .Any ()).Return (nil , fmt .Errorf ("Unable to list NodeBalancers " ))
105
+ mockClient .EXPECT ().GetNodeBalancer (gomock .Any (), gomock .Any ()).Return (nil , fmt .Errorf ("Unable to get NodeBalancer " ))
140
106
},
141
- expectedError : fmt .Errorf ("Unable to list NodeBalancers " ),
107
+ expectedError : fmt .Errorf ("Unable to get NodeBalancer " ),
142
108
},
143
109
{
144
110
name : "Error - Create NodeBalancer returns an error" ,
@@ -148,15 +114,10 @@ func TestCreateNodeBalancer(t *testing.T) {
148
114
Name : "test-cluster" ,
149
115
UID : "test-uid" ,
150
116
},
151
- Spec : infrav1alpha2.LinodeClusterSpec {
152
- Network : infrav1alpha2.NetworkSpec {
153
- NodeBalancerID : ptr .To (1234 ),
154
- },
155
- },
117
+ Spec : infrav1alpha2.LinodeClusterSpec {},
156
118
},
157
119
},
158
120
expects : func (mockClient * mock.MockLinodeClient ) {
159
- mockClient .EXPECT ().ListNodeBalancers (gomock .Any (), gomock .Any ()).Return ([]linodego.NodeBalancer {}, nil )
160
121
mockClient .EXPECT ().CreateNodeBalancer (gomock .Any (), gomock .Any ()).Return (nil , fmt .Errorf ("Unable to create NodeBalancer" ))
161
122
},
162
123
expectedError : fmt .Errorf ("Unable to create NodeBalancer" ),
@@ -176,7 +137,7 @@ func TestCreateNodeBalancer(t *testing.T) {
176
137
177
138
testcase .expects (MockLinodeClient )
178
139
179
- got , err := CreateNodeBalancer (context .Background (), testcase .clusterScope , logr .Discard ())
140
+ got , err := EnsureNodeBalancer (context .Background (), testcase .clusterScope , logr .Discard ())
180
141
if testcase .expectedError != nil {
181
142
assert .ErrorContains (t , err , testcase .expectedError .Error ())
182
143
} else {
@@ -187,7 +148,7 @@ func TestCreateNodeBalancer(t *testing.T) {
187
148
}
188
149
}
189
150
190
- func TestCreateNodeBalancerConfigs (t * testing.T ) {
151
+ func TestEnsureNodeBalancerConfigs (t * testing.T ) {
191
152
t .Parallel ()
192
153
193
154
tests := []struct {
@@ -232,6 +193,48 @@ func TestCreateNodeBalancerConfigs(t *testing.T) {
232
193
}, nil )
233
194
},
234
195
},
196
+ {
197
+ name : "Success - Get NodeBalancerConfig" ,
198
+ clusterScope : & scope.ClusterScope {
199
+ LinodeClient : nil ,
200
+ LinodeCluster : & infrav1alpha2.LinodeCluster {
201
+ ObjectMeta : metav1.ObjectMeta {
202
+ Name : "test-cluster" ,
203
+ UID : "test-uid" ,
204
+ },
205
+ Spec : infrav1alpha2.LinodeClusterSpec {
206
+ Network : infrav1alpha2.NetworkSpec {
207
+ NodeBalancerID : ptr .To (1234 ),
208
+ ApiserverNodeBalancerConfigID : ptr .To (2 ),
209
+ },
210
+ ControlPlaneEndpoint : clusterv1.APIEndpoint {
211
+ Host : "" ,
212
+ Port : 0 ,
213
+ },
214
+ },
215
+ },
216
+ },
217
+ expectedConfigs : []* linodego.NodeBalancerConfig {
218
+ {
219
+ Port : DefaultApiserverLBPort ,
220
+ Protocol : linodego .ProtocolTCP ,
221
+ Algorithm : linodego .AlgorithmRoundRobin ,
222
+ Check : linodego .CheckConnection ,
223
+ NodeBalancerID : 1234 ,
224
+ ID : 2 ,
225
+ },
226
+ },
227
+ expects : func (mockClient * mock.MockLinodeClient ) {
228
+ mockClient .EXPECT ().GetNodeBalancerConfig (gomock .Any (), gomock .Any (), gomock .Any ()).Return (& linodego.NodeBalancerConfig {
229
+ ID : 2 ,
230
+ Port : DefaultApiserverLBPort ,
231
+ Protocol : linodego .ProtocolTCP ,
232
+ Algorithm : linodego .AlgorithmRoundRobin ,
233
+ Check : linodego .CheckConnection ,
234
+ NodeBalancerID : 1234 ,
235
+ }, nil )
236
+ },
237
+ },
235
238
{
236
239
name : "Success - Create NodeBalancerConfig using assigned LB ports" ,
237
240
clusterScope : & scope.ClusterScope {
@@ -396,7 +399,7 @@ func TestCreateNodeBalancerConfigs(t *testing.T) {
396
399
397
400
testcase .expects (MockLinodeClient )
398
401
399
- got , err := CreateNodeBalancerConfigs (context .Background (), testcase .clusterScope , logr .Discard ())
402
+ got , err := EnsureNodeBalancerConfigs (context .Background (), testcase .clusterScope , logr .Discard ())
400
403
if testcase .expectedError != nil {
401
404
assert .ErrorContains (t , err , testcase .expectedError .Error ())
402
405
} else {
0 commit comments