From e115a0e159ab9c6f4863e71878e5e82237e7d138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ruben=20H=C3=B6nle?= Date: Wed, 26 Mar 2025 15:38:44 +0100 Subject: [PATCH] chore: add make option to create test coverage reports (#741) --- .gitignore | 4 ++++ CONTRIBUTION.md | 1 + Makefile | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/.gitignore b/.gitignore index 09fb0713..e376491c 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,7 @@ go.work.sum # Unit test files stackit/internal/services/iaas/test-512k.img + +# Test coverage reports +coverage.out +coverage.html diff --git a/CONTRIBUTION.md b/CONTRIBUTION.md index 5f555da3..399bf721 100644 --- a/CONTRIBUTION.md +++ b/CONTRIBUTION.md @@ -26,6 +26,7 @@ These commands can be executed from the project root: - `make lint`: lint the code and examples - `make generate-docs`: generate terraform documentation - `make test`: run unit tests +- `make coverage`: create unit test coverage report (output file: `stackit/coverage.html`) - `make test-acceptance-tf`: run acceptance tests ### Repository structure diff --git a/Makefile b/Makefile index 0e644f94..cbba865d 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,12 @@ test: @echo "Running tests for the terraform provider" @cd $(ROOT_DIR)/stackit && go test ./... -count=1 && cd $(ROOT_DIR) +# Test coverage +coverage: + @echo ">> Creating test coverage report for the terraform provider" + @cd $(ROOT_DIR)/stackit && (go test ./... -count=1 -coverprofile=coverage.out || true) && cd $(ROOT_DIR) + @cd $(ROOT_DIR)/stackit && go tool cover -html=coverage.out -o coverage.html && cd $(ROOT_DIR) + test-acceptance-tf: @if [ -z $(TF_ACC_PROJECT_ID) ]; then echo "Input TF_ACC_PROJECT_ID missing"; exit 1; fi @if [ -z $(TF_ACC_ORGANIZATION_ID) ]; then echo "Input TF_ACC_ORGANIZATION_ID missing"; exit 1; fi