@@ -2,6 +2,7 @@ package unit
22
33import (
44 "context"
5+ "fmt"
56 "testing"
67
78 "github.com/linode/linodego"
@@ -66,23 +67,53 @@ func String(s string) *string {
6667}
6768
6869func TestNodeBalancer_Get (t * testing.T ) {
69- fixtureData , err := fixtures .GetFixture ("nodebalancer_get" )
70- assert .NoError (t , err )
70+ tests := []struct {
71+ name string
72+ nodeBalancerID int
73+ fixture string
74+ expectedLKECluster * linodego.NodeBalancerLKECluster
75+ }{
76+ {
77+ name : "basic get" ,
78+ nodeBalancerID : 123 ,
79+ fixture : "nodebalancer_get" ,
80+ expectedLKECluster : nil ,
81+ },
82+ {
83+ name : "get with lke_cluster" ,
84+ nodeBalancerID : 123 ,
85+ fixture : "nodebalancer_get_with_lke_cluster" ,
86+ expectedLKECluster : & linodego.NodeBalancerLKECluster {
87+ ID : 1234 ,
88+ Type : "lkecluster" ,
89+ Label : "test-cluster" ,
90+ URL : "/v4/lke/clusters/1234" ,
91+ },
92+ },
93+ }
7194
72- var base ClientBaseCase
73- base .SetUp (t )
74- defer base .TearDown (t )
95+ for _ , tt := range tests {
96+ t .Run (tt .name , func (t * testing.T ) {
97+ fixtureData , err := fixtures .GetFixture (tt .fixture )
98+ assert .NoError (t , err )
7599
76- // Mock the GET request with the fixture response
77- base .MockGet ("nodebalancers/123" , fixtureData )
100+ var base ClientBaseCase
101+ base .SetUp (t )
102+ defer base .TearDown (t )
78103
79- nodebalancer , err := base . Client . GetNodeBalancer ( context . Background (), 123 )
80- assert . NoError ( t , err )
104+ // Mock the GET request with the fixture response
105+ base . MockGet ( fmt . Sprintf ( "nodebalancers/%d" , tt . nodeBalancerID ), fixtureData )
81106
82- assert .Equal (t , 123 , nodebalancer .ID , "Expected NodeBalancer ID to match" )
83- assert .Equal (t , "Existing NodeBalancer" , * nodebalancer .Label , "Expected NodeBalancer label to match" )
84- assert .Equal (t , "us-west" , nodebalancer .Region , "Expected NodeBalancer region to match" )
85- assert .Equal (t , []linodego.LockType {linodego .LockTypeCannotDeleteWithSubresources }, nodebalancer .Locks , "Expected NodeBalancer locks to match" )
107+ nodebalancer , err := base .Client .GetNodeBalancer (context .Background (), tt .nodeBalancerID )
108+ assert .NoError (t , err )
109+
110+ assert .Equal (t , tt .nodeBalancerID , nodebalancer .ID , "Expected NodeBalancer ID to match" )
111+ assert .Equal (t , "Existing NodeBalancer" , * nodebalancer .Label , "Expected NodeBalancer label to match" )
112+ assert .Equal (t , "us-west" , nodebalancer .Region , "Expected NodeBalancer region to match" )
113+ assert .Equal (t , []linodego.LockType {linodego .LockTypeCannotDeleteWithSubresources }, nodebalancer .Locks , "Expected NodeBalancer locks to match" )
114+ assert .Equal (t , tt .expectedLKECluster , nodebalancer .LKECluster , "Expected NodeBalancer LKECluster to match" )
115+ })
116+ }
86117}
87118
88119func TestNodeBalancer_List (t * testing.T ) {
@@ -107,13 +138,20 @@ func TestNodeBalancer_List(t *testing.T) {
107138 assert .Equal (t , "us-east" , nodebalancers [0 ].Region , "Expected first NodeBalancer region to match" )
108139 assert .Equal (t , []string {"tag1" , "tag2" }, nodebalancers [0 ].Tags , "Expected first NodeBalancer tags to match" )
109140 assert .Equal (t , []linodego.LockType {linodego .LockTypeCannotDelete }, nodebalancers [0 ].Locks , "Expected first NodeBalancer locks to match" )
141+ assert .Nil (t , nodebalancers [0 ].LKECluster , "Expected first NodeBalancer LKECluster to match" )
110142
111143 // Verify details of the second NodeBalancer
112144 assert .Equal (t , 456 , nodebalancers [1 ].ID , "Expected second NodeBalancer ID to match" )
113145 assert .Equal (t , "NodeBalancer B" , * nodebalancers [1 ].Label , "Expected second NodeBalancer label to match" )
114146 assert .Equal (t , "us-west" , nodebalancers [1 ].Region , "Expected second NodeBalancer region to match" )
115147 assert .Equal (t , []string {"tag3" }, nodebalancers [1 ].Tags , "Expected second NodeBalancer tags to match" )
116148 assert .Empty (t , nodebalancers [1 ].Locks , "Expected second NodeBalancer to have no locks" )
149+ assert .Equal (t , & linodego.NodeBalancerLKECluster {
150+ ID : 1234 ,
151+ Type : "lkecluster" ,
152+ Label : "test-cluster" ,
153+ URL : "/v4/lke/clusters/1234" ,
154+ }, nodebalancers [1 ].LKECluster , "Expected second NodeBalancer LKECluster to match" )
117155}
118156
119157func TestNodeBalancer_Update (t * testing.T ) {
0 commit comments