@@ -157,6 +157,194 @@ func TestNodeBalancer_Rebuild(t *testing.T) {
157157 }
158158}
159159
160+ func TestNodeBalancerNode_Create_InVPC (t * testing.T ) {
161+ client , nodebalancer , subnet , instanceVPCIP , teardown , err := setupNodeBalancerWithVPCAndInstance (t , "fixtures/TestNodeBalancerNode_Create_InVPC" )
162+ defer teardown ()
163+ if err != nil {
164+ t .Error (err )
165+ }
166+
167+ config , err := client .CreateNodeBalancerConfig (context .Background (), nodebalancer .ID , TestNodeBalancerConfigCreateOpts )
168+ if err != nil {
169+ t .Errorf ("Error creating NodeBalancer Config, got error %v" , err )
170+ }
171+
172+ // Create a nodebalancer node in the VPC
173+ node , err := client .CreateNodeBalancerNode (context .Background (), nodebalancer .ID , config .ID , linodego.NodeBalancerNodeCreateOptions {
174+ Address : instanceVPCIP + ":" + testNodePort ,
175+ Mode : linodego .ModeAccept ,
176+ Weight : 10 ,
177+ Label : "go-node-test-def" ,
178+ SubnetID : subnet .ID ,
179+ })
180+ if err != nil {
181+ t .Fatalf ("Error creating NodeBalancer Node, got error %v" , err )
182+ }
183+
184+ // get nodebalancer vpc config - cross check the nodebalancer node VPC config ID
185+ vpcConfigs , err := client .ListNodeBalancerVPCConfigs (context .Background (), nodebalancer .ID , nil )
186+ if err != nil {
187+ t .Errorf ("Error listing nodebalancer VPC configs: %s" , err )
188+ }
189+ if len (vpcConfigs ) != 1 {
190+ t .Errorf ("Expected exactly one nodebalancer VPC config, got %d" , len (vpcConfigs ))
191+ }
192+ if vpcConfigs [0 ].ID != node .VPCConfigID {
193+ t .Errorf ("Expected nodebalancer VPC config ID to be the same as the nodebalancer node VPC config ID, got %d" , vpcConfigs [0 ].ID )
194+ }
195+ }
196+
197+ func TestNodeBalancerNode_List_InVPC (t * testing.T ) {
198+ client , nodebalancer , subnet , instanceVPCIP , teardown , err := setupNodeBalancerWithVPCAndInstance (t , "fixtures/TestNodeBalancerNode_List_InVPC" )
199+ defer teardown ()
200+ if err != nil {
201+ t .Error (err )
202+ }
203+
204+ config , err := client .CreateNodeBalancerConfig (context .Background (), nodebalancer .ID , TestNodeBalancerConfigCreateOpts )
205+ if err != nil {
206+ t .Errorf ("Error creating NodeBalancer Config, got error %v" , err )
207+ }
208+
209+ node , err := client .CreateNodeBalancerNode (context .Background (), nodebalancer .ID , config .ID , linodego.NodeBalancerNodeCreateOptions {
210+ Address : instanceVPCIP + ":" + testNodePort ,
211+ Mode : linodego .ModeAccept ,
212+ Weight : 10 ,
213+ Label : "go-node-test-def" ,
214+ SubnetID : subnet .ID ,
215+ })
216+ if err != nil {
217+ t .Errorf ("Error creating NodeBalancer Node, got error %v" , err )
218+ }
219+
220+ // Test listing nodebalancer nodes method
221+ nodes , err := client .ListNodeBalancerNodes (context .Background (), nodebalancer .ID , config .ID , nil )
222+ if err != nil {
223+ t .Fatalf ("Error listing nodebalancer nodes: %s" , err )
224+ }
225+ if len (nodes ) != 1 {
226+ t .Errorf ("Expected exactly one nodebalancer node, got %d" , len (nodes ))
227+ }
228+ if nodes [0 ].Address != instanceVPCIP + ":" + testNodePort {
229+ t .Errorf ("Expected nodebalancer node address to be the same as the instance VPC IP, got %s" , nodes [0 ].Address )
230+ }
231+ if nodes [0 ].ID != node .ID {
232+ t .Errorf ("Expected nodebalancer node ID to be the same as the nodebalancer node ID, got %d" , nodes [0 ].ID )
233+ }
234+ if nodes [0 ].VPCConfigID != node .VPCConfigID {
235+ t .Errorf ("Expected nodebalancer node VPC config ID to be the same as the nodebalancer node VPC config ID, got %d" , nodes [0 ].VPCConfigID )
236+ }
237+
238+ vpcConfigs , err := client .ListNodeBalancerVPCConfigs (context .Background (), nodebalancer .ID , nil )
239+ if err != nil {
240+ t .Errorf ("Error listing nodebalancer VPC configs: %s" , err )
241+ }
242+ if len (vpcConfigs ) != 1 {
243+ t .Errorf ("Expected exactly one nodebalancer VPC config, got %d" , len (vpcConfigs ))
244+ }
245+ if vpcConfigs [0 ].ID != nodes [0 ].VPCConfigID {
246+ t .Errorf ("Expected nodebalancer VPC config ID to be the same as the nodebalancer node VPC config ID, got %d" , vpcConfigs [0 ].ID )
247+ }
248+ }
249+
250+ func TestNodeBalancerNode_Update_InVPC (t * testing.T ) {
251+ client , nodebalancer , subnet , instanceVPCIP , teardown , err := setupNodeBalancerWithVPCAndInstance (t , "fixtures/TestNodeBalancerNode_Update_InVPC" )
252+ defer teardown ()
253+ if err != nil {
254+ t .Error (err )
255+ }
256+
257+ config , err := client .CreateNodeBalancerConfig (context .Background (), nodebalancer .ID , TestNodeBalancerConfigCreateOpts )
258+ if err != nil {
259+ t .Errorf ("Error creating NodeBalancer Config, got error %v" , err )
260+ }
261+
262+ node , err := client .CreateNodeBalancerNode (context .Background (), nodebalancer .ID , config .ID , linodego.NodeBalancerNodeCreateOptions {
263+ Address : instanceVPCIP + ":" + testNodePort ,
264+ Mode : linodego .ModeAccept ,
265+ Weight : 10 ,
266+ Label : "not-updated" ,
267+ SubnetID : subnet .ID ,
268+ })
269+ if err != nil {
270+ t .Errorf ("Error creating NodeBalancer Node, got error %v" , err )
271+ }
272+
273+ updateOpts := linodego.NodeBalancerNodeUpdateOptions {
274+ Address : instanceVPCIP + ":" + testNodePort ,
275+ Label : "updated" ,
276+ SubnetID : subnet .ID ,
277+ }
278+
279+ node , err = client .UpdateNodeBalancerNode (context .Background (), nodebalancer .ID , config .ID , node .ID , updateOpts )
280+ if err != nil {
281+ t .Fatalf ("Error updating NodeBalancer Node, got error %v" , err )
282+ }
283+ if node .Label != "updated" {
284+ t .Errorf ("Expected nodebalancer node label to be updated, got %s" , node .Label )
285+ }
286+
287+ vpcConfigs , err := client .ListNodeBalancerVPCConfigs (context .Background (), nodebalancer .ID , nil )
288+ if err != nil {
289+ t .Errorf ("Error listing nodebalancer VPC configs: %s" , err )
290+ }
291+ if len (vpcConfigs ) != 1 {
292+ t .Errorf ("Expected exactly one nodebalancer VPC config, got %d" , len (vpcConfigs ))
293+ }
294+ if vpcConfigs [0 ].ID != node .VPCConfigID {
295+ t .Errorf ("Expected nodebalancer VPC config ID to be the same as the nodebalancer node VPC config ID, got %d" , vpcConfigs [0 ].ID )
296+ }
297+ }
298+
299+ func TestNodeBalancerNode_Get_InVPC (t * testing.T ) {
300+ client , nodebalancer , subnet , instanceVPCIP , teardown , err := setupNodeBalancerWithVPCAndInstance (t , "fixtures/TestNodeBalancerNode_Get_InVPC" )
301+ defer teardown ()
302+ if err != nil {
303+ t .Error (err )
304+ }
305+
306+ config , err := client .CreateNodeBalancerConfig (context .Background (), nodebalancer .ID , TestNodeBalancerConfigCreateOpts )
307+ if err != nil {
308+ t .Errorf ("Error creating NodeBalancer Config, got error %v" , err )
309+ }
310+
311+ node , err := client .CreateNodeBalancerNode (context .Background (), nodebalancer .ID , config .ID , linodego.NodeBalancerNodeCreateOptions {
312+ Address : instanceVPCIP + ":" + testNodePort ,
313+ Mode : linodego .ModeAccept ,
314+ Weight : 10 ,
315+ Label : "go-node-test-def" ,
316+ SubnetID : subnet .ID ,
317+ })
318+ if err != nil {
319+ t .Errorf ("Error creating NodeBalancer Node, got error %v" , err )
320+ }
321+
322+ nodeGot , err := client .GetNodeBalancerNode (context .Background (), nodebalancer .ID , config .ID , node .ID )
323+ if err != nil {
324+ t .Fatalf ("Error getting NodeBalancer Node, got error %v" , err )
325+ }
326+ if nodeGot .ID != node .ID {
327+ t .Errorf ("Expected nodebalancer node ID to be the same as the nodebalancer node ID, got %d" , nodeGot .ID )
328+ }
329+ if nodeGot .Address != node .Address {
330+ t .Errorf ("Expected nodebalancer node address to be the same as the nodebalancer node address, got %s" , nodeGot .Address )
331+ }
332+ if nodeGot .VPCConfigID != node .VPCConfigID {
333+ t .Errorf ("Expected nodebalancer node VPC config ID to be the same as the nodebalancer node VPC config ID, got %d" , nodeGot .VPCConfigID )
334+ }
335+
336+ vpcConfigs , err := client .ListNodeBalancerVPCConfigs (context .Background (), nodebalancer .ID , nil )
337+ if err != nil {
338+ t .Errorf ("Error listing nodebalancer VPC configs: %s" , err )
339+ }
340+ if len (vpcConfigs ) != 1 {
341+ t .Errorf ("Expected exactly one nodebalancer VPC config, got %d" , len (vpcConfigs ))
342+ }
343+ if vpcConfigs [0 ].ID != nodeGot .VPCConfigID {
344+ t .Errorf ("Expected nodebalancer VPC config ID to be the same as the nodebalancer node VPC config ID, got %d" , vpcConfigs [0 ].ID )
345+ }
346+ }
347+
160348func setupNodeBalancerNode (t * testing.T , fixturesYaml string ) (* linodego.Client , * linodego.NodeBalancer , * linodego.NodeBalancerConfig , * linodego.NodeBalancerNode , func (), error ) {
161349 t .Helper ()
162350 var fixtureTeardown func ()
0 commit comments