From 0abc22cd5368ad0c7d1e424426c20970c665711f Mon Sep 17 00:00:00 2001 From: Amisha Singla Date: Thu, 8 Aug 2024 16:46:12 -0500 Subject: [PATCH] add coverage report and readme Fix coverage report --- .github/workflows/integration-tests.yml | 29 +++++++++++++++--- Makefile | 18 +++++++++++ README.md | 40 +++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 4 deletions(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 835cf47e..6debe371 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -16,9 +16,6 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: Set up Docker Compose run: | sudo apt-get update @@ -41,7 +38,31 @@ jobs: - name: Run tests run: | - docker-compose run -v ${{ runner.workspace }}/gcp-key.json:/usr/credential.json:ro -e GOOGLE_APPLICATION_CREDENTIALS=/usr/credential.json integration-tests go test -v -cover ./cmd -timeout 30m + docker-compose run -v ${{ runner.workspace }}/gcp-key.json:/usr/credential.json:ro \ + -v ${{ runner.workspace }}/coverage.out:/usr/coverage.out \ + -e GOOGLE_APPLICATION_CREDENTIALS=/usr/credential.json \ + integration-tests \ + go test -v -coverprofile=/usr/coverage.out ./cmd ./internal/transform -timeout 30m + + - name: Generate Coverage Report + run: | + go tool cover -func=${{ runner.workspace }}/coverage.out + + - name: Check Coverage + id: coverage + run: | + COVERAGE=$(go tool cover -func=${{ runner.workspace }}/coverage.out | grep total: | awk '{print $3}' | sed 's/%//') + echo "Coverage: $COVERAGE%" + if (( $(echo "$COVERAGE < 60" | bc -l) )); then + echo "Coverage is below the 60% threshold." + exit 1 + fi + + - name: Upload Coverage Report + uses: actions/upload-artifact@v3 + with: + name: coverage-report + path: ${{ runner.workspace }}/coverage.out - name: Stop and remove containers run: | diff --git a/Makefile b/Makefile index a94eaadf..319cbc22 100644 --- a/Makefile +++ b/Makefile @@ -13,3 +13,21 @@ docker-build: docker-push: $(SUDO) docker push $(ETLHASH) $(SUDO) docker push stellar/stellar-etl:latest + +int-test: + docker-compose build + docker-compose run \ + -v $(HOME)/.config/gcloud/application_default_credentials.json:/usr/credential.json:ro \ + -v $(PWD)/testdata:/usr/src/etl/testdata \ + -e GOOGLE_APPLICATION_CREDENTIALS=/usr/credential.json \ + integration-tests \ + go test -v ./cmd -timeout 30m + +int-test-update: + docker-compose build + docker-compose run \ + -v $(HOME)/.config/gcloud/application_default_credentials.json:/usr/credential.json:ro \ + -v $(PWD)/testdata:/usr/src/etl/testdata \ + -e GOOGLE_APPLICATION_CREDENTIALS=/usr/credential.json \ + integration-tests \ + go test -v ./cmd -timeout 30m -args -update=true diff --git a/README.md b/README.md index c5d31764..b2c59333 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,46 @@ Add following to docker run command to pass gcloud credentials to docker contain
+## **Running Tests** + +### Unit tests + +```sh +# Running all unit tests +go test -v -cover ./internal/transform + +# Running an individual test +go test -v -run ^TestTransformAsset$ ./internal/transform +``` + +### Integration tests + +```sh +# Running all integration tests +make int-test + +# Running all integration tests and update golden files +make int-test-update + +# Above essentially runs following: +docker-compose build +docker-compose run \ +-v $(HOME)/.config/gcloud/application_default_credentials.json:/usr/credential.json:ro \ +-v $(PWD)/testdata:/usr/src/etl/testdata \ +-e GOOGLE_APPLICATION_CREDENTIALS=/usr/credential.json \ +integration-tests \ +go test -v ./cmd -timeout 30m -args -update=true + +# Running an individual test +docker-compose build +docker-compose run \ +-v $(HOME)/.config/gcloud/application_default_credentials.json:/usr/credential.json:ro \ +-v $(PWD)/testdata:/usr/src/etl/testdata \ +-e GOOGLE_APPLICATION_CREDENTIALS=/usr/credential.json \ +integration-tests \ +go test -v -run ^TestExportAssets$ ./cmd -timeout 30m -args -update=true +``` + --- # **Command Reference**