Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use golang 1.20 for binary test code coverage #44

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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