Skip to content

Commit 02d5d2f

Browse files
Shashank SinhatshcherbanartemgavrilovBupycHukJiriCtvrtka
authored
Add code coverage action in pipeline (#569)
* Add code coverage action in pipeline * Trigger pipeline * Fix configuration of test sandbox --------- Co-authored-by: Taras Shcherban <shcherban91@gmail.com> Co-authored-by: Artem Gavrilov <charlieblackwood7@gmail.com> Co-authored-by: Nurlan Moldomurov <bupychuk1989@gmail.com> Co-authored-by: Jiří Čtvrtka <62988319+JiriCtvrtka@users.noreply.github.com>
1 parent 0239f77 commit 02d5d2f

File tree

5 files changed

+31
-15
lines changed

5 files changed

+31
-15
lines changed

.github/workflows/go.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,22 @@ jobs:
4343
with:
4444
go-version-file: ${{ github.workspace }}/go.mod
4545

46-
- name: Test
46+
- name: Run tests with code coverage
4747
run: |
4848
TEST_MONGODB_IMAGE=${{ matrix.image }} make test-cluster
4949
sleep 10
50-
make test-race
50+
make test-cover
5151
make test-cluster-clean
5252
53+
54+
- name: Upload coverage results
55+
uses: codecov/codecov-action@v3
56+
with:
57+
file: cover.out
58+
flags: agent
59+
env_vars: GO_VERSION,TEST_MONGODB_IMAGE
60+
fail_ci_if_error: false
61+
5362
- name: Run debug commands on failure
5463
if: ${{ failure() }}
5564
run: |

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
.dist
22
.env
3+
34
.vscode/
45
.idea
6+
57
bin
68
build
79
dist
10+
11+
cover.out
812
mongodb_exporter
913
.DS_Store

Makefile

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ define TEST_ENV
5050
TEST_MONGODB_S1_PRIMARY_PORT=$(TEST_MONGODB_S1_PRIMARY_PORT) \
5151
TEST_MONGODB_S1_SECONDARY1_PORT=$(TEST_MONGODB_S1_SECONDARY1_PORT) \
5252
TEST_MONGODB_S1_SECONDARY2_PORT=$(TEST_MONGODB_S1_SECONDARY2_PORT) \
53-
TEST_MONGODB_S1_ARTBITER_PORT=$(TEST_MONGODB_S1_ARBITER_PORT) \
53+
TEST_MONGODB_S1_ARBITER_PORT=$(TEST_MONGODB_S1_ARBITER_PORT) \
5454
TEST_MONGODB_S2_RS=$(TEST_MONGODB_S2_RS) \
5555
TEST_MONGODB_S2_PRIMARY_PORT=$(TEST_MONGODB_S2_PRIMARY_PORT) \
5656
TEST_MONGODB_S2_SECONDARY1_PORT=$(TEST_MONGODB_S2_SECONDARY1_PORT) \
5757
TEST_MONGODB_S2_SECONDARY2_PORT=$(TEST_MONGODB_S2_SECONDARY2_PORT) \
58-
TEST_MONGODB_S2_ARTBITER_PORT=$(TEST_MONGODB_S2_ARBITER_PORT) \
58+
TEST_MONGODB_S2_ARBITER_PORT=$(TEST_MONGODB_S2_ARBITER_PORT) \
5959
TEST_MONGODB_CONFIGSVR_RS=$(TEST_MONGODB_CONFIGSVR_RS) \
6060
TEST_MONGODB_CONFIGSVR1_PORT=$(TEST_MONGODB_CONFIGSVR1_PORT) \
6161
TEST_MONGODB_CONFIGSVR2_PORT=$(TEST_MONGODB_CONFIGSVR2_PORT) \
@@ -67,7 +67,7 @@ endef
6767
env:
6868
@echo $(TEST_ENV) | tr ' ' '\n' >.env
6969

70-
init: ## Install linters.
70+
init: ## Install linters
7171
cd tools && go generate -x -tags=tools
7272

7373
build: ## Compile using plain go build
@@ -82,32 +82,34 @@ release: ## Build the binaries using goreleaser
8282

8383
FILES = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
8484

85-
format: ## Format source code.
85+
format: ## Format source code
8686
go mod tidy
8787
bin/gofumpt -l -w $(FILES)
8888
bin/gci write --section Standard --section Default --section "Prefix(github.com/percona/mongodb_exporter)" .
8989

9090
check: ## Run checks/linters
9191
bin/golangci-lint run
9292

93-
check-license: ## Check license in headers.
93+
check-license: ## Check license in headers
9494
@go run .github/check-license.go
9595

96-
help: ## Display this help message.
96+
help: ## Display this help message
9797
@echo "Please use \`make <target>\` where <target> is one of:"
9898
@grep '^[a-zA-Z]' $(MAKEFILE_LIST) | \
9999
awk -F ':.*?## ' 'NF==2 {printf " %-26s%s\n", $$1, $$2}'
100100

101-
test: env ## Run all tests.
101+
test: env ## Run all tests
102102
go test -v -count 1 -timeout 30s ./...
103103

104-
test-race: env ## Run all tests with race flag.
104+
test-race: env ## Run all tests with race flag
105105
go test -race -v -timeout 30s ./...
106106

107+
test-cover: env ## Run tests and collect cross-package coverage information
108+
go test -race -timeout 30s -coverprofile=cover.out -covermode=atomic -coverpkg=./... ./...
109+
107110
test-cluster: env ## Starts MongoDB test cluster. Use env var TEST_MONGODB_IMAGE to set flavor and version. Example: TEST_MONGODB_IMAGE=mongo:3.6 make test-cluster
108111
docker compose up --build -d
109112
./docker/scripts/setup-pbm.sh
110113

111114
test-cluster-clean: env ## Stops MongoDB test cluster.
112-
docker compose down --remove-orphans
113-
115+
docker compose down --remove-orphans --volumes

docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ services:
176176
container_name: "mongo-cnf-2"
177177
image: ${TEST_MONGODB_IMAGE:-mongo:4.4}
178178
ports:
179-
- "${TEST_MONGODB_CONFIGSVR1_PORT:-17007}:27017"
179+
- "${TEST_MONGODB_CONFIGSVR2_PORT:-17008}:27017"
180180
command: mongod --dbpath /data/db --replSet cnf-serv --configsvr --port 27017 --oplogSize 16
181181
networks:
182182
- cnf-serv
@@ -185,7 +185,7 @@ services:
185185
container_name: "mongo-cnf-3"
186186
image: ${TEST_MONGODB_IMAGE:-mongo:4.4}
187187
ports:
188-
- "${TEST_MONGODB_CONFIGSVR2_PORT:-17008}:27017"
188+
- "${TEST_MONGODB_CONFIGSVR3_PORT:-17009}:27017"
189189
command: mongod --dbpath /data/db --replSet cnf-serv --configsvr --port 27017 --oplogSize 16
190190
networks:
191191
- cnf-serv
@@ -194,7 +194,7 @@ services:
194194
container_name: "mongo-cnf-1"
195195
image: ${TEST_MONGODB_IMAGE:-mongo:4.4}
196196
ports:
197-
- "${TEST_MONGODB_CONFIGSVR3_PORT:-17009}:27017"
197+
- "${TEST_MONGODB_CONFIGSVR1_PORT:-17007}:27017"
198198
command: mongod --dbpath /data/db --replSet cnf-serv --configsvr --port 27017 --oplogSize 16
199199
networks:
200200
- cnf-serv

docker/scripts/setup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ function general_servers() {
100100
EOF
101101
}
102102

103+
103104
case $1 in
104105
cnf_servers)
105106
cnf_servers

0 commit comments

Comments
 (0)