Skip to content

Commit

Permalink
feat(test): cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
paralta committed Aug 8, 2023
1 parent 1110b53 commit 70c4fca
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 139 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ api` to regenerate the model, client and server code.

### Testing End to End

`make integration-test` can be used run all the integration tests in the repo.

For details on how to test VMClarity end to end please see the End to End
testing guide [here](/docs/test_e2e.md).

Expand Down
21 changes: 18 additions & 3 deletions integration_test/abort_scan_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
// Copyright © 2023 Cisco Systems, Inc. and its affiliates.
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package integration_test

import (
Expand All @@ -18,7 +33,7 @@ var _ = Describe("Aborting a scan", func() {
apiScanConfig, err := client.PostScanConfig(ctx, helpers.GetDefaultScanConfig())
Expect(err).NotTo(HaveOccurred())

By("updating a scan configuration to run now")
By("updating scan configuration to run now")
updateScanConfig := helpers.UpdateScanConfigToStartNow(apiScanConfig)
err = client.PatchScanConfig(ctx, *apiScanConfig.Id, updateScanConfig)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -37,7 +52,7 @@ var _ = Describe("Aborting a scan", func() {
scans, err = client.GetScans(ctx, params)
Expect(err).NotTo(HaveOccurred())
return len(*scans.Items) == 1
}, time.Second*60, time.Second).Should(BeTrue())
}, helpers.DefaultTimeout, time.Second).Should(BeTrue())

By("aborting a scan")
err = client.PatchScan(ctx, *(*scans.Items)[0].Id, &models.Scan{
Expand All @@ -57,7 +72,7 @@ var _ = Describe("Aborting a scan", func() {
scans, err = client.GetScans(ctx, params)
Expect(err).NotTo(HaveOccurred())
return len(*scans.Items) == 1
}, time.Second*60, time.Second).Should(BeTrue())
}, helpers.DefaultTimeout, time.Second).Should(BeTrue())
})
})
})
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
// Copyright © 2023 Cisco Systems, Inc. and its affiliates.
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package integration_test

import (
Expand All @@ -14,23 +29,31 @@ var _ = 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")
assetsParams := models.GetAssetsParams{
Filter: utils.PointerTo("assetInfo.containerName eq '/alpine-test'"),
//TODO(paralta) Filter: utils.PointerTo("assetInfo/labels/any(l: l/Key eq 'scanconfig' and l/Value eq 'test')"),
Filter: utils.PointerTo(helpers.DefaultScope),
}
Eventually(func() bool {
assets, err := client.GetAssets(ctx, assetsParams)
Expect(err).NotTo(HaveOccurred())
return len(*assets.Items) == 1
}, time.Second*60, time.Second).Should(BeTrue())
}, helpers.DefaultTimeout, time.Second).Should(BeTrue())

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

By("updating a scan configuration to run now")
By("updating scan configuration to run now")
updateScanConfig := helpers.UpdateScanConfigToStartNow(apiScanConfig)
err = client.PatchScanConfig(ctx, *apiScanConfig.Id, updateScanConfig)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -49,7 +72,7 @@ var _ = Describe("Running a basic scan (only SBOM)", func() {
scans, err = client.GetScans(ctx, scanParams)
Expect(err).NotTo(HaveOccurred())
return len(*scans.Items) == 1
}, time.Second*60, time.Second).Should(BeTrue())
}, helpers.DefaultTimeout, time.Second).Should(BeTrue())

By("waiting until scan state changes to done")
scanParams = models.GetScansParams{
Expand Down
20 changes: 17 additions & 3 deletions integration_test/default_scan_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
// Copyright © 2023 Cisco Systems, Inc. and its affiliates.
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package integration_test

import (
Expand All @@ -15,7 +30,6 @@ var _ = Describe("Running a default scan (SBOM, vulnerabilities and exploits)",

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())
Expand All @@ -38,7 +52,7 @@ var _ = Describe("Running a default scan (SBOM, vulnerabilities and exploits)",
return err == nil
}, time.Second*600).Should(BeTrue())

By("updating a scan configuration to run now")
By("updating scan configuration to run now")
updateScanConfig := helpers.UpdateScanConfigToStartNow(apiScanConfig)
err = client.PatchScanConfig(ctx, *apiScanConfig.Id, updateScanConfig)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -57,7 +71,7 @@ var _ = Describe("Running a default scan (SBOM, vulnerabilities and exploits)",
scans, err = client.GetScans(ctx, scanParams)
Expect(err).NotTo(HaveOccurred())
return len(*scans.Items) == 1
}, time.Second*60, time.Second).Should(BeTrue())
}, helpers.DefaultTimeout, time.Second).Should(BeTrue())

By("waiting until scan state changes to done")
scanParams = models.GetScansParams{
Expand Down
48 changes: 25 additions & 23 deletions integration_test/fail_scan_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
// Copyright © 2023 Cisco Systems, Inc. and its affiliates.
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package integration_test

import (
Expand All @@ -18,12 +33,13 @@ var _ = Describe("Detecting scan failures", func() {
apiScanConfig, err := client.PostScanConfig(
ctx,
helpers.GetCustomScanConfig(
&helpers.DefaultScanFamiliesConfig,
"contains(assetInfo.tags, '{\"key\":\"notexisting\",\"value\":\"label\"}')",
1200,
600,
))
Expect(err).NotTo(HaveOccurred())

By("updating a scan configuration to run now")
By("updating scan configuration to run now")
updateScanConfig := helpers.UpdateScanConfigToStartNow(apiScanConfig)
err = client.PatchScanConfig(ctx, *apiScanConfig.Id, updateScanConfig)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -42,7 +58,7 @@ var _ = Describe("Detecting scan failures", func() {
scans, err = client.GetScans(ctx, params)
Expect(err).NotTo(HaveOccurred())
return len(*scans.Items) == 1
}, time.Second*60, time.Second).Should(BeTrue())
}, helpers.DefaultTimeout, time.Second).Should(BeTrue())
})
})

Expand All @@ -52,46 +68,32 @@ var _ = Describe("Detecting scan failures", func() {
apiScanConfig, err := client.PostScanConfig(
ctx,
helpers.GetCustomScanConfig(
"contains(assetInfo.labels, '{\"key\":\"scanconfig\",\"value\":\"test\"}')",
&helpers.DefaultScanFamiliesConfig,
helpers.DefaultScope,
2,
))
Expect(err).NotTo(HaveOccurred())

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

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'",
*apiScanConfig.Id,
models.ScanStateDone,
models.ScanStateFailed,
)),
}
var scans *models.Scans
Eventually(func() bool {
scans, err = client.GetScans(ctx, params)
Expect(err).NotTo(HaveOccurred())
return len(*scans.Items) == 1
}, time.Second*60, time.Second).Should(BeTrue())

By("waiting until scan state changes to failed with timed out as state reason")
params = models.GetScansParams{
params := models.GetScansParams{
Filter: utils.PointerTo(fmt.Sprintf(
"scanConfig/id eq '%s' and state eq '%s' and stateReason eq '%s'",
*apiScanConfig.Id,
models.ScanStateFailed,
models.ScanStateReasonTimedOut,
)),
}
var scans *models.Scans
Eventually(func() bool {
scans, err = client.GetScans(ctx, params)
Expect(err).NotTo(HaveOccurred())
return len(*scans.Items) == 1
}, time.Second*60, time.Second).Should(BeTrue())
}, helpers.DefaultTimeout, time.Second).Should(BeTrue())
})
})
})
36 changes: 18 additions & 18 deletions integration_test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.20.0 // indirect
github.com/aws/aws-sdk-go-v2/config v1.18.31 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.30 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.7 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.37 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.31 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.38 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.31 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.13.0 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.21.0 // indirect
github.com/aws/smithy-go v1.14.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.20.1 // indirect
github.com/aws/aws-sdk-go-v2/config v1.18.33 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.32 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.8 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.38 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.32 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.39 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.32 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.13.2 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.2 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.21.2 // indirect
github.com/aws/smithy-go v1.14.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/buger/goterm v1.0.4 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
Expand All @@ -49,7 +49,7 @@ require (
github.com/containerd/typeurl/v2 v2.1.0 // indirect
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deepmap/oapi-codegen v1.13.0 // indirect
github.com/deepmap/oapi-codegen v1.13.2 // indirect
github.com/distribution/distribution/v3 v3.0.0-20230327091844-0c958010ace2 // indirect
github.com/docker/buildx v0.10.4 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
Expand Down Expand Up @@ -162,27 +162,27 @@ require (
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.9.3 // indirect
golang.org/x/tools v0.11.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230706204954-ccb25ca9f130 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230720185612-659f7aaaa771 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230726155614-23370e0ffb3e // indirect
google.golang.org/grpc v1.57.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.26.3 // indirect
k8s.io/api v0.27.4 // indirect
k8s.io/apimachinery v0.27.4 // indirect
k8s.io/client-go v0.26.3 // indirect
k8s.io/client-go v0.27.4 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/utils v0.0.0-20230308161112-d77c459e9343 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
Expand Down
Loading

0 comments on commit 70c4fca

Please sign in to comment.