@@ -20,6 +20,7 @@ import (
20
20
"context"
21
21
"errors"
22
22
"math"
23
+ "slices"
23
24
"strconv"
24
25
"testing"
25
26
@@ -54,6 +55,8 @@ func TestValidateLinodeMachine(t *testing.T) {
54
55
Type : "example" ,
55
56
},
56
57
}
58
+ region = linodego.Region {ID : "test" }
59
+ capabilities = []string {linodego .CapabilityLinodeInterfaces }
57
60
disk = infrav1alpha2.InstanceDisk {Size : resource .MustParse ("1G" )}
58
61
disk_zero = infrav1alpha2.InstanceDisk {Size : * resource .NewQuantity (0 , resource .BinarySI )}
59
62
plan = linodego.LinodeType {Disk : 2 * int (disk .Size .ScaledValue (resource .Mega ))}
@@ -163,6 +166,72 @@ func TestValidateLinodeMachine(t *testing.T) {
163
166
}
164
167
}),
165
168
),
169
+ Path (
170
+ Call ("invalid linode interfaces with private IP" , func (ctx context.Context , mck Mock ) {
171
+ region := region
172
+ region .Capabilities = slices .Clone (capabilities )
173
+ mck .LinodeClient .EXPECT ().GetRegion (gomock .Any (), gomock .Any ()).Return (& region , nil ).AnyTimes ()
174
+ mck .LinodeClient .EXPECT ().GetType (gomock .Any (), gomock .Any ()).Return (& plan_max , nil ).AnyTimes ()
175
+ }),
176
+ Result ("error" , func (ctx context.Context , mck Mock ) {
177
+ machine := machine
178
+ machine .Spec .LinodeInterfaces = []infrav1alpha2.LinodeInterfaceCreateOptions {{}}
179
+ machine .Spec .PrivateIP = ptr .To (true )
180
+ errs := validator .validateLinodeMachineSpec (ctx , mck .LinodeClient , machine .Spec , SkipAPIValidation )
181
+ for _ , err := range errs {
182
+ assert .ErrorContains (t , err , "Linode Interfaces do not support private IPs" )
183
+ }
184
+ }),
185
+ ),
186
+ Path (
187
+ Call ("invalid linode interfaces with network helpers" , func (ctx context.Context , mck Mock ) {
188
+ region := region
189
+ region .Capabilities = slices .Clone (capabilities )
190
+ mck .LinodeClient .EXPECT ().GetRegion (gomock .Any (), gomock .Any ()).Return (& region , nil ).AnyTimes ()
191
+ mck .LinodeClient .EXPECT ().GetType (gomock .Any (), gomock .Any ()).Return (& plan_max , nil ).AnyTimes ()
192
+ }),
193
+ Result ("error" , func (ctx context.Context , mck Mock ) {
194
+ machine := machine
195
+ machine .Spec .LinodeInterfaces = []infrav1alpha2.LinodeInterfaceCreateOptions {{}}
196
+ machine .Spec .NetworkHelper = ptr .To (true )
197
+ errs := validator .validateLinodeMachineSpec (ctx , mck .LinodeClient , machine .Spec , SkipAPIValidation )
198
+ for _ , err := range errs {
199
+ assert .ErrorContains (t , err , "Linode Interfaces do not support configuring network helper" )
200
+ }
201
+ }),
202
+ ),
203
+ Path (
204
+ Call ("invalid linode interfaces with legacy interfaces" , func (ctx context.Context , mck Mock ) {
205
+ region := region
206
+ region .Capabilities = slices .Clone (capabilities )
207
+ mck .LinodeClient .EXPECT ().GetRegion (gomock .Any (), gomock .Any ()).Return (& region , nil ).AnyTimes ()
208
+ mck .LinodeClient .EXPECT ().GetType (gomock .Any (), gomock .Any ()).Return (& plan_max , nil ).AnyTimes ()
209
+ }),
210
+ Result ("error" , func (ctx context.Context , mck Mock ) {
211
+ machine := machine
212
+ machine .Spec .LinodeInterfaces = []infrav1alpha2.LinodeInterfaceCreateOptions {{}}
213
+ machine .Spec .Interfaces = []infrav1alpha2.InstanceConfigInterfaceCreateOptions {{}}
214
+ errs := validator .validateLinodeMachineSpec (ctx , mck .LinodeClient , machine .Spec , SkipAPIValidation )
215
+ for _ , err := range errs {
216
+ assert .ErrorContains (t , err , "Cannot specify both LinodeInterfaces and Interfaces" )
217
+ }
218
+ }),
219
+ ),
220
+ Path (
221
+ Call ("linode interfaces with invalid region" , func (ctx context.Context , mck Mock ) {
222
+ region := region
223
+ mck .LinodeClient .EXPECT ().GetRegion (gomock .Any (), gomock .Any ()).Return (& region , nil ).AnyTimes ()
224
+ mck .LinodeClient .EXPECT ().GetType (gomock .Any (), gomock .Any ()).Return (& plan_max , nil ).AnyTimes ()
225
+ }),
226
+ Result ("error" , func (ctx context.Context , mck Mock ) {
227
+ machine := machine
228
+ machine .Spec .LinodeInterfaces = []infrav1alpha2.LinodeInterfaceCreateOptions {{}}
229
+ errs := validator .validateLinodeMachineSpec (ctx , mck .LinodeClient , machine .Spec , SkipAPIValidation )
230
+ for _ , err := range errs {
231
+ assert .ErrorContains (t , err , "no capability: Linode Interfaces" )
232
+ }
233
+ }),
234
+ ),
166
235
),
167
236
)
168
237
}
0 commit comments