Skip to content

Commit 6388348

Browse files
committed
WIP: KUTTL coverage
1 parent 46e246b commit 6388348

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

.github/workflows/test.yaml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
- run: gzip envtest.coverage
4141
- uses: actions/upload-artifact@v3
4242
with:
43-
name: "kubernetes-api=${{ matrix.kubernetes }}"
43+
name: "~coverage~kubernetes-api=${{ matrix.kubernetes }}"
4444
path: envtest.coverage.gz
4545
retention-days: 1
4646

@@ -74,7 +74,7 @@ jobs:
7474
- run: gzip envtest-existing.coverage
7575
- uses: actions/upload-artifact@v3
7676
with:
77-
name: "kubernetes-k3d=${{ matrix.kubernetes }}"
77+
name: "~coverage~kubernetes-k3d=${{ matrix.kubernetes }}"
7878
path: envtest-existing.coverage.gz
7979
retention-days: 1
8080

@@ -102,9 +102,11 @@ jobs:
102102
registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi8-14.4-3.1-0
103103
104104
- run: go mod download
105-
- name: Build PGO
105+
- name: Build coverage executable
106106
run: |
107-
make build-postgres-operator PGO_VERSION=${{ github.sha }}
107+
make build-postgres-operator \
108+
GO_BUILD='go test -c --tags main-with-coverage --trimpath --coverpkg ./internal/...' \
109+
PGO_VERSION='${{ github.sha }}-coverage'
108110
109111
# Start a Docker container with the working directory mounted.
110112
- name: Start PGO
@@ -122,7 +124,7 @@ jobs:
122124
--env 'RELATED_IMAGE_POSTGRES_14=registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi8-14.4-0' \
123125
--env 'RELATED_IMAGE_POSTGRES_14_GIS_3.1=registry.developers.crunchydata.com/crunchydata/crunchy-postgres-gis:ubi8-14.4-3.1-0' \
124126
--name 'postgres-operator' ubuntu \
125-
postgres-operator
127+
postgres-operator --test.coverprofile 'kuttl.coverage'
126128
127129
- run: make tools/kuttl
128130
- run: make generate-kuttl
@@ -138,12 +140,24 @@ jobs:
138140
env:
139141
KUTTL_TEST: hack/tools/kuttl test --test cluster-start --timeout=180 --parallel=1
140142
143+
- name: Stop PGO
144+
run: docker stop 'postgres-operator' || true
145+
146+
# Upload coverage to GitHub
147+
- run: gzip kuttl.coverage
148+
- uses: actions/upload-artifact@v3
149+
with:
150+
name: "~coverage~kuttl-k3d=${{ matrix.kubernetes }}"
151+
path: kuttl.coverage.gz
152+
retention-days: 1
153+
141154
coverage-report:
142155
if: ${{ success() || contains(needs.*.result, 'success') }}
143156
runs-on: ubuntu-latest
144157
needs:
145158
- kubernetes-api
146159
- kubernetes-k3d
160+
- kuttl-k3d
147161
steps:
148162
- uses: actions/checkout@v3
149163
- uses: actions/setup-go@v3
@@ -174,6 +188,6 @@ jobs:
174188
- run: gzip total-coverage.html
175189
- uses: actions/upload-artifact@v3
176190
with:
177-
name: coverage-report
191+
name: coverage-report=html
178192
path: total-coverage.html.gz
179193
retention-days: 15
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//go:build main-with-coverage
2+
// +build main-with-coverage
3+
4+
/*
5+
Copyright 2022 Crunchy Data Solutions, Inc.
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package main
20+
21+
import "testing"
22+
23+
// TestWithCoverage is a simple way to run the entire application when built by
24+
// "go test -c" with code coverage enabled. This file has a build constraint,
25+
// and should *not* be run with regular "go test".
26+
//
27+
// - https://www.elastic.co/blog/code-coverage-for-your-golang-system-tests
28+
//
29+
func TestWithCoverage(t *testing.T) { main() }

0 commit comments

Comments
 (0)