From b226c754d8d225f62cb4dd4bffc973a931b8bec8 Mon Sep 17 00:00:00 2001 From: 1riatsila1 Date: Wed, 30 Oct 2024 08:39:55 +0000 Subject: [PATCH] Breaking client methods in provider --- .../test/api_configuration_test.go | 30 +++++++++---------- .../provider/data-sources/group.go | 2 +- .../data-sources/network_group_assignment.go | 2 +- .../provider/data-sources/sensor.go | 2 +- .../data-sources/sensor_group_assignment.go | 2 +- .../provider/data-sources/wired_network.go | 2 +- .../provider/data-sources/wireless_network.go | 2 +- .../provider/resources/group.go | 9 +++--- .../resources/network_group_assignment.go | 6 ++-- .../provider/resources/sensor.go | 2 +- .../resources/sensor_group_assignment.go | 6 ++-- .../resources/service_group_assignment.go | 4 +-- .../provider/resources/wired_network.go | 2 +- .../provider/resources/wireless_network.go | 2 +- pkg/config-api-provider/test/util/utils.go | 4 ++- 15 files changed, 39 insertions(+), 38 deletions(-) diff --git a/pkg/config-api-client/test/api_configuration_test.go b/pkg/config-api-client/test/api_configuration_test.go index c32f56ea..c63256ea 100644 --- a/pkg/config-api-client/test/api_configuration_test.go +++ b/pkg/config-api-client/test/api_configuration_test.go @@ -20,7 +20,7 @@ func TestConfigurationAPI(t *testing.T) { defer gock.Off() - t.Run("Test ConfigurationAPI GroupsGetNetworkingUxiV1alpha1GroupsGet", func(t *testing.T) { + t.Run("Test ConfigurationAPI GroupsGet", func(t *testing.T) { parent_uid := "parent_uid" gock.New(configuration.Scheme + "://" + configuration.Host). Get("/networking-uxi/v1alpha1/groups"). @@ -63,7 +63,7 @@ func TestConfigurationAPI(t *testing.T) { }) }) - t.Run("Test ConfigurationAPI GroupsPostNetworkingUxiV1alpha1GroupsPost", func(t *testing.T) { + t.Run("Test ConfigurationAPI GroupsPost", func(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Post("/networking-uxi/v1alpha1/groups"). @@ -96,7 +96,7 @@ func TestConfigurationAPI(t *testing.T) { }) }) - t.Run("Test ConfigurationAPI GroupsPatchNetworkingUxiV1alpha1GroupsGroupUidPatch", func(t *testing.T) { + t.Run("Test ConfigurationAPI GroupsPatch", func(t *testing.T) { gock.New(configuration.Scheme+"://"+configuration.Host). Patch("/networking-uxi/v1alpha1/groups/node"). MatchHeader("Content-Type", "application/merge-patch+json"). @@ -124,7 +124,7 @@ func TestConfigurationAPI(t *testing.T) { }) }) - t.Run("Test ConfigurationAPI GroupsDeleteNetworkingUxiV1alpha1GroupsGroupUidDelete", func(t *testing.T) { + t.Run("Test ConfigurationAPI GroupsDelete", func(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Delete("/networking-uxi/v1alpha1/groups/uid"). Reply(204) @@ -137,7 +137,7 @@ func TestConfigurationAPI(t *testing.T) { assert.Equal(t, 204, httpRes.StatusCode) }) - t.Run("Test ConfigurationAPI GetNetworkingUxiV1alpha1SensorsGet", func(t *testing.T) { + t.Run("Test ConfigurationAPI SensorsGet", func(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Get("/networking-uxi/v1alpha1/sensors"). MatchParams(map[string]string{"id": "uid", "limit": "10", "next": "some-cursor"}). @@ -203,7 +203,7 @@ func TestConfigurationAPI(t *testing.T) { }) }) - t.Run("Test ConfigurationAPI GetNetworkingUxiV1alpha1SensorGroupAssignmentsGet", func(t *testing.T) { + t.Run("Test ConfigurationAPI SensorGroupAssignmentsGet", func(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Get("/networking-uxi/v1alpha1/sensor-group-assignments"). @@ -244,7 +244,7 @@ func TestConfigurationAPI(t *testing.T) { }) }) - t.Run("Test ConfigurationAPI PostNetworkingUxiV1alpha1SensorGroupAssignmentsPost", func(t *testing.T) { + t.Run("Test ConfigurationAPI SensorGroupAssignmentsPost", func(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Post("/networking-uxi/v1alpha1/sensor-group-assignments"). @@ -276,7 +276,7 @@ func TestConfigurationAPI(t *testing.T) { }) }) - t.Run("Test ConfigurationAPI DeleteSensorGroupAssignmentNetworkingUxiV1alpha1SensorGroupAssignmentsIdDelete", func(t *testing.T) { + t.Run("Test ConfigurationAPI SensorGroupAssignmentsDelete", func(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Delete("/networking-uxi/v1alpha1/sensor-group-assignments/uid"). Reply(204) @@ -289,7 +289,7 @@ func TestConfigurationAPI(t *testing.T) { assert.Equal(t, 204, httpRes.StatusCode) }) - t.Run("Test ConfigurationAPI GetNetworkingUxiV1alpha1WiredNetworksGet", func(t *testing.T) { + t.Run("Test ConfigurationAPI WiredNetworksGet", func(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Get("/networking-uxi/v1alpha1/wired-networks"). @@ -350,7 +350,7 @@ func TestConfigurationAPI(t *testing.T) { }) }) - t.Run("Test ConfigurationAPI GetNetworkingUxiV1alpha1WirelessNetworksGet", func(t *testing.T) { + t.Run("Test ConfigurationAPI WirelessNetworksGet", func(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Get("/networking-uxi/v1alpha1/wireless-networks"). @@ -414,7 +414,7 @@ func TestConfigurationAPI(t *testing.T) { }) }) - t.Run("Test ConfigurationAPI GetNetworkingUxiV1alpha1NetworkGroupAssignmentsGet", func(t *testing.T) { + t.Run("Test ConfigurationAPI NetworkGroupAssignmentsGet", func(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Get("/networking-uxi/v1alpha1/network-group-assignments"). @@ -455,7 +455,7 @@ func TestConfigurationAPI(t *testing.T) { }) }) - t.Run("Test ConfigurationAPI PostNetworkingUxiV1alpha1NetworkGroupAssignmentsPost", func(t *testing.T) { + t.Run("Test ConfigurationAPI NetworkGroupAssignmentsPost", func(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Post("/networking-uxi/v1alpha1/network-group-assignments"). @@ -487,7 +487,7 @@ func TestConfigurationAPI(t *testing.T) { }) }) - t.Run("Test ConfigurationAPI DeleteNetworkGroupAssignmentNetworkingUxiV1alpha1NetworkGroupAssignmentsIdDelete", func(t *testing.T) { + t.Run("Test ConfigurationAPI NetworkGroupAssignmentsDelete", func(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Delete("/networking-uxi/v1alpha1/network-group-assignments/uid"). Reply(204) @@ -500,7 +500,7 @@ func TestConfigurationAPI(t *testing.T) { assert.Equal(t, 204, httpRes.StatusCode) }) - t.Run("Test ConfigurationAPI PostNetworkingUxiV1alpha1ServiceTestGroupAssignmentsPost", func(t *testing.T) { + t.Run("Test ConfigurationAPI ServiceTestGroupAssignmentsPost", func(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Post("/networking-uxi/v1alpha1/service-test-group-assignments"). @@ -532,7 +532,7 @@ func TestConfigurationAPI(t *testing.T) { }) }) - t.Run("Test ConfigurationAPI DeleteServiceTestGroupAssignmentNetworkingUxiV1alpha1ServiceTestGroupAssignmentsIdDelete", func(t *testing.T) { + t.Run("Test ConfigurationAPI ServiceTestGroupAssignmentsDelete", func(t *testing.T) { gock.New(configuration.Scheme + "://" + configuration.Host). Delete("/networking-uxi/v1alpha1/service-test-group-assignments/uid"). diff --git a/pkg/config-api-provider/provider/data-sources/group.go b/pkg/config-api-provider/provider/data-sources/group.go index e549e7a3..73476b72 100644 --- a/pkg/config-api-provider/provider/data-sources/group.go +++ b/pkg/config-api-provider/provider/data-sources/group.go @@ -75,7 +75,7 @@ func (d *groupDataSource) Read(ctx context.Context, req datasource.ReadRequest, } request := d.client.ConfigurationAPI. - GroupsGetNetworkingUxiV1alpha1GroupsGet(ctx). + GroupsGet(ctx). Id(*state.Filter.GroupID) groupResponse, response, err := util.RetryFor429(request.Execute) diff --git a/pkg/config-api-provider/provider/data-sources/network_group_assignment.go b/pkg/config-api-provider/provider/data-sources/network_group_assignment.go index 97196883..36b6f279 100644 --- a/pkg/config-api-provider/provider/data-sources/network_group_assignment.go +++ b/pkg/config-api-provider/provider/data-sources/network_group_assignment.go @@ -70,7 +70,7 @@ func (d *networkGroupAssignmentDataSource) Read(ctx context.Context, req datasou } request := d.client.ConfigurationAPI. - GetNetworkingUxiV1alpha1NetworkGroupAssignmentsGet(ctx). + NetworkGroupAssignmentsGet(ctx). Id(state.Filter.NetworkGroupAssignmentID) networkGroupAssignmentResponse, response, err := util.RetryFor429(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) diff --git a/pkg/config-api-provider/provider/data-sources/sensor.go b/pkg/config-api-provider/provider/data-sources/sensor.go index 2fe67013..08f2f3a3 100644 --- a/pkg/config-api-provider/provider/data-sources/sensor.go +++ b/pkg/config-api-provider/provider/data-sources/sensor.go @@ -103,7 +103,7 @@ func (d *sensorDataSource) Read(ctx context.Context, req datasource.ReadRequest, } request := d.client.ConfigurationAPI. - GetNetworkingUxiV1alpha1SensorsGet(ctx). + SensorsGet(ctx). Id(state.Filter.SensorID.ValueString()) sensorResponse, response, err := util.RetryFor429(request.Execute) diff --git a/pkg/config-api-provider/provider/data-sources/sensor_group_assignment.go b/pkg/config-api-provider/provider/data-sources/sensor_group_assignment.go index b7bd3e69..2b2a08af 100644 --- a/pkg/config-api-provider/provider/data-sources/sensor_group_assignment.go +++ b/pkg/config-api-provider/provider/data-sources/sensor_group_assignment.go @@ -72,7 +72,7 @@ func (d *sensorGroupAssignmentDataSource) Read(ctx context.Context, req datasour } request := d.client.ConfigurationAPI. - GetNetworkingUxiV1alpha1SensorGroupAssignmentsGet(ctx). + SensorGroupAssignmentsGet(ctx). Id(state.Filter.SensorGroupAssignmentID) sensorGroupAssignmentResponse, response, err := util.RetryFor429(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) diff --git a/pkg/config-api-provider/provider/data-sources/wired_network.go b/pkg/config-api-provider/provider/data-sources/wired_network.go index 78818318..b75cff07 100644 --- a/pkg/config-api-provider/provider/data-sources/wired_network.go +++ b/pkg/config-api-provider/provider/data-sources/wired_network.go @@ -97,7 +97,7 @@ func (d *wiredNetworkDataSource) Read(ctx context.Context, req datasource.ReadRe } request := d.client.ConfigurationAPI. - GetNetworkingUxiV1alpha1WiredNetworksGet(ctx). + WiredNetworksGet(ctx). Id(state.Filter.WiredNetworkID) networkResponse, response, err := util.RetryFor429(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) diff --git a/pkg/config-api-provider/provider/data-sources/wireless_network.go b/pkg/config-api-provider/provider/data-sources/wireless_network.go index 974dcedd..8e8b672a 100644 --- a/pkg/config-api-provider/provider/data-sources/wireless_network.go +++ b/pkg/config-api-provider/provider/data-sources/wireless_network.go @@ -105,7 +105,7 @@ func (d *wirelessNetworkDataSource) Read(ctx context.Context, req datasource.Rea } request := d.client.ConfigurationAPI. - GetNetworkingUxiV1alpha1WirelessNetworksGet(ctx). + WirelessNetworksGet(ctx). Id(state.Filter.WirelessNetworkID) networkResponse, response, err := util.RetryFor429(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) diff --git a/pkg/config-api-provider/provider/resources/group.go b/pkg/config-api-provider/provider/resources/group.go index 674626fc..6a53854e 100644 --- a/pkg/config-api-provider/provider/resources/group.go +++ b/pkg/config-api-provider/provider/resources/group.go @@ -96,7 +96,7 @@ func (r *groupResource) Create(ctx context.Context, req resource.CreateRequest, groups_post_request.SetParentId(plan.ParentGroupId.ValueString()) } request := r.client.ConfigurationAPI. - GroupsPostNetworkingUxiV1alpha1GroupsPost(ctx). + GroupsPost(ctx). GroupsPostRequest(*groups_post_request) group, response, err := util.RetryFor429(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) @@ -129,7 +129,7 @@ func (r *groupResource) Read(ctx context.Context, req resource.ReadRequest, resp } request := r.client.ConfigurationAPI. - GroupsGetNetworkingUxiV1alpha1GroupsGet(ctx). + GroupsGet(ctx). Id(state.ID.ValueString()) groupResponse, response, err := util.RetryFor429(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) @@ -175,7 +175,7 @@ func (r *groupResource) Update(ctx context.Context, req resource.UpdateRequest, patchRequest := config_api_client.NewGroupsPatchRequest(plan.Name.ValueString()) request := r.client.ConfigurationAPI. - GroupsPatchNetworkingUxiV1alpha1GroupsGroupUidPatch(ctx, plan.ID.ValueString()). + GroupsPatch(ctx, plan.ID.ValueString()). GroupsPatchRequest(*patchRequest) group, response, err := util.RetryFor429(request.Execute) @@ -208,8 +208,7 @@ func (r *groupResource) Delete(ctx context.Context, req resource.DeleteRequest, } // Delete existing group using the plan_id - request := r.client.ConfigurationAPI. - GroupsDeleteNetworkingUxiV1alpha1GroupsGroupUidDelete(ctx, state.ID.ValueString()) + request := r.client.ConfigurationAPI.GroupsDelete(ctx, state.ID.ValueString()) _, response, err := util.RetryFor429(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) diff --git a/pkg/config-api-provider/provider/resources/network_group_assignment.go b/pkg/config-api-provider/provider/resources/network_group_assignment.go index 2595ba66..af22e974 100644 --- a/pkg/config-api-provider/provider/resources/network_group_assignment.go +++ b/pkg/config-api-provider/provider/resources/network_group_assignment.go @@ -94,7 +94,7 @@ func (r *networkGroupAssignmentResource) Create(ctx context.Context, req resourc plan.NetworkID.ValueString(), ) request := r.client.ConfigurationAPI. - PostNetworkingUxiV1alpha1NetworkGroupAssignmentsPost(ctx). + NetworkGroupAssignmentsPost(ctx). NetworkGroupAssignmentsPostRequest(*postRequest) networkGroupAssignment, response, err := util.RetryFor429(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) @@ -127,7 +127,7 @@ func (r *networkGroupAssignmentResource) Read(ctx context.Context, req resource. } request := r.client.ConfigurationAPI. - GetNetworkingUxiV1alpha1NetworkGroupAssignmentsGet(ctx). + NetworkGroupAssignmentsGet(ctx). Id(state.ID.ValueString()) networkGroupAssignmentResponse, response, err := util.RetryFor429(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) @@ -178,7 +178,7 @@ func (r *networkGroupAssignmentResource) Delete(ctx context.Context, req resourc } request := r.client.ConfigurationAPI. - DeleteNetworkGroupAssignmentNetworkingUxiV1alpha1NetworkGroupAssignmentsIdDelete(ctx, state.ID.ValueString()) + NetworkGroupAssignmentsDelete(ctx, state.ID.ValueString()) _, response, err := util.RetryFor429(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) diff --git a/pkg/config-api-provider/provider/resources/sensor.go b/pkg/config-api-provider/provider/resources/sensor.go index e6d96bba..725f3159 100644 --- a/pkg/config-api-provider/provider/resources/sensor.go +++ b/pkg/config-api-provider/provider/resources/sensor.go @@ -125,7 +125,7 @@ func (r *sensorResource) Read(ctx context.Context, req resource.ReadRequest, res } request := r.client.ConfigurationAPI. - GetNetworkingUxiV1alpha1SensorsGet(ctx). + SensorsGet(ctx). Id(state.ID.ValueString()) sensorResponse, response, err := util.RetryFor429(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) diff --git a/pkg/config-api-provider/provider/resources/sensor_group_assignment.go b/pkg/config-api-provider/provider/resources/sensor_group_assignment.go index 7efe67ec..f5bc99ff 100644 --- a/pkg/config-api-provider/provider/resources/sensor_group_assignment.go +++ b/pkg/config-api-provider/provider/resources/sensor_group_assignment.go @@ -99,7 +99,7 @@ func (r *sensorGroupAssignmentResource) Create(ctx context.Context, req resource postRequest := config_api_client.NewSensorGroupAssignmentsPostRequest(plan.GroupID.ValueString(), plan.SensorID.ValueString()) request := r.client.ConfigurationAPI. - PostNetworkingUxiV1alpha1SensorGroupAssignmentsPost(ctx). + SensorGroupAssignmentsPost(ctx). SensorGroupAssignmentsPostRequest(*postRequest) sensorGroupAssignment, response, err := util.RetryFor429(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) @@ -130,7 +130,7 @@ func (r *sensorGroupAssignmentResource) Read(ctx context.Context, req resource.R } request := r.client.ConfigurationAPI. - GetNetworkingUxiV1alpha1SensorGroupAssignmentsGet(ctx). + SensorGroupAssignmentsGet(ctx). Id(state.ID.ValueString()) sensorGroupAssignmentResponse, response, err := util.RetryFor429(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) @@ -183,7 +183,7 @@ func (r *sensorGroupAssignmentResource) Delete(ctx context.Context, req resource // Delete existing sensorGroupAssignment using the plan_id request := r.client.ConfigurationAPI. - DeleteSensorGroupAssignmentNetworkingUxiV1alpha1SensorGroupAssignmentsIdDelete(ctx, state.ID.ValueString()) + SensorGroupAssignmentsDelete(ctx, state.ID.ValueString()) _, response, err := util.RetryFor429(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) diff --git a/pkg/config-api-provider/provider/resources/service_group_assignment.go b/pkg/config-api-provider/provider/resources/service_group_assignment.go index 6443fc4d..a8c40ecd 100644 --- a/pkg/config-api-provider/provider/resources/service_group_assignment.go +++ b/pkg/config-api-provider/provider/resources/service_group_assignment.go @@ -94,7 +94,7 @@ func (r *serviceTestGroupAssignmentResource) Create(ctx context.Context, req res plan.ServiceTestID.ValueString(), ) request := r.client.ConfigurationAPI. - PostNetworkingUxiV1alpha1ServiceTestGroupAssignmentsPost(ctx). + ServiceTestGroupAssignmentsPost(ctx). ServiceTestGroupAssignmentsPostRequest(*postRequest) serviceTestGroupAssignment, response, err := util.RetryFor429(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) @@ -162,7 +162,7 @@ func (r *serviceTestGroupAssignmentResource) Delete(ctx context.Context, req res } request := r.client.ConfigurationAPI. - DeleteServiceTestGroupAssignmentNetworkingUxiV1alpha1ServiceTestGroupAssignmentsIdDelete(ctx, state.ID.ValueString()) + ServiceTestGroupAssignmentsDelete(ctx, state.ID.ValueString()) _, response, err := util.RetryFor429(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) diff --git a/pkg/config-api-provider/provider/resources/wired_network.go b/pkg/config-api-provider/provider/resources/wired_network.go index c4658fd2..066dac01 100644 --- a/pkg/config-api-provider/provider/resources/wired_network.go +++ b/pkg/config-api-provider/provider/resources/wired_network.go @@ -90,7 +90,7 @@ func (r *wiredNetworkResource) Read(ctx context.Context, req resource.ReadReques } request := r.client.ConfigurationAPI. - GetNetworkingUxiV1alpha1WiredNetworksGet(ctx). + WiredNetworksGet(ctx). Id(state.ID.ValueString()) networkResponse, response, err := util.RetryFor429(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) diff --git a/pkg/config-api-provider/provider/resources/wireless_network.go b/pkg/config-api-provider/provider/resources/wireless_network.go index f23ca858..ebc84741 100644 --- a/pkg/config-api-provider/provider/resources/wireless_network.go +++ b/pkg/config-api-provider/provider/resources/wireless_network.go @@ -90,7 +90,7 @@ func (r *wirelessNetworkResource) Read(ctx context.Context, req resource.ReadReq } request := r.client.ConfigurationAPI. - GetNetworkingUxiV1alpha1WirelessNetworksGet(ctx). + WirelessNetworksGet(ctx). Id(state.ID.ValueString()) networkResponse, response, err := util.RetryFor429(request.Execute) errorPresent, errorDetail := util.RaiseForStatus(response, err) diff --git a/pkg/config-api-provider/test/util/utils.go b/pkg/config-api-provider/test/util/utils.go index 98ff9f52..5b6ca886 100644 --- a/pkg/config-api-provider/test/util/utils.go +++ b/pkg/config-api-provider/test/util/utils.go @@ -214,11 +214,13 @@ func MockGetGroup(uid string, response map[string]interface{}, times int) { } func MockUpdateGroup(uid string, request map[string]interface{}, response map[string]interface{}, times int) { + body, _ := json.Marshal(request) gock.New("https://test.api.capenetworks.com"). Patch("/networking-uxi/v1alpha1/groups/"+uid). MatchHeader("Authorization", "mock_token"). + MatchHeader("Content-Type", "application/merge-patch+json"). + BodyString(string(body)). Times(times). - JSON(request). Reply(200). JSON(response) }