Skip to content

Commit

Permalink
combine k8s-policy endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam0Brien committed Nov 15, 2024
1 parent f146121 commit 320961f
Showing 1 changed file with 88 additions and 78 deletions.
166 changes: 88 additions & 78 deletions test/e2e/inventory_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]",
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: "[email protected]",
// 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: "[email protected]",
// 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: "[email protected]",
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: "[email protected]",
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: "[email protected]",
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
Expand Down

0 comments on commit 320961f

Please sign in to comment.