Run tests with coverage on CI (#2141)

Combine 'make cover' and 'make acc-cover' into single command. They
still write coverage into different files -- it would be useful to see
separate coverage numbers.

Note, we're not making use of coverage information yet. However, running
tests in CI with coverage will
- let us catch issues that only manifest when coverage is enabled, like
https://github.com/databricks/cli/pull/2150
- will let us know if there are any issues with running coverage on CI
before investing in additional coverage support
This commit is contained in:
Denis Bilenko 2025-01-20 16:41:24 +01:00 committed by GitHub
parent e6982d09ac
commit 395a04a8d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 10 deletions

View File

@ -77,8 +77,8 @@ jobs:
make vendor make vendor
pip3 install wheel pip3 install wheel
- name: Run tests - name: Run tests with coverage
run: make test run: make cover
golangci: golangci:
needs: cleanups needs: cleanups

View File

@ -3,6 +3,8 @@ default: vendor fmt lint
PACKAGES=./acceptance/... ./libs/... ./internal/... ./cmd/... ./bundle/... . PACKAGES=./acceptance/... ./libs/... ./internal/... ./cmd/... ./bundle/... .
GOTESTSUM_FORMAT ?= pkgname-and-test-fails GOTESTSUM_FORMAT ?= pkgname-and-test-fails
GOTESTSUM_CMD ?= gotestsum --format ${GOTESTSUM_FORMAT} --no-summary=skipped
lint: lint:
golangci-lint run --fix golangci-lint run --fix
@ -18,22 +20,19 @@ fmt:
golangci-lint run --enable-only="gofmt,gofumpt,goimports" --fix ./... golangci-lint run --enable-only="gofmt,gofumpt,goimports" --fix ./...
test: test:
gotestsum --format ${GOTESTSUM_FORMAT} --no-summary=skipped -- ${PACKAGES} ${GOTESTSUM_CMD} -- ${PACKAGES}
cover: cover:
gotestsum --format ${GOTESTSUM_FORMAT} --no-summary=skipped -- -coverprofile=coverage.txt ${PACKAGES}
showcover:
go tool cover -html=coverage.txt
acc-cover:
rm -fr ./acceptance/build/cover/ rm -fr ./acceptance/build/cover/
CLI_GOCOVERDIR=build/cover go test ./acceptance CLI_GOCOVERDIR=build/cover ${GOTESTSUM_CMD} -- -coverprofile=coverage.txt ${PACKAGES}
rm -fr ./acceptance/build/cover-merged/ rm -fr ./acceptance/build/cover-merged/
mkdir -p acceptance/build/cover-merged/ mkdir -p acceptance/build/cover-merged/
go tool covdata merge -i $$(printf '%s,' acceptance/build/cover/* | sed 's/,$$//') -o acceptance/build/cover-merged/ go tool covdata merge -i $$(printf '%s,' acceptance/build/cover/* | sed 's/,$$//') -o acceptance/build/cover-merged/
go tool covdata textfmt -i acceptance/build/cover-merged -o coverage-acceptance.txt go tool covdata textfmt -i acceptance/build/cover-merged -o coverage-acceptance.txt
showcover:
go tool cover -html=coverage.txt
acc-showcover: acc-showcover:
go tool cover -html=coverage-acceptance.txt go tool cover -html=coverage-acceptance.txt