Skip to content

Commit

Permalink
feat: add functions to cleanup environment after test is completed
Browse files Browse the repository at this point in the history
Signed-off-by: Alessio Greggi <[email protected]>
  • Loading branch information
alegrey91 committed Jan 11, 2024
1 parent e7d7084 commit f79c4d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions e2e/e2e_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ func getCustomResourceData(k8sClient *kubernetes.Clientset, path string) ([]byte
DoRaw(context.TODO())
}

func deleteCustomResourceData(k8sClient *kubernetes.Clientset, path string) ([]byte, error) {
return k8sClient.RESTClient().
Delete().
AbsPath(path).
DoRaw(context.TODO())
}

func getCustomResource(k8sClient *kubernetes.Clientset, path string) ([]byte, error) {
data, err := getCustomResourceData(k8sClient, path)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions e2e/generate_filtered_sbom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var (
//go:embed testdata/nginx-sbomspdx-filtered.json
nginxSbomSpdxBytesFiltered []byte

expectedSbom string = "nginx-b49026"
expectedSbomFiltered string = "pod-nginx-nginx-1ba5-4aaf"
)

Expand Down Expand Up @@ -66,6 +67,14 @@ var _ = Describe("Generate filtered SBOM", func() {
JustAfterEach(func() {
err := deletePod(k8sClient, pod)
Expect(err).To(BeNil())

path := fmt.Sprintf("/apis/%s/namespaces/%s/sbomspdxv2p3s/%s", sbom.APIVersion, sbom.Namespace, expectedSbom)
_, err = deleteCustomResourceData(k8sClient, path)
Expect(err).To(BeNil())

path = fmt.Sprintf("/apis/%s/namespaces/%s/sbomspdxv2p3filtereds/%s", sbom.APIVersion, sbom.Namespace, expectedSbomFiltered)
_, err = deleteCustomResourceData(k8sClient, path)
Expect(err).To(BeNil())
})

It("should generate a SBOMSPDXv2p3Filtered resource within 2 minutes", func() {
Expand Down

0 comments on commit f79c4d7

Please sign in to comment.