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

Test coverage in PRs #193

Merged
merged 4 commits into from
May 13, 2024
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
31 changes: 31 additions & 0 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,40 @@ jobs:
- name: Check style
run: make check_style

- name: Install Go Test Coverage
run: make install-go-test-coverage

- name: Build
run: make bin

- name: Test
# Run tests as root as we require it for systemd tests
run: sudo make test

- name: Check test coverage
uses: vladopajic/go-test-coverage@v2
id: go-test-coverage
with:
config: ./.testcoverage.yml

- name: Upload report
uses: actions/upload-artifact@v4
id: uploaded-report
with:
name: cover
path: cover.html

- name: Comment test coverage
if: ${{ github.event_name == 'pull_request' }}
uses: actions/github-script@v7
env:
TOTAL_COVERAGE: ${{ steps.go-test-coverage.outputs.total-coverage }}
ARTIFACT_URL: ${{ steps.uploaded-report.outputs.artifact-url }}
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Total test coverage: ${{ env.TOTAL_COVERAGE }}%\n Download report: ${{ env.ARTIFACT_URL }}'
})
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ go.work
go.work.sum
.github/artifacts/benchmark-data.json
.github/artifacts/data.json
cover.out
cover.html
17 changes: 17 additions & 0 deletions .testcoverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# (mandatory)
# Path to coverprofile file (output of `go test -coverprofile` command)
profile: cover.out

# (optional)
# When specified reported file paths will not contain local prefix in the output
local-prefix: "github.com/awslabs/mountpoint-s3-csi-driver"

# Holds regexp rules which will exclude matched files or packages from coverage statistics
exclude:
# Exclude files or packages matching their paths
paths:
- \.pb\.go$ # excludes all protobuf generated files

# NOTES:
# - symbol `/` in all path regexps will be replaced by
# current OS file path separator to properly work on Windows
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,15 @@ bin:
CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -ldflags ${LDFLAGS} -o bin/aws-s3-csi-driver ./cmd/aws-s3-csi-driver/
CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -ldflags ${LDFLAGS} -o bin/install-mp ./cmd/install-mp/

.PHONY: install-go-test-coverage
install-go-test-coverage:
go install github.com/vladopajic/go-test-coverage/v2@latest

.PHONY: test
test:
go test -v -race ./pkg/...
go test -v -race ./pkg/... -coverprofile=./cover.out -covermode=atomic -coverpkg=./pkg/...
${GOBIN}/go-test-coverage --config=./.testcoverage.yml
go tool cover -html=cover.out -o=cover.html
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we able to see this html output somewhere?

# skipping controller test cases because we don't implement controller for static provisioning, this is a known limitation of sanity testing package: https://github.com/kubernetes-csi/csi-test/issues/214
go test -v ./tests/sanity/... -ginkgo.skip="ControllerGetCapabilities" -ginkgo.skip="ValidateVolumeCapabilities"

Expand Down
Loading