Skip to content

Commit

Permalink
fix: groups patch variable and improve test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
1riatsila1 committed Oct 24, 2024
1 parent 9acc55a commit 2c40c94
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 47 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 @@ -171,7 +171,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.
GroupsPatchUxiV1alpha1GroupsGroupUidPatch(ctx, plan.ID.ValueString()).
GroupsPatchRequest(*patchRequest)
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 @@ -185,7 +196,11 @@ func TestGroupResource429Handling(t *testing.T) {
Post("/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 @@ -218,7 +233,10 @@ func TestGroupResource429Handling(t *testing.T) {
Patch("/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 @@ -335,7 +353,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 2c40c94

Please sign in to comment.