Skip to content

Commit 77fa0cf

Browse files
committed
generate code coverage
1 parent b9494d9 commit 77fa0cf

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

.pipelines/templates/run-unit-tests.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,30 @@ stages:
1313
steps:
1414
- script: |
1515
make tools
16-
# run test, echo exit status code to fd 3, pipe output from test to tee, which splits output to stdout and go-junit-report (which converts test output to report.xml), stdout from tee is redirected to fd 4. Take output written to fd 3 (which is the exit code of test), redirect to stdout, pipe to read from stdout then exit with that status code. Read all output from fd 4 (output from tee) and write to top stdout
16+
sudo ln -s $(pwd)/build/tools/bin/gocov /usr/local/bin/gocov
17+
sudo ln -s $(pwd)/build/tools/bin/gocov-xml /usr/local/bin/gocov-xml
18+
19+
# run test, echo exit status code to fd 3, pipe output from test to tee, which splits output to stdout and go-junit-report (which converts test output to report.xml),
20+
# stdout from tee is redirected to fd 4. Take output written to fd 3 (which is the exit code of test), redirect to stdout, pipe to read from stdout then exit with that status code.
21+
# Read all output from fd 4 (output from tee) and write to top stdout
1722
{ { { {
1823
sudo -E env "PATH=$PATH" make test-all;
1924
echo $? >&3;
2025
} | tee >(build/tools/bin/go-junit-report > report.xml) >&4;
2126
} 3>&1;
2227
} | { read xs; exit $xs; }
2328
} 4>&1
29+
30+
gocov convert coverage-all.out > total_ut_coverage.json
31+
gocov-xml < total_ut_coverage.json > total_ut_coverage.xml
2432
retryCountOnTaskFailure: 3
2533
name: "Test"
2634
displayName: "Run Tests"
35+
- task: PublishCodeCoverageResults@2
36+
displayName: "Publish Code Coverage Report"
37+
condition: always()
38+
inputs:
39+
summaryFileLocation: total_ut_coverage.xml
2740

2841
- stage: test_windows
2942
displayName: Test ACN Windows

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -758,9 +758,8 @@ RESTART_CASE ?= false
758758
CNI_TYPE ?= cilium
759759

760760
test-all: ## run all unit tests.
761-
@$(eval COVER_FILTER=`go list $(COVER_PKG)/... | tr '\n' ','`)
762-
@echo Test coverpkg: $(COVER_FILTER)
763-
go test -mod=readonly -buildvcs=false -tags "unit" --skip 'TestE2E*' -coverpkg=$(COVER_FILTER) -race -covermode atomic -coverprofile=coverage.out $(COVER_PKG)/...
761+
-go test -mod=readonly -buildvcs=false -tags "unit" --skip 'TestE2E*' -race -covermode atomic -coverprofile=coverage-all.out $(COVER_PKG)/...
762+
go tool cover -func=coverage-all.out
764763

765764
test-integration: ## run all integration tests.
766765
AZURE_IPAM_VERSION=$(AZURE_IPAM_VERSION) \

0 commit comments

Comments
 (0)