Skip to content

Commit

Permalink
Merge pull request #44 from adrianreber/2023-04-14-coverage
Browse files Browse the repository at this point in the history
Use golang 1.20 for binary test code coverage
  • Loading branch information
adrianreber authored Apr 14, 2023
2 parents 586a9f1 + 6517f80 commit 86e9400
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 64 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: checkout
uses: actions/checkout@v3
with:
# needed for codecov
fetch-depth: 0
- name: Install tools
run: sudo apt-get install -qqy bats
- name: Run make coverage
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
checkpointctl
checkpointctl.coverage
.coverage
38 changes: 28 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,33 @@ VERSION := $(VERSION_MAJOR)$(if $(VERSION_MINOR),.$(VERSION_MINOR))$(if $(VERSIO

COVERAGE_PATH ?= $(shell pwd)/.coverage

GO_MAJOR_VER = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
GO_MINOR_VER = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
MIN_GO_MAJOR_VER = 1
MIN_GO_MINOR_VER = 20
GO_VALIDATION_ERR = Go version is not supported. Please update to at least $(MIN_GO_MAJOR_VER).$(MIN_GO_MINOR_VER)

all: $(NAME)

check-go-version:
@if [ $(GO_MAJOR_VER) -gt $(MIN_GO_MAJOR_VER) ]; then \
exit 0 ;\
elif [ $(GO_MAJOR_VER) -lt $(MIN_GO_MAJOR_VER) ]; then \
echo '$(GO_VALIDATION_ERR)';\
exit 1; \
elif [ $(GO_MINOR_VER) -lt $(MIN_GO_MINOR_VER) ] ; then \
echo '$(GO_VALIDATION_ERR)';\
exit 1; \
fi


$(NAME): $(GO_SRC)
$(GO_BUILD) -buildmode=pie -o $@ -ldflags "-X main.name=$(NAME) -X main.version=${VERSION}"

$(NAME).coverage: $(GO_SRC)
$(GO) test \
-covermode=count \
-coverpkg=./... \
-mod=vendor \
-tags coverage \
-buildmode=pie -c -o $@ \
$(NAME).coverage: check-go-version $(GO_SRC)
$(GO) build \
-cover \
-buildmode=pie -o $@ \
-ldflags "-X main.name=$(NAME) -X main.version=${VERSION}"


Expand Down Expand Up @@ -55,14 +70,17 @@ lint: golang-lint shellcheck
test: $(NAME)
bats test/*bats

coverage: $(NAME).coverage
coverage: check-go-version $(NAME).coverage
mkdir -p $(COVERAGE_PATH)
COVERAGE_PATH=$(COVERAGE_PATH) COVERAGE=1 bats test/*bats
# Print coverage from this run
$(GO) tool covdata percent -i=${COVERAGE_PATH}
$(GO) tool covdata textfmt -i=${COVERAGE_PATH} -o ${COVERAGE_PATH}/coverage.out

codecov:
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov -f '.coverage/*'
./codecov -f "$(COVERAGE_PATH)"/coverage.out

vendor:
go mod tidy
Expand All @@ -79,4 +97,4 @@ help:
@echo " * test - run tests"
@echo " * help - show help"

.PHONY: clean install uninstall lint golang-lint shellcheck vendor test help
.PHONY: clean install uninstall lint golang-lint shellcheck vendor test help check-go-version
40 changes: 0 additions & 40 deletions checkpointctl_coverage_test.go

This file was deleted.

11 changes: 0 additions & 11 deletions checkpointctl_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions test/checkpointctl.bats
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if [ -n "$COVERAGE" ]; then
export GOCOVERDIR="${COVERAGE_PATH}"
CHECKPOINTCTL="./checkpointctl.coverage"
ARGS="-test.coverprofile=coverprofile.integration.$RANDOM -test.outputdir=${COVERAGE_PATH} COVERAGE"
else
CHECKPOINTCTL="./checkpointctl"
fi
Expand All @@ -9,7 +9,7 @@ TEST_TMP_DIR2=""

function checkpointctl() {
# shellcheck disable=SC2086
run $CHECKPOINTCTL $ARGS "$@"
run $CHECKPOINTCTL "$@"
echo "$output"
}

Expand Down

0 comments on commit 86e9400

Please sign in to comment.