@@ -22,20 +22,20 @@ type testCtxKey struct{}
2222var testCtx = context .WithValue (context .Background (), testCtxKey {}, "foo" )
2323var testClient = & mariadb.APIClient {DefaultAPI : & mariadb.DefaultAPIService {}}
2424
25- type mariaDBClientMocked struct {
25+ type mockSettings struct {
2626 returnError bool
2727 listOfferingsResp * mariadb.ListOfferingsResponse
2828}
2929
30- func (c * mariaDBClientMocked ) PartialUpdateInstance (ctx context.Context , projectId , instanceId string ) mariadb.ApiPartialUpdateInstanceRequest {
31- return testClient .PartialUpdateInstance (ctx , projectId , instanceId )
32- }
33-
34- func (c * mariaDBClientMocked ) ListOfferingsExecute (_ context.Context , _ string ) (* mariadb.ListOfferingsResponse , error ) {
35- if c .returnError {
36- return nil , fmt .Errorf ("list flavors failed" )
30+ func newAPIMock (s mockSettings ) mariadb.DefaultAPI {
31+ return & mariadb.DefaultAPIServiceMock {
32+ ListOfferingsExecuteMock : utils .Ptr (func (_ mariadb.ApiListOfferingsRequest ) (* mariadb.ListOfferingsResponse , error ) {
33+ if s .returnError {
34+ return nil , fmt .Errorf ("list flavors failed" )
35+ }
36+ return s .listOfferingsResp , nil
37+ }),
3738 }
38- return c .listOfferingsResp , nil
3939}
4040
4141var (
@@ -82,7 +82,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
8282 InstanceId : testInstanceId ,
8383 EnableMonitoring : utils .Ptr (true ),
8484 Graphite : utils .Ptr ("example-graphite" ),
85- MetricsFrequency : utils .Ptr (int64 (100 )),
85+ MetricsFrequency : utils .Ptr (int32 (100 )),
8686 MetricsPrefix : utils .Ptr ("example-prefix" ),
8787 MonitoringInstanceId : utils .Ptr (testMonitoringInstanceId ),
8888 SgwAcl : utils .Ptr ([]string {"198.51.100.14/24" }),
@@ -96,16 +96,16 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
9696}
9797
9898func fixtureRequest (mods ... func (request * mariadb.ApiPartialUpdateInstanceRequest )) mariadb.ApiPartialUpdateInstanceRequest {
99- request := testClient .PartialUpdateInstance (testCtx , testProjectId , testInstanceId )
99+ request := testClient .DefaultAPI . PartialUpdateInstance (testCtx , testProjectId , testInstanceId )
100100 request = request .PartialUpdateInstancePayload (mariadb.PartialUpdateInstancePayload {
101101 Parameters : & mariadb.InstanceParameters {
102102 EnableMonitoring : utils .Ptr (true ),
103103 Graphite : utils .Ptr ("example-graphite" ),
104- MetricsFrequency : utils .Ptr (int64 (100 )),
104+ MetricsFrequency : utils .Ptr (int32 (100 )),
105105 MetricsPrefix : utils .Ptr ("example-prefix" ),
106106 MonitoringInstanceId : utils .Ptr (testMonitoringInstanceId ),
107107 SgwAcl : utils .Ptr ("198.51.100.14/24" ),
108- Syslog : utils . Ptr ( []string {"example-syslog" }) ,
108+ Syslog : []string {"example-syslog" },
109109 },
110110 PlanId : utils .Ptr (testPlanId ),
111111 })
@@ -186,7 +186,7 @@ func TestParseInput(t *testing.T) {
186186 PlanId : utils .Ptr (testPlanId ),
187187 EnableMonitoring : utils .Ptr (false ),
188188 Graphite : utils .Ptr ("" ),
189- MetricsFrequency : utils .Ptr (int64 (0 )),
189+ MetricsFrequency : utils .Ptr (int32 (0 )),
190190 MetricsPrefix : utils .Ptr ("" ),
191191 },
192192 },
@@ -363,13 +363,13 @@ func TestBuildRequest(t *testing.T) {
363363 model : fixtureInputModel (),
364364 expectedRequest : fixtureRequest (),
365365 listOfferingsResp : & mariadb.ListOfferingsResponse {
366- Offerings : & []mariadb.Offering {
366+ Offerings : []mariadb.Offering {
367367 {
368- Version : utils . Ptr ( "example-version" ) ,
369- Plans : & []mariadb.Plan {
368+ Version : "example-version" ,
369+ Plans : []mariadb.Plan {
370370 {
371- Name : utils . Ptr ( "example-plan-name" ) ,
372- Id : utils . Ptr ( testPlanId ) ,
371+ Name : "example-plan-name" ,
372+ Id : testPlanId ,
373373 },
374374 },
375375 },
@@ -387,13 +387,13 @@ func TestBuildRequest(t *testing.T) {
387387 ),
388388 expectedRequest : fixtureRequest (),
389389 listOfferingsResp : & mariadb.ListOfferingsResponse {
390- Offerings : & []mariadb.Offering {
390+ Offerings : []mariadb.Offering {
391391 {
392- Version : utils . Ptr ( "example-version" ) ,
393- Plans : & []mariadb.Plan {
392+ Version : "example-version" ,
393+ Plans : []mariadb.Plan {
394394 {
395- Name : utils . Ptr ( "example-plan-name" ) ,
396- Id : utils . Ptr ( testPlanId ) ,
395+ Name : "example-plan-name" ,
396+ Id : testPlanId ,
397397 },
398398 },
399399 },
@@ -422,13 +422,13 @@ func TestBuildRequest(t *testing.T) {
422422 },
423423 ),
424424 listOfferingsResp : & mariadb.ListOfferingsResponse {
425- Offerings : & []mariadb.Offering {
425+ Offerings : []mariadb.Offering {
426426 {
427- Version : utils . Ptr ( "example-version" ) ,
428- Plans : & []mariadb.Plan {
427+ Version : "example-version" ,
428+ Plans : []mariadb.Plan {
429429 {
430- Name : utils . Ptr ( "other-plan-name" ) ,
431- Id : utils . Ptr ( testPlanId ) ,
430+ Name : "other-plan-name" ,
431+ Id : testPlanId ,
432432 },
433433 },
434434 },
@@ -445,18 +445,18 @@ func TestBuildRequest(t *testing.T) {
445445 },
446446 InstanceId : testInstanceId ,
447447 },
448- expectedRequest : testClient .PartialUpdateInstance (testCtx , testProjectId , testInstanceId ).
448+ expectedRequest : testClient .DefaultAPI . PartialUpdateInstance (testCtx , testProjectId , testInstanceId ).
449449 PartialUpdateInstancePayload (mariadb.PartialUpdateInstancePayload {Parameters : & mariadb.InstanceParameters {}}),
450450 },
451451 }
452452
453453 for _ , tt := range tests {
454454 t .Run (tt .description , func (t * testing.T ) {
455- client := & mariaDBClientMocked {
455+ settings := mockSettings {
456456 returnError : tt .getOfferingsFails ,
457457 listOfferingsResp : tt .listOfferingsResp ,
458458 }
459- request , err := buildRequest (testCtx , tt .model , client )
459+ request , err := buildRequest (testCtx , tt .model , newAPIMock ( settings ) )
460460 if err != nil {
461461 if ! tt .isValid {
462462 return
@@ -467,6 +467,8 @@ func TestBuildRequest(t *testing.T) {
467467 diff := cmp .Diff (request , tt .expectedRequest ,
468468 cmp .AllowUnexported (tt .expectedRequest ),
469469 cmpopts .EquateComparable (testCtx ),
470+ cmpopts .EquateEmpty (),
471+ cmpopts .IgnoreFields (tt .expectedRequest , "ApiService" ),
470472 )
471473 if diff != "" {
472474 t .Fatalf ("Data does not match: %s" , diff )
0 commit comments