@@ -19,39 +19,6 @@ import (
1919 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/webhook/preflight"
2020)
2121
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-
5522func TestVMImageCheck (t * testing.T ) {
5623 testCases := []struct {
5724 name string
@@ -61,7 +28,7 @@ func TestVMImageCheck(t *testing.T) {
6128 }{
6229 {
6330 name : "imageLookup not yet supported" ,
64- v4client : & mockV4Client {},
31+ v4client : & mockv4client {},
6532 machineDetails : & carenv1.NutanixMachineDetails {
6633 ImageLookup : & capxv1.NutanixImageLookup {
6734 Format : ptr .To ("test-format" ),
@@ -78,7 +45,7 @@ func TestVMImageCheck(t *testing.T) {
7845 },
7946 {
8047 name : "image found by uuid" ,
81- v4client : & mockV4Client {
48+ v4client : & mockv4client {
8249 getImageByIdFunc : func (uuid * string ) (* vmmv4.GetImageApiResponse , error ) {
8350 assert .Equal (t , "test-uuid" , * uuid )
8451 resp := & vmmv4.GetImageApiResponse {}
@@ -103,7 +70,7 @@ func TestVMImageCheck(t *testing.T) {
10370 },
10471 {
10572 name : "image found by name" ,
106- v4client : & mockV4Client {
73+ v4client : & mockv4client {
10774 listImagesFunc : func (page ,
10875 limit * int ,
10976 filter ,
@@ -137,7 +104,7 @@ func TestVMImageCheck(t *testing.T) {
137104 },
138105 {
139106 name : "image not found by name" ,
140- v4client : & mockV4Client {
107+ v4client : & mockv4client {
141108 listImagesFunc : func (page ,
142109 limit * int ,
143110 filter ,
@@ -170,7 +137,7 @@ func TestVMImageCheck(t *testing.T) {
170137 },
171138 {
172139 name : "multiple images found by name" ,
173- v4client : & mockV4Client {
140+ v4client : & mockv4client {
174141 listImagesFunc : func (page ,
175142 limit * int ,
176143 filter ,
@@ -213,7 +180,7 @@ func TestVMImageCheck(t *testing.T) {
213180 },
214181 {
215182 name : "error getting image by id" ,
216- v4client : & mockV4Client {
183+ v4client : & mockv4client {
217184 getImageByIdFunc : func (uuid * string ) (* vmmv4.GetImageApiResponse , error ) {
218185 return nil , fmt .Errorf ("api error" )
219186 },
@@ -238,7 +205,7 @@ func TestVMImageCheck(t *testing.T) {
238205 },
239206 {
240207 name : "error listing images" ,
241- v4client : & mockV4Client {
208+ v4client : & mockv4client {
242209 listImagesFunc : func (page ,
243210 limit * int ,
244211 filter ,
@@ -272,7 +239,7 @@ func TestVMImageCheck(t *testing.T) {
272239 },
273240 {
274241 name : "neither image nor imageLookup specified" ,
275- v4client : & mockV4Client {},
242+ v4client : & mockv4client {},
276243 machineDetails : & carenv1.NutanixMachineDetails {
277244 // both Image and ImageLookup are nil
278245 },
@@ -314,15 +281,15 @@ func TestVMImageCheck(t *testing.T) {
314281func TestGetVMImages (t * testing.T ) {
315282 testCases := []struct {
316283 name string
317- client * mockV4Client
284+ client * mockv4client
318285 id * capxv1.NutanixResourceIdentifier
319286 want []vmmv4.Image
320287 wantErr bool
321288 errorMsg string
322289 }{
323290 {
324291 name : "get image by uuid success" ,
325- client : & mockV4Client {
292+ client : & mockv4client {
326293 getImageByIdFunc : func (uuid * string ) (* vmmv4.GetImageApiResponse , error ) {
327294 assert .Equal (t , "test-uuid" , * uuid )
328295 resp := & vmmv4.GetImageApiResponse {}
@@ -348,7 +315,7 @@ func TestGetVMImages(t *testing.T) {
348315 },
349316 {
350317 name : "get image by name success" ,
351- client : & mockV4Client {
318+ client : & mockv4client {
352319 listImagesFunc : func (page ,
353320 limit * int ,
354321 filter ,
@@ -384,7 +351,7 @@ func TestGetVMImages(t *testing.T) {
384351 },
385352 {
386353 name : "get image by uuid error" ,
387- client : & mockV4Client {
354+ client : & mockv4client {
388355 getImageByIdFunc : func (uuid * string ) (* vmmv4.GetImageApiResponse , error ) {
389356 return nil , fmt .Errorf ("api error" )
390357 },
@@ -398,7 +365,7 @@ func TestGetVMImages(t *testing.T) {
398365 },
399366 {
400367 name : "get image by name error" ,
401- client : & mockV4Client {
368+ client : & mockv4client {
402369 listImagesFunc : func (page ,
403370 limit * int ,
404371 filter ,
@@ -421,7 +388,7 @@ func TestGetVMImages(t *testing.T) {
421388 },
422389 {
423390 name : "neither name nor uuid specified" ,
424- client : & mockV4Client {},
391+ client : & mockv4client {},
425392 id : & capxv1.NutanixResourceIdentifier {
426393 // Both Name and UUID are not set
427394 },
@@ -430,7 +397,7 @@ func TestGetVMImages(t *testing.T) {
430397 },
431398 {
432399 name : "invalid data from GetImageById" ,
433- client : & mockV4Client {
400+ client : & mockv4client {
434401 getImageByIdFunc : func (uuid * string ) (* vmmv4.GetImageApiResponse , error ) {
435402 return & vmmv4.GetImageApiResponse {
436403 Data : & vmmv4.OneOfGetImageApiResponseData {
@@ -448,7 +415,7 @@ func TestGetVMImages(t *testing.T) {
448415 },
449416 {
450417 name : "empty response from ListImages" ,
451- client : & mockV4Client {
418+ client : & mockv4client {
452419 listImagesFunc : func (page ,
453420 limit * int ,
454421 filter ,
0 commit comments