Skip to content

Commit db0c8dd

Browse files
JustinKuliopenshift-ci[bot]
authored andcommitted
Run PolicyAutomation tests separately in CI
The PolicyAutomation tests were taking about half of the total e2e test duration. This excludes those tests from the usual `make e2e-test` target, which will accelerate both the CI and local development. Those tests are now run in a separate (concurrent) GH job in the CI workflow, and the test coverage information is merged in another new job. This also combines the unit tests and linting tasks into one job, which means that a linting or formatting error will not prevent the e2e tests from running. Refs: - https://issues.redhat.com/browse/ACM-8239 Signed-off-by: Justin Kulikauskas <[email protected]>
1 parent 00a960f commit db0c8dd

File tree

3 files changed

+161
-36
lines changed

3 files changed

+161
-36
lines changed

.github/workflows/kind.yml

Lines changed: 133 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,15 @@ defaults:
1616
working-directory: governance-policy-propagator
1717

1818
jobs:
19-
kind-tests:
19+
unit-tests:
2020
runs-on: ubuntu-latest
21-
env:
22-
REGISTRY: localhost:5000
23-
strategy:
24-
fail-fast: false
25-
matrix:
26-
# Run tests on minimum and newest supported OCP Kubernetes
27-
# The "minimum" tag is set in the Makefile
28-
# KinD tags: https://hub.docker.com/r/kindest/node/tags
29-
kind:
30-
- 'minimum'
31-
- 'latest'
32-
name: KinD tests
21+
name: Unit Tests
3322
steps:
3423
- name: Checkout Governance Policy Propagator
3524
uses: actions/checkout@v3
3625
with:
3726
path: governance-policy-propagator
38-
fetch-depth: 0 # Fetch all history for all tags and branches
39-
27+
4028
- name: Set up Go
4129
uses: actions/setup-go@v3
4230
id: go
@@ -62,6 +50,38 @@ jobs:
6250
run: |
6351
make test
6452
53+
- name: Unit Test Coverage
54+
if: ${{ github.event_name == 'pull_request' }}
55+
run: |
56+
make test-coverage
57+
58+
- name: Upload Unit Test Coverage
59+
if: ${{ github.event_name == 'pull_request' }}
60+
uses: actions/upload-artifact@v3
61+
with:
62+
name: coverage_unit
63+
path: governance-policy-propagator/coverage_unit.out
64+
65+
kind-tests:
66+
runs-on: ubuntu-latest
67+
env:
68+
REGISTRY: localhost:5000
69+
strategy:
70+
fail-fast: false
71+
matrix:
72+
# Run tests on minimum and newest supported OCP Kubernetes
73+
# The "minimum" tag is set in the Makefile
74+
# KinD tags: https://hub.docker.com/r/kindest/node/tags
75+
kind:
76+
- 'minimum'
77+
- 'latest'
78+
name: KinD tests
79+
steps:
80+
- name: Checkout Governance Policy Propagator
81+
uses: actions/checkout@v3
82+
with:
83+
path: governance-policy-propagator
84+
6585
- name: Create K8s KinD Cluster - ${{ matrix.kind }}
6686
env:
6787
KIND_VERSION: ${{ matrix.kind }}
@@ -73,16 +93,24 @@ jobs:
7393
export GOPATH=$(go env GOPATH)
7494
make e2e-test-coverage
7595
96+
- name: Upload E2E Test Coverage
97+
if: ${{ github.event_name == 'pull_request' && matrix.kind == 'latest'}}
98+
uses: actions/upload-artifact@v3
99+
with:
100+
name: coverage_e2e
101+
path: governance-policy-propagator/coverage_e2e.out
102+
76103
- name: E2E Tests for Compliance Events API
77104
run: |
78105
make postgres
79106
make e2e-test-coverage-compliance-events-api
80107
81-
- name: Test Coverage Verification
82-
if: ${{ github.event_name == 'pull_request' }}
83-
run: |
84-
make test-coverage
85-
make coverage-verify
108+
- name: Upload Compliance Events API Test Coverage
109+
if: ${{ github.event_name == 'pull_request' && matrix.kind == 'latest'}}
110+
uses: actions/upload-artifact@v3
111+
with:
112+
name: coverage_e2e_compliance_events_api
113+
path: governance-policy-propagator/coverage_e2e_compliance_events_api.out
86114

87115
- name: Verify Deployment Configuration
88116
run: |
@@ -103,4 +131,88 @@ jobs:
103131
if: ${{ always() }}
104132
run: |
105133
make kind-delete-cluster
106-
134+
135+
policyautomation-tests:
136+
runs-on: ubuntu-latest
137+
env:
138+
REGISTRY: localhost:5000
139+
strategy:
140+
fail-fast: false
141+
matrix:
142+
# Run tests on minimum and newest supported OCP Kubernetes
143+
# The "minimum" tag is set in the Makefile
144+
# KinD tags: https://hub.docker.com/r/kindest/node/tags
145+
kind:
146+
- 'minimum'
147+
- 'latest'
148+
name: PolicyAutomation tests
149+
steps:
150+
- name: Checkout Governance Policy Propagator
151+
uses: actions/checkout@v3
152+
with:
153+
path: governance-policy-propagator
154+
155+
- name: Create K8s KinD Cluster - ${{ matrix.kind }}
156+
env:
157+
KIND_VERSION: ${{ matrix.kind }}
158+
run: |
159+
make kind-bootstrap-cluster-dev
160+
161+
- name: PolicyAutomation E2E Tests
162+
run: |
163+
export GOPATH=$(go env GOPATH)
164+
make e2e-test-coverage-policyautomation
165+
166+
- name: Upload PolicyAutomation Test Coverage
167+
if: ${{ github.event_name == 'pull_request' && matrix.kind == 'latest'}}
168+
uses: actions/upload-artifact@v3
169+
with:
170+
name: coverage_e2e_policyautomation
171+
path: governance-policy-propagator/coverage_e2e_policyautomation.out
172+
173+
- name: Debug
174+
if: ${{ failure() }}
175+
run: |
176+
make e2e-debug
177+
178+
- name: Clean up cluster
179+
if: ${{ always() }}
180+
run: |
181+
make kind-delete-cluster
182+
183+
coveage-verification:
184+
defaults:
185+
run:
186+
working-directory: '.'
187+
runs-on: ubuntu-latest
188+
name: Test Coverage Verification
189+
if: ${{ github.event_name == 'pull_request' }}
190+
needs: [unit-tests, kind-tests, policyautomation-tests]
191+
192+
steps:
193+
- name: Checkout Governance Policy Propagator
194+
uses: actions/checkout@v3
195+
196+
- name: Download Unit Coverage Result
197+
uses: actions/download-artifact@v3
198+
with:
199+
name: coverage_unit
200+
201+
- name: Download E2E Coverage Result
202+
uses: actions/download-artifact@v3
203+
with:
204+
name: coverage_e2e
205+
206+
- name: Download Compliance Events Coverage Result
207+
uses: actions/download-artifact@v3
208+
with:
209+
name: coverage_e2e_compliance_events_api
210+
211+
- name: Download PolicyAutomation Coverage Result
212+
uses: actions/download-artifact@v3
213+
with:
214+
name: coverage_e2e_policyautomation
215+
216+
- name: Test Coverage Verification
217+
run: |
218+
make coverage-verify

Makefile

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -314,36 +314,49 @@ install-resources:
314314
e2e-dependencies:
315315
$(call go-get-tool,github.com/onsi/ginkgo/v2/ginkgo@$(shell awk '/github.com\/onsi\/ginkgo\/v2/ {print $$2}' go.mod))
316316

317+
E2E_LABEL_FILTER = --label-filter="!webhook && !compliance-events-api && !policyautomation"
317318
.PHONY: e2e-test
318319
e2e-test: e2e-dependencies
319-
$(GINKGO) -v --fail-fast $(E2E_TEST_ARGS) --label-filter="!webhook && !compliance-events-api" test/e2e
320+
$(GINKGO) -v --fail-fast $(E2E_TEST_ARGS) $(E2E_LABEL_FILTER) test/e2e
320321

321-
.PHONY: e2e-test-coverage
322-
e2e-test-coverage: E2E_TEST_ARGS = --json-report=report_e2e.json --output-dir=.
323-
e2e-test-coverage: e2e-run-instrumented e2e-test e2e-stop-instrumented
322+
.PHONY: e2e-test-webhook
323+
e2e-test-webhook: E2E_LABEL_FILTER = --label-filter="webhook"
324+
e2e-test-webhook: e2e-test
325+
326+
.PHONY: e2e-test-compliance-events-api
327+
e2e-test-compliance-events-api: E2E_LABEL_FILTER = --label-filter="compliance-events-api"
328+
e2e-test-compliance-events-api: e2e-test
329+
330+
.PHONY: e2e-test-coverage-compliance-events-api
331+
e2e-test-coverage-compliance-events-api: E2E_TEST_ARGS = --json-report=report_e2e_compliance_events_api.json --covermode=atomic --coverpkg=open-cluster-management.io/governance-policy-propagator/controllers/complianceeventsapi --coverprofile=coverage_e2e_compliance_events_api.out --output-dir=.
332+
e2e-test-coverage-compliance-events-api: e2e-test-compliance-events-api
333+
334+
.PHONY: e2e-test-policyautomation
335+
e2e-test-policyautomation: E2E_LABEL_FILTER = --label-filter="policyautomation"
336+
e2e-test-policyautomation: e2e-test
324337

325338
.PHONY: e2e-build-instrumented
326339
e2e-build-instrumented:
327340
go test -covermode=atomic -coverpkg=$(shell cat go.mod | head -1 | cut -d ' ' -f 2)/... -c -tags e2e ./ -o build/_output/bin/$(IMG)-instrumented
328341

342+
TEST_COVERAGE_OUT = coverage_e2e.out
329343
.PHONY: e2e-run-instrumented
330344
e2e-run-instrumented: e2e-build-instrumented
331-
WATCH_NAMESPACE="$(WATCH_NAMESPACE)" ./build/_output/bin/$(IMG)-instrumented -test.run "^TestRunMain$$" -test.coverprofile=coverage_e2e.out &>build/_output/controller.log &
345+
WATCH_NAMESPACE="$(WATCH_NAMESPACE)" ./build/_output/bin/$(IMG)-instrumented -test.run "^TestRunMain$$" -test.coverprofile=$(TEST_COVERAGE_OUT) &>build/_output/controller.log &
332346

333347
.PHONY: e2e-stop-instrumented
334348
e2e-stop-instrumented:
335349
ps -ef | grep '$(IMG)' | grep -v grep | awk '{print $$2}' | xargs kill
336350

337-
e2e-test-webhook:
338-
$(GINKGO) -v --fail-fast --label-filter="webhook" test/e2e
339-
340-
.PHONY: e2e-test-compliance-events-api
341-
e2e-test-compliance-events-api:
342-
$(GINKGO) -v --fail-fast $(E2E_TEST_ARGS) --label-filter="compliance-events-api" test/e2e
351+
.PHONY: e2e-test-coverage
352+
e2e-test-coverage: E2E_TEST_ARGS = --json-report=report_e2e.json --output-dir=.
353+
e2e-test-coverage: e2e-run-instrumented e2e-test e2e-stop-instrumented
343354

344-
.PHONY: e2e-test-coverage-compliance-events-api
345-
e2e-test-coverage-compliance-events-api: E2E_TEST_ARGS = --json-report=report_e2e_compliance_events_api.json --covermode=atomic --coverpkg=open-cluster-management.io/governance-policy-propagator/controllers/complianceeventsapi --coverprofile=coverage_e2e_compliance_events_api.out --output-dir=.
346-
e2e-test-coverage-compliance-events-api: e2e-test-compliance-events-api
355+
.PHONY: e2e-test-coverage-policyautomation
356+
e2e-test-coverage-policyautomation: E2E_TEST_ARGS = --json-report=report_e2e_policyautomation.json --output-dir=.
357+
e2e-test-coverage-policyautomation: E2E_LABEL_FILTER = --label-filter="policyautomation"
358+
e2e-test-coverage-policyautomation: TEST_COVERAGE_OUT = coverage_e2e_policyautomation.out
359+
e2e-test-coverage-policyautomation: e2e-test-coverage
347360

348361
.PHONY: e2e-debug
349362
e2e-debug:

test/e2e/case5_policy_automation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const (
2727

2828
const automationName string = "create-service.now-ticket"
2929

30-
var _ = Describe("Test policy automation", Ordered, func() {
30+
var _ = Describe("Test policy automation", Label("policyautomation"), Ordered, func() {
3131
ansiblelistlen := 0
3232
// Use this only when target_clusters managed1 managed2 managed3
3333
getLastAnsiblejob := func() *unstructured.Unstructured {

0 commit comments

Comments
 (0)