@@ -19,39 +19,6 @@ import (
19
19
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/webhook/preflight"
20
20
)
21
21
22
- // mockV4Client is a mock implementation of the v4client interface for testing.
23
- type mockV4Client struct {
24
- getImageByIdFunc func (
25
- uuid * string ,
26
- ) (
27
- * vmmv4.GetImageApiResponse , error ,
28
- )
29
-
30
- listImagesFunc func (
31
- page ,
32
- limit * int ,
33
- filter ,
34
- orderby ,
35
- select_ * string ,
36
- args ... map [string ]interface {},
37
- ) (
38
- * vmmv4.ListImagesApiResponse ,
39
- error ,
40
- )
41
- }
42
-
43
- func (m * mockV4Client ) GetImageById (uuid * string ) (* vmmv4.GetImageApiResponse , error ) {
44
- return m .getImageByIdFunc (uuid )
45
- }
46
-
47
- func (m * mockV4Client ) ListImages (
48
- page , limit * int ,
49
- filter , orderby , select_ * string ,
50
- args ... map [string ]interface {},
51
- ) (* vmmv4.ListImagesApiResponse , error ) {
52
- return m .listImagesFunc (page , limit , filter , orderby , select_ )
53
- }
54
-
55
22
func TestVMImageCheck (t * testing.T ) {
56
23
testCases := []struct {
57
24
name string
@@ -61,7 +28,7 @@ func TestVMImageCheck(t *testing.T) {
61
28
}{
62
29
{
63
30
name : "imageLookup not yet supported" ,
64
- v4client : & mockV4Client {},
31
+ v4client : & mockv4client {},
65
32
machineDetails : & carenv1.NutanixMachineDetails {
66
33
ImageLookup : & capxv1.NutanixImageLookup {
67
34
Format : ptr .To ("test-format" ),
@@ -78,7 +45,7 @@ func TestVMImageCheck(t *testing.T) {
78
45
},
79
46
{
80
47
name : "image found by uuid" ,
81
- v4client : & mockV4Client {
48
+ v4client : & mockv4client {
82
49
getImageByIdFunc : func (uuid * string ) (* vmmv4.GetImageApiResponse , error ) {
83
50
assert .Equal (t , "test-uuid" , * uuid )
84
51
resp := & vmmv4.GetImageApiResponse {}
@@ -103,7 +70,7 @@ func TestVMImageCheck(t *testing.T) {
103
70
},
104
71
{
105
72
name : "image found by name" ,
106
- v4client : & mockV4Client {
73
+ v4client : & mockv4client {
107
74
listImagesFunc : func (page ,
108
75
limit * int ,
109
76
filter ,
@@ -137,7 +104,7 @@ func TestVMImageCheck(t *testing.T) {
137
104
},
138
105
{
139
106
name : "image not found by name" ,
140
- v4client : & mockV4Client {
107
+ v4client : & mockv4client {
141
108
listImagesFunc : func (page ,
142
109
limit * int ,
143
110
filter ,
@@ -170,7 +137,7 @@ func TestVMImageCheck(t *testing.T) {
170
137
},
171
138
{
172
139
name : "multiple images found by name" ,
173
- v4client : & mockV4Client {
140
+ v4client : & mockv4client {
174
141
listImagesFunc : func (page ,
175
142
limit * int ,
176
143
filter ,
@@ -213,7 +180,7 @@ func TestVMImageCheck(t *testing.T) {
213
180
},
214
181
{
215
182
name : "error getting image by id" ,
216
- v4client : & mockV4Client {
183
+ v4client : & mockv4client {
217
184
getImageByIdFunc : func (uuid * string ) (* vmmv4.GetImageApiResponse , error ) {
218
185
return nil , fmt .Errorf ("api error" )
219
186
},
@@ -238,7 +205,7 @@ func TestVMImageCheck(t *testing.T) {
238
205
},
239
206
{
240
207
name : "error listing images" ,
241
- v4client : & mockV4Client {
208
+ v4client : & mockv4client {
242
209
listImagesFunc : func (page ,
243
210
limit * int ,
244
211
filter ,
@@ -272,7 +239,7 @@ func TestVMImageCheck(t *testing.T) {
272
239
},
273
240
{
274
241
name : "neither image nor imageLookup specified" ,
275
- v4client : & mockV4Client {},
242
+ v4client : & mockv4client {},
276
243
machineDetails : & carenv1.NutanixMachineDetails {
277
244
// both Image and ImageLookup are nil
278
245
},
@@ -314,15 +281,15 @@ func TestVMImageCheck(t *testing.T) {
314
281
func TestGetVMImages (t * testing.T ) {
315
282
testCases := []struct {
316
283
name string
317
- client * mockV4Client
284
+ client * mockv4client
318
285
id * capxv1.NutanixResourceIdentifier
319
286
want []vmmv4.Image
320
287
wantErr bool
321
288
errorMsg string
322
289
}{
323
290
{
324
291
name : "get image by uuid success" ,
325
- client : & mockV4Client {
292
+ client : & mockv4client {
326
293
getImageByIdFunc : func (uuid * string ) (* vmmv4.GetImageApiResponse , error ) {
327
294
assert .Equal (t , "test-uuid" , * uuid )
328
295
resp := & vmmv4.GetImageApiResponse {}
@@ -348,7 +315,7 @@ func TestGetVMImages(t *testing.T) {
348
315
},
349
316
{
350
317
name : "get image by name success" ,
351
- client : & mockV4Client {
318
+ client : & mockv4client {
352
319
listImagesFunc : func (page ,
353
320
limit * int ,
354
321
filter ,
@@ -384,7 +351,7 @@ func TestGetVMImages(t *testing.T) {
384
351
},
385
352
{
386
353
name : "get image by uuid error" ,
387
- client : & mockV4Client {
354
+ client : & mockv4client {
388
355
getImageByIdFunc : func (uuid * string ) (* vmmv4.GetImageApiResponse , error ) {
389
356
return nil , fmt .Errorf ("api error" )
390
357
},
@@ -398,7 +365,7 @@ func TestGetVMImages(t *testing.T) {
398
365
},
399
366
{
400
367
name : "get image by name error" ,
401
- client : & mockV4Client {
368
+ client : & mockv4client {
402
369
listImagesFunc : func (page ,
403
370
limit * int ,
404
371
filter ,
@@ -421,7 +388,7 @@ func TestGetVMImages(t *testing.T) {
421
388
},
422
389
{
423
390
name : "neither name nor uuid specified" ,
424
- client : & mockV4Client {},
391
+ client : & mockv4client {},
425
392
id : & capxv1.NutanixResourceIdentifier {
426
393
// Both Name and UUID are not set
427
394
},
@@ -430,7 +397,7 @@ func TestGetVMImages(t *testing.T) {
430
397
},
431
398
{
432
399
name : "invalid data from GetImageById" ,
433
- client : & mockV4Client {
400
+ client : & mockv4client {
434
401
getImageByIdFunc : func (uuid * string ) (* vmmv4.GetImageApiResponse , error ) {
435
402
return & vmmv4.GetImageApiResponse {
436
403
Data : & vmmv4.OneOfGetImageApiResponseData {
@@ -448,7 +415,7 @@ func TestGetVMImages(t *testing.T) {
448
415
},
449
416
{
450
417
name : "empty response from ListImages" ,
451
- client : & mockV4Client {
418
+ client : & mockv4client {
452
419
listImagesFunc : func (page ,
453
420
limit * int ,
454
421
filter ,
0 commit comments