Skip to content

Commit

Permalink
Merge branch 'main' into ay/fix/latest-client-api-group-rename
Browse files Browse the repository at this point in the history
  • Loading branch information
1riatsila1 authored Oct 25, 2024
2 parents 9e12782 + 20a8471 commit f260244
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 49 deletions.
2 changes: 1 addition & 1 deletion pkg/config-api-provider/provider/resources/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (r *groupResource) Update(ctx context.Context, req resource.UpdateRequest,
return
}

patchRequest := config_api_client.NewGroupsPatchRequest("new_name")
patchRequest := config_api_client.NewGroupsPatchRequest(plan.Name.ValueString())
request := r.client.ConfigurationAPI.
GroupsPatchNetworkingUxiV1alpha1GroupsGroupUidPatch(ctx, plan.ID.ValueString()).
GroupsPatchRequest(*patchRequest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,15 @@ func (r *serviceTestGroupAssignmentResource) Delete(ctx context.Context, req res
return
}

// Delete existing serviceTestGroupAssignment using the plan_id
request := r.client.ConfigurationAPI.DeleteServiceTestGroupAssignmentUxiV1alpha1ServiceTestGroupAssignmentsIdDelete(ctx, state.ID.ValueString())

_, response, err := util.RetryFor429(request.Execute)
errorPresent, errorDetail := util.RaiseForStatus(response, err)

if errorPresent {
resp.Diagnostics.AddError(util.GenerateErrorSummary("delete", "uxi_service_test_group_assignment"), errorDetail)
return
}
}

func (r *serviceTestGroupAssignmentResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ func TestAgentGroupAssignmentResource(t *testing.T) {
}

// required for group create
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), 1)
util.MockPostGroup(
util.GenerateGroupRequestModel("group_uid", "", ""),
util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")),
1,
)
util.MockGetGroup(
"group_uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}),
Expand Down Expand Up @@ -98,7 +102,11 @@ func TestAgentGroupAssignmentResource(t *testing.T) {
)

// required for creating another group
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")), 1)
util.MockPostGroup(
util.GenerateGroupRequestModel("group_uid_2", "_2", "_2"),
util.StructToMap(util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")),
1,
)

// required for agent group assignment create
resources.GetAgentGroupAssignment = func(uid string) resources.AgentGroupAssignmentResponseModel {
Expand Down
34 changes: 28 additions & 6 deletions pkg/config-api-provider/test/resources/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ func TestGroupResource(t *testing.T) {
// Create and Read testing
{
PreConfig: func() {
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponseModel("uid", "", "")), 1)
util.MockPostGroup(
util.GenerateGroupRequestModel("uid", "", ""),
util.StructToMap(util.GenerateGroupResponseModel("uid", "", "")),
1,
)
util.MockGetGroup("uid", util.GeneratePaginatedResponse(
[]map[string]interface{}{util.GenerateGroupResponseModel("uid", "", "")}),
1,
Expand Down Expand Up @@ -65,7 +69,10 @@ func TestGroupResource(t *testing.T) {
1,
)
// updated group
util.MockUpdateGroup("uid", util.GenerateGroupResponseModel("uid", "_2", ""),
util.MockUpdateGroup(
"uid",
map[string]interface{}{"name": "name_2"},
util.GenerateGroupResponseModel("uid", "_2", ""),
1,
)
util.MockGetGroup("uid", util.GeneratePaginatedResponse(
Expand Down Expand Up @@ -93,7 +100,11 @@ func TestGroupResource(t *testing.T) {
1,
)
// new group (replacement)
util.MockPostGroup(util.GenerateGroupResponseModel("new_uid", "", "_2"), 1)
util.MockPostGroup(
util.GenerateGroupRequestModel("new_uid", "", "_2"),
util.GenerateGroupResponseModel("new_uid", "", "_2"),
1,
)
util.MockGetGroup("new_uid", util.GeneratePaginatedResponse(
[]map[string]interface{}{util.GenerateGroupResponseModel("new_uid", "", "_2")}),
1,
Expand Down Expand Up @@ -186,7 +197,11 @@ func TestGroupResource429Handling(t *testing.T) {
Post("/networking-uxi/v1alpha1/groups").
Reply(429).
SetHeaders(util.RateLimitingHeaders)
util.MockPostGroup(util.GenerateGroupResponseModel("uid", "", ""), 1)
util.MockPostGroup(
util.GenerateGroupRequestModel("uid", "", ""),
util.GenerateGroupResponseModel("uid", "", ""),
1,
)
util.MockGetGroup(
"uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("uid", "", "")}),
Expand Down Expand Up @@ -219,7 +234,10 @@ func TestGroupResource429Handling(t *testing.T) {
Patch("/networking-uxi/v1alpha1/groups/uid").
Reply(429).
SetHeaders(util.RateLimitingHeaders)
util.MockUpdateGroup("uid", util.GenerateGroupResponseModel("uid", "_2", ""),
util.MockUpdateGroup(
"uid",
map[string]interface{}{"name": "name_2"},
util.GenerateGroupResponseModel("uid", "_2", ""),
1,
)
util.MockGetGroup("uid", util.GeneratePaginatedResponse(
Expand Down Expand Up @@ -336,7 +354,11 @@ func TestGroupResourceHttpErrorHandling(t *testing.T) {
// Create group in prep for next step
{
PreConfig: func() {
util.MockPostGroup(util.GenerateGroupResponseModel("uid", "", ""), 1)
util.MockPostGroup(
util.GenerateGroupRequestModel("uid", "", ""),
util.GenerateGroupResponseModel("uid", "", ""),
1,
)
util.MockGetGroup(
"uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("uid", "", "")}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,19 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) {
)

// required for group create
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), 1)
util.MockPostGroup(
util.GenerateGroupRequestModel("group_uid", "", ""),
util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")),
1,
)
util.MockGetGroup("group_uid", util.GeneratePaginatedResponse(
[]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}),
2,
)

// required for network group assignment create
util.MockPostNetworkGroupAssignment(
"network_group_assignment_uid",
util.GenerateNetworkGroupAssignmentRequest("network_group_assignment_uid", ""),
util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", ""),
1,
)
Expand Down Expand Up @@ -112,12 +116,16 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(t *testing.T) {
)

// required for creating another group
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")), 1)
util.MockPostGroup(
util.GenerateGroupRequestModel("group_uid_2", "_2", "_2"),
util.StructToMap(util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")),
1,
)

// required for network group assignment create
util.MockDeleteNetworkGroupAssignment("network_group_assignment_uid", 1)
util.MockPostNetworkGroupAssignment(
"network_group_assignment_uid_2",
util.GenerateNetworkGroupAssignmentRequest("network_group_assignment_uid_2", "_2"),
util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid_2", "_2"),
1,
)
Expand Down Expand Up @@ -252,7 +260,11 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) {
2,
)
// required for group create
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), 1)
util.MockPostGroup(
util.GenerateGroupRequestModel("group_uid", "", ""),
util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")),
1,
)
util.MockGetGroup(
"group_uid",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}),
Expand All @@ -261,7 +273,7 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) {

// required for network group assignment create
util.MockPostNetworkGroupAssignment(
"network_group_assignment_uid",
util.GenerateNetworkGroupAssignmentRequest("network_group_assignment_uid", ""),
util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", ""),
1,
)
Expand Down Expand Up @@ -326,7 +338,11 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) {

// required for creating another group
util.MockDeleteNetworkGroupAssignment("network_group_assignment_uid", 1)
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")), 1)
util.MockPostGroup(
util.GenerateGroupRequestModel("group_uid_2", "_2", "_2"),
util.StructToMap(util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")),
1,
)
util.MockGetGroup(
"group_uid_2",
util.GeneratePaginatedResponse([]map[string]interface{}{util.GenerateGroupResponseModel("group_uid_2", "_2", "_2")}),
Expand All @@ -351,7 +367,7 @@ func TestNetworkGroupAssignmentResourceForWirelessNetwork(t *testing.T) {
2,
)
util.MockPostNetworkGroupAssignment(
"network_group_assignment_uid_2",
util.GenerateNetworkGroupAssignmentRequest("network_group_assignment_uid_2", "_2"),
util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid_2", "_2"),
1,
)
Expand Down Expand Up @@ -478,7 +494,11 @@ func TestNetworkGroupAssignmentResource429Handling(t *testing.T) {
)

// required for group create
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), 1)
util.MockPostGroup(
util.GenerateGroupRequestModel("group_uid", "", ""),
util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")),
1,
)
util.MockGetGroup("group_uid", util.GeneratePaginatedResponse(
[]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}),
2,
Expand All @@ -490,7 +510,7 @@ func TestNetworkGroupAssignmentResource429Handling(t *testing.T) {
Reply(429).
SetHeaders(util.RateLimitingHeaders)
util.MockPostNetworkGroupAssignment(
"network_group_assignment_uid",
util.GenerateNetworkGroupAssignmentRequest("network_group_assignment_uid", ""),
util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", ""),
1,
)
Expand Down Expand Up @@ -591,7 +611,11 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) {
)

// required for group create
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), 1)
util.MockPostGroup(
util.GenerateGroupRequestModel("group_uid", "", ""),
util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")),
1,
)
util.MockGetGroup("group_uid", util.GeneratePaginatedResponse(
[]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}),
2,
Expand Down Expand Up @@ -640,7 +664,11 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) {
)

// required for group create
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), 1)
util.MockPostGroup(
util.GenerateGroupRequestModel("group_uid", "", ""),
util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")),
1,
)
util.MockGetGroup("group_uid", util.GeneratePaginatedResponse(
[]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}),
2,
Expand Down Expand Up @@ -690,7 +718,11 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) {
)

// required for group create
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), 1)
util.MockPostGroup(
util.GenerateGroupRequestModel("group_uid", "", ""),
util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")),
1,
)
util.MockGetGroup("group_uid", util.GeneratePaginatedResponse(
[]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}),
2,
Expand Down Expand Up @@ -745,15 +777,19 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) {
)

// required for group create
util.MockPostGroup(util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")), 1)
util.MockPostGroup(
util.GenerateGroupRequestModel("group_uid", "", ""),
util.StructToMap(util.GenerateGroupResponseModel("group_uid", "", "")),
1,
)
util.MockGetGroup("group_uid", util.GeneratePaginatedResponse(
[]map[string]interface{}{util.GenerateGroupResponseModel("group_uid", "", "")}),
2,
)

// required for network group assignment create
util.MockPostNetworkGroupAssignment(
"network_group_assignment_uid",
util.GenerateNetworkGroupAssignmentRequest("network_group_assignment_uid", ""),
util.GenerateNetworkGroupAssignmentResponse("network_group_assignment_uid", ""),
1,
)
Expand Down
Loading

0 comments on commit f260244

Please sign in to comment.