diff --git a/pkg/config-api-provider/provider/resources/group.go b/pkg/config-api-provider/provider/resources/group.go index 924fd300..a30ee112 100644 --- a/pkg/config-api-provider/provider/resources/group.go +++ b/pkg/config-api-provider/provider/resources/group.go @@ -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) diff --git a/pkg/config-api-provider/test/resources/agent_group_assignment_test.go b/pkg/config-api-provider/test/resources/agent_group_assignment_test.go index b4ac6f80..02e471d7 100644 --- a/pkg/config-api-provider/test/resources/agent_group_assignment_test.go +++ b/pkg/config-api-provider/test/resources/agent_group_assignment_test.go @@ -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", "", "")}), @@ -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 { diff --git a/pkg/config-api-provider/test/resources/group_test.go b/pkg/config-api-provider/test/resources/group_test.go index 002cfa19..24a5bff6 100644 --- a/pkg/config-api-provider/test/resources/group_test.go +++ b/pkg/config-api-provider/test/resources/group_test.go @@ -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, @@ -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( @@ -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, @@ -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", "", "")}), @@ -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( @@ -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", "", "")}), diff --git a/pkg/config-api-provider/test/resources/network_group_assignment_test.go b/pkg/config-api-provider/test/resources/network_group_assignment_test.go index 7f12cd84..0969c863 100644 --- a/pkg/config-api-provider/test/resources/network_group_assignment_test.go +++ b/pkg/config-api-provider/test/resources/network_group_assignment_test.go @@ -30,7 +30,11 @@ 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, @@ -38,7 +42,7 @@ func TestNetworkGroupAssignmentResourceForWiredNetwork(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, ) @@ -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, ) @@ -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", "", "")}), @@ -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, ) @@ -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")}), @@ -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, ) @@ -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, @@ -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, ) @@ -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, @@ -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, @@ -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, @@ -745,7 +777,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, @@ -753,7 +789,7 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(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, ) diff --git a/pkg/config-api-provider/test/resources/sensor_group_assignment_test.go b/pkg/config-api-provider/test/resources/sensor_group_assignment_test.go index 001999ba..3586d9d8 100644 --- a/pkg/config-api-provider/test/resources/sensor_group_assignment_test.go +++ b/pkg/config-api-provider/test/resources/sensor_group_assignment_test.go @@ -29,7 +29,11 @@ func TestSensorGroupAssignmentResource(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", "", "")}), @@ -38,7 +42,7 @@ func TestSensorGroupAssignmentResource(t *testing.T) { // required for sensor group assignment create util.MockPostSensorGroupAssignment( - "sensor_group_assignment_uid", + util.GenerateSensorGroupAssignmentRequest("sensor_group_assignment_uid", ""), util.GenerateSensorGroupAssignmentResponse("sensor_group_assignment_uid", ""), 1, ) @@ -115,7 +119,11 @@ func TestSensorGroupAssignmentResource(t *testing.T) { // required for creating another group util.MockDeleteSensorGroupAssignment("sensor_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, + ) // required for sensor group assignment create util.MockGetSensorGroupAssignment( @@ -130,7 +138,7 @@ func TestSensorGroupAssignmentResource(t *testing.T) { ) util.MockPostSensorGroupAssignment( - "sensor_group_assignment_uid_2", + util.GenerateSensorGroupAssignmentRequest("sensor_group_assignment_uid_2", "_2"), util.GenerateSensorGroupAssignmentResponse("sensor_group_assignment_uid_2", "_2"), 1, ) @@ -247,7 +255,11 @@ func TestSensorGroupAssignmentResource429Handling(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", "", "")}), @@ -260,7 +272,7 @@ func TestSensorGroupAssignmentResource429Handling(t *testing.T) { Reply(429). SetHeaders(util.RateLimitingHeaders) util.MockPostSensorGroupAssignment( - "sensor_group_assignment_uid", + util.GenerateSensorGroupAssignmentRequest("sensor_group_assignment_uid", ""), util.GenerateSensorGroupAssignmentResponse("sensor_group_assignment_uid", ""), 1, ) @@ -368,7 +380,11 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(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", "", "")}), @@ -421,7 +437,11 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(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", "", "")}), @@ -475,7 +495,11 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(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", "", "")}), @@ -534,7 +558,11 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(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", "", "")}), @@ -543,7 +571,7 @@ func TestSensorGroupAssignmentResourceHttpErrorHandling(t *testing.T) { // required for sensor group assignment create util.MockPostSensorGroupAssignment( - "sensor_group_assignment_uid", + util.GenerateSensorGroupAssignmentRequest("sensor_group_assignment_uid", ""), util.GenerateSensorGroupAssignmentResponse("sensor_group_assignment_uid", ""), 1, ) diff --git a/pkg/config-api-provider/test/resources/service_test_group_assignment_test.go b/pkg/config-api-provider/test/resources/service_test_group_assignment_test.go index 7dd19727..c98d55e7 100644 --- a/pkg/config-api-provider/test/resources/service_test_group_assignment_test.go +++ b/pkg/config-api-provider/test/resources/service_test_group_assignment_test.go @@ -31,7 +31,11 @@ func TestServiceTestGroupAssignmentResource(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", "", "")}), @@ -40,7 +44,7 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { // required for serviceTest group assignment create util.MockPostServiceTestGroupAssignment( - "service_test_group_assignment_uid", + util.GenerateServiceTestGroupAssignmentRequest("service_test_group_assignment_uid", ""), util.StructToMap(util.GenerateServiceTestGroupAssignmentResponse("service_test_group_assignment_uid", "")), 1, ) @@ -102,7 +106,11 @@ func TestServiceTestGroupAssignmentResource(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 serviceTest group assignment create resources.GetServiceTestGroupAssignment = func(uid string) config_api_client.ServiceTestGroupAssignmentsPostResponse { @@ -113,7 +121,7 @@ func TestServiceTestGroupAssignmentResource(t *testing.T) { } } util.MockPostServiceTestGroupAssignment( - "service_test_group_assignment_uid_2", + util.GenerateServiceTestGroupAssignmentRequest("service_test_group_assignment_uid_2", "_2"), util.StructToMap(util.GenerateServiceTestGroupAssignmentResponse("service_test_group_assignment_uid_2", "_2")), 1, ) @@ -218,7 +226,11 @@ func TestServiceTestGroupAssignmentResource429Handling(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", "", "")}), @@ -232,7 +244,7 @@ func TestServiceTestGroupAssignmentResource429Handling(t *testing.T) { SetHeaders(util.RateLimitingHeaders) util.MockPostServiceTestGroupAssignment( - "service_test_group_assignment_uid", + util.GenerateServiceTestGroupAssignmentRequest("service_test_group_assignment_uid", ""), util.StructToMap(util.GenerateServiceTestGroupAssignmentResponse("service_test_group_assignment_uid", "")), 1, ) @@ -310,7 +322,11 @@ func TestServiceTestGroupAssignmentResourceHttpErrorHandling(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", "", "")}), diff --git a/pkg/config-api-provider/test/util/utils.go b/pkg/config-api-provider/test/util/utils.go index a022a0dc..460bb646 100644 --- a/pkg/config-api-provider/test/util/utils.go +++ b/pkg/config-api-provider/test/util/utils.go @@ -50,6 +50,13 @@ func GenerateGroupResponseModel(uid string, nonReplacementFieldPostfix string, r } } +func GenerateGroupRequestModel(uid string, nonReplacementFieldPostfix string, replacementFieldPostfix string) map[string]interface{} { + return map[string]interface{}{ + "name": "name" + nonReplacementFieldPostfix, + "parentId": "parent_uid" + replacementFieldPostfix, + } +} + func GeneratePaginatedResponse(items []map[string]interface{}) map[string]interface{} { return map[string]interface{}{ "items": items, @@ -114,6 +121,13 @@ func GenerateSensorGroupAssignmentResponse(uid string, postfix string) map[strin } } +func GenerateSensorGroupAssignmentRequest(uid string, postfix string) map[string]interface{} { + return map[string]interface{}{ + "groupId": "group_uid" + postfix, + "sensorId": "sensor_uid" + postfix, + } +} + func GenerateAgentGroupAssignmentResponse(uid string, postfix string) resources.AgentGroupAssignmentResponseModel { return resources.AgentGroupAssignmentResponseModel{ UID: uid, @@ -131,6 +145,13 @@ func GenerateNetworkGroupAssignmentResponse(uid string, postfix string) map[stri } } +func GenerateNetworkGroupAssignmentRequest(uid string, postfix string) map[string]interface{} { + return map[string]interface{}{ + "groupId": "group_uid" + postfix, + "networkId": "network_uid" + postfix, + } +} + func GenerateServiceTestGroupAssignmentResponse(uid string, postfix string) config_api_client.ServiceTestGroupAssignmentsPostResponse { resourceType := "uxi/service-test-group-assignment" return config_api_client.ServiceTestGroupAssignmentsPostResponse{ @@ -141,6 +162,13 @@ func GenerateServiceTestGroupAssignmentResponse(uid string, postfix string) conf } } +func GenerateServiceTestGroupAssignmentRequest(uid string, postfix string) map[string]interface{} { + return map[string]interface{}{ + "groupId": "group_uid" + postfix, + "serviceTestId": "service_test_uid" + postfix, + } +} + // Converts a struct to a map while maintaining the json name as keys func StructToMap(obj interface{}) map[string]interface{} { data, _ := json.Marshal(obj) // Convert to a json string @@ -165,12 +193,13 @@ func MockOAuth() *gock.Response { } -func MockPostGroup(response map[string]interface{}, times int) { +func MockPostGroup(request map[string]interface{}, response map[string]interface{}, times int) { gock.New("https://test.api.capenetworks.com"). Post("/uxi/v1alpha1/groups"). MatchHeader("Content-Type", "application/json"). MatchHeader("Authorization", "mock_token"). Times(times). + JSON(request). Reply(200). JSON(response) } @@ -185,11 +214,12 @@ func MockGetGroup(uid string, response map[string]interface{}, times int) { JSON(response) } -func MockUpdateGroup(uid string, response map[string]interface{}, times int) { +func MockUpdateGroup(uid string, request map[string]interface{}, response map[string]interface{}, times int) { gock.New("https://test.api.capenetworks.com"). Patch("/uxi/v1alpha1/groups/"+uid). MatchHeader("Authorization", "mock_token"). Times(times). + JSON(request). Reply(200). JSON(response) } @@ -242,12 +272,13 @@ func MockGetSensorGroupAssignment(uid string, response map[string]interface{}, t JSON(response) } -func MockPostSensorGroupAssignment(uid string, response map[string]interface{}, times int) { +func MockPostSensorGroupAssignment(request map[string]interface{}, response map[string]interface{}, times int) { gock.New("https://test.api.capenetworks.com"). Post("/uxi/v1alpha1/sensor-group-assignments"). MatchHeader("Content-Type", "application/json"). MatchHeader("Authorization", "mock_token"). Times(times). + JSON(request). Reply(200). JSON(response) } @@ -270,12 +301,13 @@ func MockGetNetworkGroupAssignment(uid string, response map[string]interface{}, JSON(response) } -func MockPostNetworkGroupAssignment(uid string, response map[string]interface{}, times int) { +func MockPostNetworkGroupAssignment(request map[string]interface{}, response map[string]interface{}, times int) { gock.New("https://test.api.capenetworks.com"). Post("/uxi/v1alpha1/network-group-assignments"). MatchHeader("Content-Type", "application/json"). MatchHeader("Authorization", "mock_token"). Times(times). + JSON(request). Reply(200). JSON(response) } @@ -288,12 +320,13 @@ func MockDeleteNetworkGroupAssignment(uid string, times int) { Reply(204) } -func MockPostServiceTestGroupAssignment(uid string, response map[string]interface{}, times int) { +func MockPostServiceTestGroupAssignment(request map[string]interface{}, response map[string]interface{}, times int) { gock.New("https://test.api.capenetworks.com"). Post("/uxi/v1alpha1/service-test-group-assignments"). MatchHeader("Content-Type", "application/json"). MatchHeader("Authorization", "mock_token"). Times(times). + JSON(request). Reply(200). JSON(response) }