Skip to content

Commit cd737ec

Browse files
committed
tests: improve and display coverage
1 parent fd20b40 commit cd737ec

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ obj-x86_64-linux-gnu/
44
obj-aarch64-linux-gnu/
55
obj-arm-linux-gnueabihf/
66
obj-i686-linux-gnu/
7-
unit.out
7+
unit-test.cov
8+
system-test.cov
89
aptly.test
910
build/
1011
dpkgs/

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ jobs:
8989
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
9090
run: |
9191
sudo mkdir -p /srv ; sudo chown runner /srv
92-
COVERAGE_DIR=${{ runner.temp }} make system-test
92+
make system-test
9393
9494
- name: "Merge Code Coverage"
9595
run: |
9696
go install github.com/wadey/[email protected]
97-
~/go/bin/gocovmerge unit.out ${{ runner.temp }}/*.out > coverage.txt
97+
~/go/bin/gocovmerge unit-test.cov system-test.cov > coverage.txt
9898
9999
- name: "Upload Code Coverage"
100100
uses: codecov/codecov-action@v2

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
*.o
33
*.a
44
*.so
5-
unit.out
5+
unit-test.cov
6+
system-test.cov
67

78
# Folders
89
_obj

Makefile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ VERSION=$(shell make -s version)
33
PYTHON?=python3
44
BINPATH?=$(GOPATH)/bin
55
GOLANGCI_LINT_VERSION=v2.0.2 # version supporting go 1.24
6-
COVERAGE_DIR?=$(shell mktemp -d)
76
GOOS=$(shell go env GOHOSTOS)
87
GOARCH=$(shell go env GOHOSTARCH)
98

@@ -15,12 +14,16 @@ export TZ=UTC
1514
# Unit Tests and some sysmte tests rely on expired certificates, turn back the time
1615
export TEST_FAKETIME := 2025-01-02 03:04:05
1716

17+
ifeq ($(origin COVERAGE_DIR), undefined)
18+
COVERAGE_DIR := $(shell mktemp -d)
19+
endif
20+
1821
# run with 'COVERAGE_SKIP=1' to skip coverage checks during system tests
1922
ifeq ($(COVERAGE_SKIP),1)
2023
COVERAGE_ARG_BUILD :=
2124
COVERAGE_ARG_TEST := --coverage-skip
2225
else
23-
COVERAGE_ARG_BUILD := -coverpkg="./..."
26+
COVERAGE_ARG_BUILD := -coverpkg=github.com/aptly-dev/aptly/...
2427
COVERAGE_ARG_TEST := --coverage-dir $(COVERAGE_DIR)
2528
endif
2629

@@ -107,13 +110,16 @@ test: prepare swagger etcd-install ## Run unit tests (add TEST=regex to specify
107110
@echo "\e[33m\e[1mStarting etcd ...\e[0m"
108111
@mkdir -p /tmp/aptly-etcd-data; system/t13_etcd/start-etcd.sh > /tmp/aptly-etcd-data/etcd.log 2>&1 &
109112
@echo "\e[33m\e[1mRunning go test ...\e[0m"
110-
faketime "$(TEST_FAKETIME)" go test -v ./... -gocheck.v=true -check.f "$(TEST)" -coverprofile=unit.out; echo $$? > .unit-test.ret
113+
faketime "$(TEST_FAKETIME)" go test -v ./... -gocheck.v=true -check.f "$(TEST)" -coverprofile=unit-test.cov; echo $$? > .unit-test.ret
111114
@echo "\e[33m\e[1mStopping etcd ...\e[0m"
112115
@pid=`cat /tmp/etcd.pid`; kill $$pid
113116
@rm -f /tmp/aptly-etcd-data/etcd.log
114117
@ret=`cat .unit-test.ret`; if [ "$$ret" = "0" ]; then echo "\n\e[32m\e[1mUnit Tests SUCCESSFUL\e[0m"; else echo "\n\e[31m\e[1mUnit Tests FAILED\e[0m"; fi; rm -f .unit-test.ret; exit $$ret
118+
@go tool cover -func=unit-test.cov
119+
115120

116121
system-test: prepare swagger etcd-install ## Run system tests
122+
@test -f $(BINPATH)/gocovmerge || GOOS= GOARCH= go install github.com/wadey/gocovmerge@latest
117123
# build coverage binary
118124
go test -v $(COVERAGE_ARG_BUILD) -c -tags testruncli
119125
# Download fixture-db, fixture-pool, etcd.db
@@ -122,6 +128,9 @@ system-test: prepare swagger etcd-install ## Run system tests
122128
test -f ~/etcd.db || (curl -o ~/etcd.db.xz http://repo.aptly.info/system-tests/etcd.db.xz && xz -d ~/etcd.db.xz)
123129
# Run system tests
124130
PATH=$(BINPATH)/:$(PATH) FORCE_COLOR=1 $(PYTHON) system/run.py --long $(COVERAGE_ARG_TEST) $(CAPTURE_ARG) $(TEST)
131+
PATH=$(BINPATH)/:$(PATH) gocovmerge $(COVERAGE_DIR)/*.out > system-test.cov
132+
rm -f $(COVERAGE_DIR)/*.out
133+
go tool cover -func=system-test.cov
125134

126135
bench:
127136
@echo "\e[33m\e[1mRunning benchmark ...\e[0m"
@@ -237,7 +246,7 @@ clean: ## remove local build and module cache
237246
test ! -e .go || find .go/ -type d ! -perm -u=w -exec chmod u+w {} \;
238247
rm -rf .go/
239248
rm -rf build/ obj-*-linux-gnu* tmp/
240-
rm -f unit.out aptly.test VERSION docs/docs.go docs/swagger.json docs/swagger.yaml docs/swagger.conf
249+
rm -f unit-test.cov system-test.cov aptly.test VERSION docs/docs.go docs/swagger.json docs/swagger.yaml docs/swagger.conf
241250
find system/ -type d -name __pycache__ -exec rm -rf {} \; 2>/dev/null || true
242251

243252
.PHONY: help man prepare swagger version binaries build docker-release docker-system-test docker-unit-test docker-lint docker-build docker-image docker-man docker-shell docker-serve clean releasetype dpkg serve flake8

system/testout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class TestOut:
55
def __init__(self):
6-
self.tmp_file = tempfile.NamedTemporaryFile(delete=False)
6+
self.tmp_file = tempfile.NamedTemporaryFile(delete=True)
77
self.read_pos = 0
88

99
def fileno(self):

0 commit comments

Comments
 (0)