Skip to content

Commit

Permalink
Breaking client methods in provider
Browse files Browse the repository at this point in the history
  • Loading branch information
1riatsila1 committed Oct 30, 2024
1 parent 5b7ff90 commit b226c75
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 38 deletions.
30 changes: 15 additions & 15 deletions pkg/config-api-client/test/api_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand Down Expand Up @@ -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").
Expand Down Expand Up @@ -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").
Expand Down Expand Up @@ -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)
Expand All @@ -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"}).
Expand Down Expand Up @@ -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").
Expand Down Expand Up @@ -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").
Expand Down Expand Up @@ -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)
Expand All @@ -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").
Expand Down Expand Up @@ -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").
Expand Down Expand Up @@ -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").
Expand Down Expand Up @@ -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").
Expand Down Expand Up @@ -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)
Expand All @@ -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").
Expand Down Expand Up @@ -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").
Expand Down
2 changes: 1 addition & 1 deletion pkg/config-api-provider/provider/data-sources/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/config-api-provider/provider/data-sources/sensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions pkg/config-api-provider/provider/resources/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pkg/config-api-provider/provider/resources/sensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion pkg/config-api-provider/test/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit b226c75

Please sign in to comment.