Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
feat(test): code review
Browse files Browse the repository at this point in the history
  • Loading branch information
paralta committed Aug 11, 2023
1 parent d1cf12b commit 904fbb4
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 184 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ push-docker-uibackend: docker-uibackend ## Build and Push UI Backend Docker imag
test: ## Run Unit Tests
@go test ./...

.PHONY: end-to-end-test
end-to-end-test: ## Run go integration test against code
@cd end_to_end_test && \
.PHONY: e2e
e2e: ## Run go e2e test against code
@cd e2e && \
go test -v -failfast -test.v -test.paniconexit0 -timeout 2h -ginkgo.v .

.PHONY: clean-ui
Expand Down
45 changes: 22 additions & 23 deletions end_to_end_test/abort_scan_test.go → e2e/abort_scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,31 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package end_to_end_test
package e2e

import (
"fmt"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/openclarity/vmclarity/api/models"
"github.com/openclarity/vmclarity/end_to_end_test/helpers"
"github.com/openclarity/vmclarity/pkg/shared/utils"
"time"
)

var _ = Describe("Aborting a scan", func() {
var _ = ginkgo.Describe("Aborting a scan", func() {

Context("which is running", func() {
It("should stop successfully", func(ctx SpecContext) {
By("applying a scan configuration")
apiScanConfig, err := client.PostScanConfig(ctx, helpers.GetDefaultScanConfig())
Expect(err).NotTo(HaveOccurred())
ginkgo.Context("which is running", func() {
ginkgo.It("should stop successfully", func(ctx ginkgo.SpecContext) {
ginkgo.By("applying a scan configuration")
apiScanConfig, err := client.PostScanConfig(ctx, GetDefaultScanConfig())
gomega.Expect(err).NotTo(gomega.HaveOccurred())

By("updating scan configuration to run now")
updateScanConfig := helpers.UpdateScanConfigToStartNow(apiScanConfig)
ginkgo.By("updating scan configuration to run now")
updateScanConfig := UpdateScanConfigToStartNow(apiScanConfig)
err = client.PatchScanConfig(ctx, *apiScanConfig.Id, updateScanConfig)
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())

By("waiting until scan starts")
ginkgo.By("waiting until scan starts")
params := models.GetScansParams{
Filter: utils.PointerTo(fmt.Sprintf(
"scanConfig/id eq '%s' and state ne '%s' and state ne '%s'",
Expand All @@ -48,31 +47,31 @@ var _ = Describe("Aborting a scan", func() {
)),
}
var scans *models.Scans
Eventually(func() bool {
gomega.Eventually(func() bool {
scans, err = client.GetScans(ctx, params)
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())
return len(*scans.Items) == 1
}, helpers.DefaultTimeout, time.Second).Should(BeTrue())
}, DefaultTimeout, time.Second).Should(gomega.BeTrue())

By("aborting a scan")
ginkgo.By("aborting a scan")
err = client.PatchScan(ctx, *(*scans.Items)[0].Id, &models.Scan{
State: utils.PointerTo(models.ScanStateAborted),
})
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())

By("waiting until scan state changes to aborted")
ginkgo.By("waiting until scan state changes to aborted")
params = models.GetScansParams{
Filter: utils.PointerTo(fmt.Sprintf(
"scanConfig/id eq '%s' and state eq '%s'",
*apiScanConfig.Id,
models.ScanStateAborted,
)),
}
Eventually(func() bool {
gomega.Eventually(func() bool {
scans, err = client.GetScans(ctx, params)
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())
return len(*scans.Items) == 1
}, helpers.DefaultTimeout, time.Second).Should(BeTrue())
}, DefaultTimeout, time.Second).Should(gomega.BeTrue())
})
})
})
53 changes: 26 additions & 27 deletions end_to_end_test/basic_scan_test.go → e2e/basic_scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,51 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package end_to_end_test
package e2e

import (
"fmt"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/openclarity/vmclarity/api/models"
"github.com/openclarity/vmclarity/end_to_end_test/helpers"
"github.com/openclarity/vmclarity/pkg/shared/utils"
"time"
)

var _ = Describe("Running a basic scan (only SBOM)", func() {
var _ = ginkgo.Describe("Running a basic scan (only SBOM)", func() {

Context("which scans a docker container", func() {
It("should finish successfully", func(ctx SpecContext) {
By("waiting until test asset is found")
ginkgo.Context("which scans a docker container", func() {
ginkgo.It("should finish successfully", func(ctx ginkgo.SpecContext) {
ginkgo.By("waiting until test asset is found")
assetsParams := models.GetAssetsParams{
Filter: utils.PointerTo(fmt.Sprintf("terminatedOn eq null and %s", helpers.DefaultScope)),
Filter: utils.PointerTo(fmt.Sprintf("terminatedOn eq null and %s", DefaultScope)),
}
Eventually(func() bool {
gomega.Eventually(func() bool {
assets, err := client.GetAssets(ctx, assetsParams)
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())
return len(*assets.Items) == 1
}, helpers.DefaultTimeout, time.Second).Should(BeTrue())
}, DefaultTimeout, time.Second).Should(gomega.BeTrue())

By("applying a scan configuration")
ginkgo.By("applying a scan configuration")
apiScanConfig, err := client.PostScanConfig(
ctx,
helpers.GetCustomScanConfig(
GetCustomScanConfig(
&models.ScanFamiliesConfig{
Sbom: &models.SBOMConfig{
Enabled: utils.PointerTo(true),
},
},
helpers.DefaultScope,
DefaultScope,
600,
))
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())

By("updating scan configuration to run now")
updateScanConfig := helpers.UpdateScanConfigToStartNow(apiScanConfig)
ginkgo.By("updating scan configuration to run now")
updateScanConfig := UpdateScanConfigToStartNow(apiScanConfig)
err = client.PatchScanConfig(ctx, *apiScanConfig.Id, updateScanConfig)
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())

By("waiting until scan starts")
ginkgo.By("waiting until scan starts")
scanParams := models.GetScansParams{
Filter: utils.PointerTo(fmt.Sprintf(
"scanConfig/id eq '%s' and state ne '%s' and state ne '%s'",
Expand All @@ -68,25 +67,25 @@ var _ = Describe("Running a basic scan (only SBOM)", func() {
)),
}
var scans *models.Scans
Eventually(func() bool {
gomega.Eventually(func() bool {
scans, err = client.GetScans(ctx, scanParams)
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())
return len(*scans.Items) == 1
}, helpers.DefaultTimeout, time.Second).Should(BeTrue())
}, DefaultTimeout, time.Second).Should(gomega.BeTrue())

By("waiting until scan state changes to done")
ginkgo.By("waiting until scan state changes to done")
scanParams = models.GetScansParams{
Filter: utils.PointerTo(fmt.Sprintf(
"scanConfig/id eq '%s' and state eq '%s'",
*apiScanConfig.Id,
models.ScanStateDone,
)),
}
Eventually(func() bool {
gomega.Eventually(func() bool {
scans, err = client.GetScans(ctx, scanParams)
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())
return len(*scans.Items) == 1
}, time.Second*120, time.Second).Should(BeTrue())
}, time.Second*120, time.Second).Should(gomega.BeTrue())
})
})
})
41 changes: 20 additions & 21 deletions end_to_end_test/default_scan_test.go → e2e/default_scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,31 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package end_to_end_test
package e2e

import (
"fmt"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/openclarity/vmclarity/api/models"
"github.com/openclarity/vmclarity/end_to_end_test/helpers"
"github.com/openclarity/vmclarity/pkg/shared/utils"
"time"
)

var _ = Describe("Running a default scan (SBOM, vulnerabilities and exploits)", func() {
var _ = ginkgo.Describe("Running a default scan (SBOM, vulnerabilities and exploits)", func() {

Context("which scans a docker container", func() {
It("should finish successfully", func(ctx SpecContext) {
By("applying a scan configuration")
apiScanConfig, err := client.PostScanConfig(ctx, helpers.GetDefaultScanConfig())
Expect(err).NotTo(HaveOccurred())
ginkgo.Context("which scans a docker container", func() {
ginkgo.It("should finish successfully", func(ctx ginkgo.SpecContext) {
ginkgo.By("applying a scan configuration")
apiScanConfig, err := client.PostScanConfig(ctx, GetDefaultScanConfig())
gomega.Expect(err).NotTo(gomega.HaveOccurred())

By("updating scan configuration to run now")
updateScanConfig := helpers.UpdateScanConfigToStartNow(apiScanConfig)
ginkgo.By("updating scan configuration to run now")
updateScanConfig := UpdateScanConfigToStartNow(apiScanConfig)
err = client.PatchScanConfig(ctx, *apiScanConfig.Id, updateScanConfig)
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())

By("waiting until scan starts")
ginkgo.By("waiting until scan starts")
scanParams := models.GetScansParams{
Filter: utils.PointerTo(fmt.Sprintf(
"scanConfig/id eq '%s' and state ne '%s' and state ne '%s'",
Expand All @@ -48,25 +47,25 @@ var _ = Describe("Running a default scan (SBOM, vulnerabilities and exploits)",
)),
}
var scans *models.Scans
Eventually(func() bool {
gomega.Eventually(func() bool {
scans, err = client.GetScans(ctx, scanParams)
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())
return len(*scans.Items) == 1
}, helpers.DefaultTimeout, time.Second).Should(BeTrue())
}, DefaultTimeout, time.Second).Should(gomega.BeTrue())

By("waiting until scan state changes to done")
ginkgo.By("waiting until scan state changes to done")
scanParams = models.GetScansParams{
Filter: utils.PointerTo(fmt.Sprintf(
"scanConfig/id eq '%s' and state eq '%s'",
*apiScanConfig.Id,
models.ScanStateDone,
)),
}
Eventually(func() bool {
gomega.Eventually(func() bool {
scans, err = client.GetScans(ctx, scanParams)
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())
return len(*scans.Items) == 1
}, time.Second*120, time.Second).Should(BeTrue())
}, time.Second*120, time.Second).Should(gomega.BeTrue())
})
})
})
63 changes: 31 additions & 32 deletions end_to_end_test/fail_scan_test.go → e2e/fail_scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,37 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package end_to_end_test
package e2e

import (
"fmt"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/openclarity/vmclarity/api/models"
"github.com/openclarity/vmclarity/end_to_end_test/helpers"
"github.com/openclarity/vmclarity/pkg/shared/utils"
"time"
)

var _ = Describe("Detecting scan failures", func() {
var _ = ginkgo.Describe("Detecting scan failures", func() {

Context("when a scan stops without assets to scan", func() {
It("should detect failure reason successfully", func(ctx SpecContext) {
By("applying a scan configuration with not existing label")
ginkgo.Context("when a scan stops without assets to scan", func() {
ginkgo.It("should detect failure reason successfully", func(ctx ginkgo.SpecContext) {
ginkgo.By("applying a scan configuration with not existing label")
apiScanConfig, err := client.PostScanConfig(
ctx,
helpers.GetCustomScanConfig(
&helpers.DefaultScanFamiliesConfig,
GetCustomScanConfig(
&DefaultScanFamiliesConfig,
"contains(assetInfo.tags, '{\"key\":\"notexisting\",\"value\":\"label\"}')",
600,
))
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())

By("updating scan configuration to run now")
updateScanConfig := helpers.UpdateScanConfigToStartNow(apiScanConfig)
ginkgo.By("updating scan configuration to run now")
updateScanConfig := UpdateScanConfigToStartNow(apiScanConfig)
err = client.PatchScanConfig(ctx, *apiScanConfig.Id, updateScanConfig)
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())

By("waiting until scan state changes to failed with nothing to scan as state reason")
ginkgo.By("waiting until scan state changes to failed with nothing to scan as state reason")
params := models.GetScansParams{
Filter: utils.PointerTo(fmt.Sprintf(
"scanConfig/id eq '%s' and state eq '%s' and stateReason eq '%s'",
Expand All @@ -54,32 +53,32 @@ var _ = Describe("Detecting scan failures", func() {
)),
}
var scans *models.Scans
Eventually(func() bool {
gomega.Eventually(func() bool {
scans, err = client.GetScans(ctx, params)
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())
return len(*scans.Items) == 1
}, helpers.DefaultTimeout, time.Second).Should(BeTrue())
}, DefaultTimeout, time.Second).Should(gomega.BeTrue())
})
})

Context("when a scan stops with timeout", func() {
It("should detect failure reason successfully", func(ctx SpecContext) {
By("applying a scan configuration with short timeout")
ginkgo.Context("when a scan stops with timeout", func() {
ginkgo.It("should detect failure reason successfully", func(ctx ginkgo.SpecContext) {
ginkgo.By("applying a scan configuration with short timeout")
apiScanConfig, err := client.PostScanConfig(
ctx,
helpers.GetCustomScanConfig(
&helpers.DefaultScanFamiliesConfig,
helpers.DefaultScope,
GetCustomScanConfig(
&DefaultScanFamiliesConfig,
DefaultScope,
2,
))
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())

By("updating scan configuration to run now")
updateScanConfig := helpers.UpdateScanConfigToStartNow(apiScanConfig)
ginkgo.By("updating scan configuration to run now")
updateScanConfig := UpdateScanConfigToStartNow(apiScanConfig)
err = client.PatchScanConfig(ctx, *apiScanConfig.Id, updateScanConfig)
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())

By("waiting until scan state changes to failed with timed out as state reason")
ginkgo.By("waiting until scan state changes to failed with timed out as state reason")
params := models.GetScansParams{
Filter: utils.PointerTo(fmt.Sprintf(
"scanConfig/id eq '%s' and state eq '%s' and stateReason eq '%s'",
Expand All @@ -89,11 +88,11 @@ var _ = Describe("Detecting scan failures", func() {
)),
}
var scans *models.Scans
Eventually(func() bool {
gomega.Eventually(func() bool {
scans, err = client.GetScans(ctx, params)
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())
return len(*scans.Items) == 1
}, helpers.DefaultTimeout, time.Second).Should(BeTrue())
}, DefaultTimeout, time.Second).Should(gomega.BeTrue())
})
})
})
Loading

0 comments on commit 904fbb4

Please sign in to comment.