Skip to content

Commit 038ebaa

Browse files
committed
#150 Added a go tag to seperate between slow tests and fast tests
fast tests can be called by "make test-fast" and all tests will run when command "make test" is used. This is done to keep the CI workflow as usual Signed-off-by: Ilyes Ben Dlala <ilyes.bendlala@iteratec.com>
1 parent 333fa67 commit 038ebaa

File tree

5 files changed

+56
-22
lines changed

5 files changed

+56
-22
lines changed

operator/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ vet: ## Run go vet against code.
7777

7878
.PHONY: test
7979
test: manifests generate fmt vet envtest ## Run tests.
80-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
80+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -tags="fast slow" ./... -coverprofile cover.out
81+
82+
.PHONY: test-fast
83+
test-fast: manifests generate fmt vet envtest ## Run tests.
84+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -tags="fast" ./... -coverprofile cover.out
8185

8286
.PHONY: view-coverage
8387
view-coverage:

operator/controllers/execution/scantype_controller_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
//
33
// SPDX-License-Identifier: Apache-2.0
44

5+
//go:build fast
6+
// +build fast
7+
58
package controllers
69

710
import (
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// SPDX-FileCopyrightText: the secureCodeBox authors
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
//go:build slow
6+
// +build slow
7+
8+
package controllers
9+
10+
import (
11+
"context"
12+
"time"
13+
14+
. "github.com/onsi/ginkgo"
15+
. "github.com/onsi/gomega"
16+
executionv1 "github.com/secureCodeBox/secureCodeBox/operator/apis/execution/v1"
17+
"sigs.k8s.io/controller-runtime/pkg/client"
18+
//+kubebuilder:scaffold:imports
19+
)
20+
21+
var _ = Describe("ScheduledScan controller", func() {
22+
Context("A Scan is triggred due to a Scheduled Scan with Schedule in Spec", func() {
23+
It("The ScheduledScan's should be triggered according to the Schedule", func() {
24+
ctx := context.Background()
25+
namespace := "scantype-multiple-scheduled-scan-triggerd-test-schedule"
26+
27+
createNamespace(ctx, namespace)
28+
createScanType(ctx, namespace)
29+
scheduledScan := createScheduledScanWithSchedule(ctx, namespace, true)
30+
31+
var scanlist executionv1.ScanList
32+
33+
// ensure that the ScheduledScan has been triggered
34+
waitForScheduledScanToBeTriggered(ctx, namespace, 90*time.Second)
35+
k8sClient.List(ctx, &scanlist, client.InNamespace(namespace))
36+
37+
Expect(scheduledScan.Spec.Schedule).Should(Equal("*/1 * * * *"))
38+
Expect(scanlist.Items).Should(HaveLen(1))
39+
})
40+
})
41+
})

operator/controllers/execution/scheduledscan_controller_test.go

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
// SPDX-FileCopyrightText: the secureCodeBox authors
22
//
33
// SPDX-License-Identifier: Apache-2.0
4+
5+
//go:build fast
6+
// +build fast
7+
48
package controllers
59

610
import (
711
"context"
8-
"time"
912

1013
. "github.com/onsi/ginkgo"
1114
. "github.com/onsi/gomega"
@@ -105,24 +108,4 @@ var _ = Describe("ScheduledScan controller", func() {
105108
Expect(scheduledScan.Status.Findings.FindingCategories).Should(Equal(map[string]uint64{"Open Port": 42}))
106109
})
107110
})
108-
109-
Context("A Scan is triggred due to a Scheduled Scan with Schedule in Spec", func() {
110-
It("The ScheduledScan's should be triggered according to the Schedule", func() {
111-
ctx := context.Background()
112-
namespace := "scantype-multiple-scheduled-scan-triggerd-test-schedule"
113-
114-
createNamespace(ctx, namespace)
115-
createScanType(ctx, namespace)
116-
scheduledScan := createScheduledScanWithSchedule(ctx, namespace, true)
117-
118-
var scanlist executionv1.ScanList
119-
120-
// ensure that the ScheduledScan has been triggered
121-
waitForScheduledScanToBeTriggered(ctx, namespace, 90*time.Second)
122-
k8sClient.List(ctx, &scanlist, client.InNamespace(namespace))
123-
124-
Expect(scheduledScan.Spec.Schedule).Should(Equal("*/1 * * * *"))
125-
Expect(scanlist.Items).Should(HaveLen(1))
126-
})
127-
})
128111
})

operator/controllers/execution/test_utils_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
//
33
// SPDX-License-Identifier: Apache-2.0
44

5+
//go:build fast
6+
// +build fast
7+
58
package controllers
69

710
import (

0 commit comments

Comments
 (0)