From 320961f8b46df2acbfdd625c44e2fec763e06c45 Mon Sep 17 00:00:00 2001 From: Adam0Brien Date: Fri, 15 Nov 2024 11:47:07 +0000 Subject: [PATCH] combine k8s-policy endpoints --- test/e2e/inventory_http_test.go | 166 +++++++++++++++++--------------- 1 file changed, 88 insertions(+), 78 deletions(-) diff --git a/test/e2e/inventory_http_test.go b/test/e2e/inventory_http_test.go index 314bee27..45fca87a 100644 --- a/test/e2e/inventory_http_test.go +++ b/test/e2e/inventory_http_test.go @@ -298,86 +298,96 @@ func TestInventoryAPIHTTP_K8SClusterLifecycle(t *testing.T) { _, err = client.K8sClusterService.UpdateK8SCluster(context.Background(), &updateRequest, opts...) assert.NoError(t, err) + + deleteRequest := resources.DeleteK8SClusterRequest{ + ReporterData: &resources.ReporterData{ + ReporterInstanceId: "user@example.com", + ReporterType: resources.ReporterData_ACM, + ConsoleHref: "www.example.com", + ApiHref: "www.example.com", + LocalResourceId: "01234", + ReporterVersion: "0.1", + }, + } + _, err = client.K8sClusterService.DeleteK8SCluster(context.Background(), &deleteRequest, opts...) + assert.NoError(t, err) } -// -//func TestInventoryAPIHTTP_K8SPolicy_CreateK8SPolicy(t *testing.T) { -// t.Parallel() -// c := v1beta1.NewConfig( -// v1beta1.WithHTTPUrl(inventoryapi_http_url), -// v1beta1.WithTLSInsecure(insecure), -// v1beta1.WithHTTPTLSConfig(tlsConfig), -// ) -// client, err := v1beta1.NewHttpClient(context.Background(), c) -// if err != nil { -// t.Error(err) -// } -// -// request := resources.CreateK8SPolicyRequest{ -// K8SPolicy: &resources.K8SPolicy{ -// Metadata: &resources.Metadata{ -// ResourceType: "k8s-policy", -// WorkspaceId: "workspace2", -// OrgId: "", -// }, -// ResourceData: &resources.K8SPolicyDetail{ -// Disabled: false, -// Severity: resources.K8SPolicyDetail_HIGH, -// }, -// ReporterData: &resources.ReporterData{ -// ReporterInstanceId: "user@example.com", -// ReporterType: resources.ReporterData_OCM, -// ConsoleHref: "www.example.com", -// ApiHref: "www.example.com", -// LocalResourceId: "012345", -// ReporterVersion: "0.1", -// }, -// }, -// } -// opts := getCallOptions() -// _, err = client.PolicyServiceClient.CreateK8SPolicy(context.Background(), &request, opts...) -// assert.NoError(t, err) -// -//} -// -//func TestInventoryAPIHTTP_K8SPolicy_UpdateK8SPolicy(t *testing.T) { -// t.Parallel() -// c := v1beta1.NewConfig( -// v1beta1.WithHTTPUrl(inventoryapi_http_url), -// v1beta1.WithTLSInsecure(insecure), -// v1beta1.WithHTTPTLSConfig(tlsConfig), -// ) -// client, err := v1beta1.NewHttpClient(context.Background(), c) -// if err != nil { -// t.Error(err) -// } -// -// request := resources.UpdateK8SPolicyRequest{ -// K8SPolicy: &resources.K8SPolicy{ -// Metadata: &resources.Metadata{ -// ResourceType: "k8s-policy", -// WorkspaceId: "workspace2", -// OrgId: "", -// }, -// ResourceData: &resources.K8SPolicyDetail{ -// Disabled: false, -// Severity: resources.K8SPolicyDetail_HIGH, -// }, -// ReporterData: &resources.ReporterData{ -// ReporterInstanceId: "user@example.com", -// ReporterType: resources.ReporterData_OCM, -// ConsoleHref: "www.example.com", -// ApiHref: "www.example.com", -// LocalResourceId: "012345", -// ReporterVersion: "0.1", -// }, -// }, -// } -// opts := getCallOptions() -// _, err = client.PolicyServiceClient.UpdateK8SPolicy(context.Background(), &request, opts...) -// assert.NoError(t, err) -// -//} +func TestInventoryAPIHTTP_K8SPolicyLifecycle(t *testing.T) { + t.Parallel() + c := v1beta1.NewConfig( + v1beta1.WithHTTPUrl(inventoryapi_http_url), + v1beta1.WithTLSInsecure(insecure), + v1beta1.WithHTTPTLSConfig(tlsConfig), + ) + client, err := v1beta1.NewHttpClient(context.Background(), c) + if err != nil { + t.Error(err) + } + + request := resources.CreateK8SPolicyRequest{ + K8SPolicy: &resources.K8SPolicy{ + Metadata: &resources.Metadata{ + ResourceType: "k8s-policy", + WorkspaceId: "workspace2", + OrgId: "", + }, + ResourceData: &resources.K8SPolicyDetail{ + Disabled: false, + Severity: resources.K8SPolicyDetail_HIGH, + }, + ReporterData: &resources.ReporterData{ + ReporterInstanceId: "user@example.com", + ReporterType: resources.ReporterData_OCM, + ConsoleHref: "www.example.com", + ApiHref: "www.example.com", + LocalResourceId: "012345", + ReporterVersion: "0.1", + }, + }, + } + opts := getCallOptions() + _, err = client.PolicyServiceClient.CreateK8SPolicy(context.Background(), &request, opts...) + assert.NoError(t, err) + + updateRequest := resources.UpdateK8SPolicyRequest{ + K8SPolicy: &resources.K8SPolicy{ + Metadata: &resources.Metadata{ + ResourceType: "k8s-policy", + WorkspaceId: "workspace2", + OrgId: "", + }, + ResourceData: &resources.K8SPolicyDetail{ + Disabled: true, + Severity: resources.K8SPolicyDetail_LOW, + }, + ReporterData: &resources.ReporterData{ + ReporterInstanceId: "user@example.com", + ReporterType: resources.ReporterData_OCM, + ConsoleHref: "www.example.com", + ApiHref: "www.example.com", + LocalResourceId: "012345", + ReporterVersion: "0.1", + }, + }, + } + + _, err = client.PolicyServiceClient.UpdateK8SPolicy(context.Background(), &updateRequest, opts...) + assert.NoError(t, err) + + deleteRequest := resources.DeleteK8SPolicyRequest{ + ReporterData: &resources.ReporterData{ + ReporterInstanceId: "user@example.com", + ReporterType: resources.ReporterData_OCM, + ConsoleHref: "www.example.com", + ApiHref: "www.example.com", + LocalResourceId: "012345", + ReporterVersion: "0.1", + }, + } + _, err = client.PolicyServiceClient.DeleteK8SPolicy(context.Background(), &deleteRequest, opts...) + assert.NoError(t, err) +} func getCallOptions() []http.CallOption { var opts []http.CallOption