@@ -10,6 +10,7 @@ import (
1010
1111 "github.com/go-logr/logr/testr"
1212 vmmv4 "github.com/nutanix/ntnx-api-golang-clients/vmm-go-client/v4/models/vmm/v4/content"
13+ vmmv4error "github.com/nutanix/ntnx-api-golang-clients/vmm-go-client/v4/models/vmm/v4/error"
1314 "github.com/stretchr/testify/assert"
1415 "github.com/stretchr/testify/require"
1516 "k8s.io/utils/ptr"
@@ -230,6 +231,42 @@ func TestVMImageCheck(t *testing.T) {
230231 },
231232 },
232233 },
234+ {
235+ name : "listing images returns an error response" ,
236+ nclient : & mocknclient {
237+ listImagesFunc : func (page ,
238+ limit * int ,
239+ filter ,
240+ orderby ,
241+ select_ * string ,
242+ args ... map [string ]interface {},
243+ ) (
244+ * vmmv4.ListImagesApiResponse ,
245+ error ,
246+ ) {
247+ resp := & vmmv4.ListImagesApiResponse {}
248+ err := resp .SetData (* vmmv4error .NewErrorResponse ())
249+ require .NoError (t , err )
250+ return resp , nil
251+ },
252+ },
253+ machineDetails : & carenv1.NutanixMachineDetails {
254+ Image : & capxv1.NutanixResourceIdentifier {
255+ Type : capxv1 .NutanixIdentifierName ,
256+ Name : ptr .To ("test-image" ),
257+ },
258+ },
259+ want : preflight.CheckResult {
260+ Allowed : false ,
261+ Error : true ,
262+ Causes : []preflight.Cause {
263+ {
264+ Message : "failed to get VM Image: api error" ,
265+ Field : "test-field" ,
266+ },
267+ },
268+ },
269+ },
233270 {
234271 name : "neither image nor imageLookup specified" ,
235272 nclient : & mocknclient {},
0 commit comments