Skip to content

Commit

Permalink
[chore] enable coverage for unit tests (open-telemetry#22966)
Browse files Browse the repository at this point in the history
This re-enables unit test coverage for the repository. Coverage will not immediately include integration tests.

Fixes open-telemetry#8394
---------

Signed-off-by: Alex Boten <[email protected]>
  • Loading branch information
Alex Boten committed Jun 2, 2023
1 parent a33b902 commit 3b88866
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,16 @@ jobs:
path: ~/.cache/go-build
key: go-test-build-${{ runner.os }}-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
- name: Run Unit Tests
if: ${{ matrix.go-version == '1.19' }}
run: make gotest GROUP=${{ matrix.group }}
- name: Run Unit Tests With Coverage
if: ${{ matrix.go-version == '1.20' }} # only run coverage on one version
run: make gotest-with-cover GROUP=${{ matrix.group }}
- uses: actions/upload-artifact@v3
if: ${{ matrix.go-version == '1.20' }} # only run coverage on one version
with:
name: coverage-artifacts
path: ${{ matrix.group }}-coverage.txt
unittest:
if: ${{ github.actor != 'dependabot[bot]' && always() }}
strategy:
Expand All @@ -274,6 +283,19 @@ jobs:
echo "One or more matrix jobs failed."
false
fi
coverage:
runs-on: ubuntu-latest
needs: [unittest]
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: coverage-artifacts
- name: Upload coverage report
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
verbose: true

integration-tests:
runs-on: ubuntu-latest
Expand Down
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ dist/
*.DS_Store

# Coverage
coverage.txt
integration-coverage.txt
coverage.html
coverage/*
*-coverage.txt
integration-coverage.html

# Wix
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ all-common:
e2e-test: otelcontribcol oteltestbedcol
$(MAKE) -C testbed run-tests

.PHONY: unit-tests-with-cover
unit-tests-with-cover:
@echo Verifying that all packages have test files to count in coverage
@internal/buildscripts/check-test-files.sh $(subst github.com/open-telemetry/opentelemetry-collector-contrib/,./,$(ALL_PKGS))
@$(MAKE) $(FOR_GROUP_TARGET) TARGET="do-unit-tests-with-cover"

TARGET="do-integration-tests-with-cover"
.PHONY: integration-tests-with-cover
integration-tests-with-cover: $(INTEGRATION_MODS)
Expand All @@ -101,6 +95,11 @@ gomoddownload:
gotest:
$(MAKE) $(FOR_GROUP_TARGET) TARGET="test"

.PHONY: gotest-with-cover
gotest-with-cover:
@$(MAKE) $(FOR_GROUP_TARGET) TARGET="test-with-cover"
$(GOCMD) tool covdata textfmt -i=./coverage/unit -o ./$(GROUP)-coverage.txt

.PHONY: gofmt
gofmt:
$(MAKE) $(FOR_GROUP_TARGET) TARGET="fmt"
Expand Down Expand Up @@ -385,6 +384,7 @@ clean:
@echo "Removing coverage files"
find . -type f -name 'coverage.txt' -delete
find . -type f -name 'coverage.html' -delete
find . -type f -name 'coverage.out' -delete
find . -type f -name 'integration-coverage.txt' -delete
find . -type f -name 'integration-coverage.html' -delete

Expand Down
7 changes: 6 additions & 1 deletion Makefile.Common
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ common: lint
.PHONY: test
test:
$(GOTEST) $(GOTEST_OPT) ./...


.PHONY: test-with-cover
test-with-cover:
mkdir -p $(PWD)/coverage/unit
$(GOTEST) -cover ./... -covermode=atomic -args -test.gocoverdir="$(PWD)/coverage/unit"

.PHONY: do-unit-tests-with-cover
do-unit-tests-with-cover:
@echo "running $(GOCMD) unit test ./... + coverage in `pwd`"
Expand Down

0 comments on commit 3b88866

Please sign in to comment.