Skip to content

Commit 84c8da5

Browse files
Fix tests
1 parent 429a1b5 commit 84c8da5

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

cloud/linode/cloud.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ type linodeCloud struct {
7070
}
7171

7272
var (
73-
instanceCache *instances
74-
ipHolderCharLimit int = 23
73+
instanceCache *instances
74+
ipHolderCharLimit int = 23
7575
NodeBalancerPrefixCharLimit int = 19
7676
)
7777

@@ -195,7 +195,7 @@ func newCloud() (cloudprovider.Interface, error) {
195195
return nil, fmt.Errorf("%s", msg)
196196
}
197197

198-
if len(Options.NodeBalancerPrefix) > NodeBalancerPrefixCharLimit {
198+
if len(Options.NodeBalancerPrefix) > NodeBalancerPrefixCharLimit {
199199
msg := fmt.Sprintf("nodebalancer-prefix must be %d characters or less: %s is %d characters\n", NodeBalancerPrefixCharLimit, Options.NodeBalancerPrefix, len(Options.NodeBalancerPrefix))
200200
klog.Error(msg)
201201
return nil, fmt.Errorf("%s", msg)

cloud/linode/cloud_test.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,32 @@ func TestNewCloud(t *testing.T) {
129129

130130
t.Run("should fail if nodebalancer-prefix is longer than 19 chars", func(t *testing.T) {
131131
prefix := Options.NodeBalancerPrefix
132+
rtEnabled := Options.EnableRouteController
133+
Options.EnableRouteController = false
134+
Options.LoadBalancerType = "nodebalancer"
135+
Options.VPCNames = "vpc-test1,vpc-test2"
136+
Options.NodeBalancerBackendIPv4SubnetName = "t1"
137+
vpcIDs = map[string]int{"vpc-test1": 1, "vpc-test2": 2, "vpc-test3": 3}
138+
subnetIDs = map[string]int{"t1": 1, "t2": 2, "t3": 3}
132139
Options.NodeBalancerPrefix = strings.Repeat("a", 21)
133140
defer func() {
134141
Options.NodeBalancerPrefix = prefix
142+
Options.LoadBalancerType = ""
143+
Options.EnableRouteController = rtEnabled
144+
Options.VPCNames = ""
145+
Options.NodeBalancerBackendIPv4SubnetID = 0
146+
Options.NodeBalancerBackendIPv4SubnetName = ""
147+
vpcIDs = map[string]int{}
148+
subnetIDs = map[string]int{}
135149
}()
136150
_, err := newCloud()
137-
assert.Error(t, err, "expected error if nodebalancer-prefix is longer than 19 chars")
151+
t.Log(err)
152+
if !assert.Error(t, err, "expected error if nodebalancer-prefix is longer than 19 chars") {
153+
t.Errorf("No error when nodebalancer-prefix is longer 19 than")
154+
}
155+
if !assert.ErrorContains(t, err, "nodebalancer-prefix") {
156+
t.Errorf("Error message does not concern nodebalancer-prefix: %s", err)
157+
}
138158
})
139159
}
140160

0 commit comments

Comments
 (0)