Skip to content

Commit 582c191

Browse files
committed
test: separate tests from coverage
Signed-off-by: Daniel Vérité <[email protected]>
1 parent 45126ca commit 582c191

File tree

2 files changed

+81
-24
lines changed

2 files changed

+81
-24
lines changed

.github/workflows/test.yaml

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,7 @@ jobs:
2727
run: make build
2828
- name: Run Go tests
2929
run: make test
30-
- name: Code Coverage Report
31-
uses: irongut/[email protected]
32-
with:
33-
filename: coverage.xml
34-
badge: true
35-
fail_below_min: false
36-
format: markdown
37-
hide_branch_rate: false
38-
hide_complexity: true
39-
indicators: true
40-
output: both
41-
thresholds: '60 80'
42-
- uses: jwalton/gh-find-current-pr@v1
43-
id: finder
44-
- name: Add Coverage PR Comment
45-
uses: marocchino/sticky-pull-request-comment@v2
46-
with:
47-
number: ${{ steps.finder.outputs.pr }}
48-
path: code-coverage-results.md
49-
recreate: true
30+
5031
- name: Upload artifact
5132
uses: actions/upload-artifact@v4
5233
with:
@@ -156,6 +137,72 @@ jobs:
156137
- name: Run Debian package tests
157138
run: make debian-test-ci
158139

140+
coverage:
141+
name: Test Coverage
142+
needs: go
143+
runs-on: ubuntu-latest
144+
env:
145+
BATS_LIB_PATH: "${{ github.workspace }}/test/bats/lib/"
146+
PGHOST: localhost
147+
PGUSER: postgres
148+
PGPASSWORD: hackme
149+
PGDATABASE: unittest
150+
services:
151+
postgres:
152+
image: postgres:14
153+
options: >-
154+
--health-cmd pg_isready
155+
--health-interval 10s
156+
--health-timeout 5s
157+
--health-retries 5
158+
--hostname postgres
159+
env:
160+
POSTGRES_PASSWORD: hackme
161+
ports:
162+
- 5432:5432
163+
steps:
164+
- uses: actions/checkout@v4
165+
- uses: actions/setup-go@v5
166+
with:
167+
go-version: '1.21'
168+
- name: Install dependencies
169+
run: |
170+
go get .
171+
- name: Build
172+
run: make build
173+
174+
- name: Setup Bats and bats libs
175+
uses: bats-core/[email protected]
176+
with:
177+
support-path: ${{ github.workspace }}/test/bats/lib/bats-support
178+
assert-path: ${{ github.workspace }}/test/bats/lib/bats-assert
179+
file-install: false # Unused
180+
detik-install: false # Unused
181+
182+
- name: Run Go and e2e tests
183+
run: make coverage
184+
185+
- name: Code Coverage Report
186+
uses: irongut/[email protected]
187+
with:
188+
filename: coverage.xml
189+
badge: true
190+
fail_below_min: false
191+
format: markdown
192+
hide_branch_rate: false
193+
hide_complexity: true
194+
indicators: true
195+
output: both
196+
thresholds: '60 80'
197+
- uses: jwalton/gh-find-current-pr@v1
198+
id: finder
199+
- name: Add Coverage PR Comment
200+
uses: marocchino/sticky-pull-request-comment@v2
201+
with:
202+
number: ${{ steps.finder.outputs.pr }}
203+
path: code-coverage-results.md
204+
recreate: true
205+
159206
# checkcov:
160207
# permissions:
161208
# security-events: write # for github/codeql-action/upload-sarif to upload SARIF results

Makefile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ format:
1919
build:
2020
CGO_ENABLED=0 go build -v -ldflags="-X '$(BUILD_INFO_PACKAGE_PATH).Version=development' -X '$(BUILD_INFO_PACKAGE_PATH).CommitSHA=$(GIT_COMMIT_SHA)' -X '$(BUILD_INFO_PACKAGE_PATH).Date=$(BUILD_DATE)'" -o $(BINARY)
2121

22+
coverage: $(COVER_BINARY) test
23+
test -d ./coverage-data || mkdir ./coverage-data
24+
rm -f ./coverage-data/cov*
25+
# run e2e test collecting coverage data
26+
cd scripts/bats && GOCOVERDIR=$(PWD)/coverage-data bats *.bats
27+
# merge go-test and e2e-tests collected data
28+
go tool covdata textfmt -i=./coverage-data -o coverage.txt
29+
go run github.com/boumenot/gocover-cobertura@latest < coverage.txt > coverage.xml
30+
go tool cover -html coverage.txt -o cover.html
31+
32+
2233
# build for coverage
2334
$(COVER_BINARY): build
2435
CGO_ENABLED=0 go build -cover -v -ldflags="-X '$(BUILD_INFO_PACKAGE_PATH).Version=development' -X '$(BUILD_INFO_PACKAGE_PATH).CommitSHA=$(GIT_COMMIT_SHA)' -X '$(BUILD_INFO_PACKAGE_PATH).Date=$(BUILD_DATE)'" -o $(COVER_BINARY)
@@ -31,7 +42,8 @@ run:
3142
install: build
3243
GOBIN=/usr/local/bin/ go install -v -ldflags="-X '$(BUILD_INFO_PACKAGE_PATH).Version=development' -X '$(BUILD_INFO_PACKAGE_PATH).CommitSHA=$(GIT_COMMIT_SHA)' -X '$(BUILD_INFO_PACKAGE_PATH).Date=$(BUILD_DATE)'"
3344

34-
bats-test: $(COVER_BINARY)
45+
.PHONY: bats-test
46+
bats-test: build $(COVER_BINARY)
3547
test -d ./coverage-data || mkdir ./coverage-data
3648
cd scripts/bats && GOCOVERDIR=$(PWD)/coverage-data bats *.bats
3749

@@ -66,10 +78,8 @@ checkcov:
6678
.PHONY: test
6779
test:
6880
test -d ./coverage-data || mkdir ./coverage-data
81+
rm -f ./coverage-data/cov*
6982
go test -v ./... -cover -test.gocoverdir=$(PWD)/coverage-data -covermode set
70-
go tool covdata textfmt -i=./coverage-data -o coverage.txt
71-
go run github.com/boumenot/gocover-cobertura@latest < coverage.txt > coverage.xml
72-
go tool cover -html coverage.txt -o cover.html
7383

7484
.PHONY: lint
7585
lint:

0 commit comments

Comments
 (0)