Fix unit test #271
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Terraform Provider testing workflow. | |
name: Tests | |
# This GitHub action runs your tests for each pull request and push. | |
# Optionally, you can turn it on using a schedule for regular testing. | |
on: | |
pull_request: | |
branches: ["main"] | |
paths-ignore: | |
- "README.md" | |
- ".github/workflows/release.yml" | |
- ".goreleaser.yml" | |
push: | |
branches: ["main"] | |
paths-ignore: | |
- "README.md" | |
- ".github/workflows/release.yml" | |
- ".goreleaser.yml" | |
# Testing only needs permissions to read the repository contents. | |
permissions: | |
contents: read | |
# Default values to simplify job configurations below. | |
env: | |
# Go language version to use for building. This value should also be updated | |
# in the release workflow if changed. | |
GO_VERSION: "1.22" | |
jobs: | |
# Ensure project builds before running testing matrix | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
timeout-minutes: 5 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- run: go mod download | |
- run: go build -v . | |
- name: Install Terraform | |
uses: hashicorp/setup-terraform@v3 | |
with: | |
terraform_version: ${{ matrix.terraform }} | |
terraform_wrapper: false | |
generate: | |
# this seems to cause an error as the generation now wants to exec | |
# terraform and it's not available here. need to consider what to do. | |
runs-on: ubuntu-latest | |
if: false | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- run: go generate ./... | |
- name: git diff | |
run: | | |
git diff --compact-summary --exit-code || \ | |
(echo; echo "Unexpected difference in directories after code generation. Run 'go generate ./...' command and commit."; exit 1) | |
# Run acceptance tests in a matrix with Terraform CLI versions | |
test: | |
name: Terraform Provider Acceptance Tests | |
needs: build | |
runs-on: ubuntu-latest | |
timeout-minutes: 30 | |
strategy: | |
max-parallel: 1 | |
fail-fast: false | |
matrix: | |
# list whatever Terraform versions here you would like to support | |
# jobs run in parallel -- some tests create resources with | |
# specific IDs which must be unique... some test resource randomization | |
# is needed but doesn't exist... Currently only testing w/ 1.6 | |
# max-parallel: 1 should fix this! | |
# Specific versions needed! | |
# NOTE: required tests are configured in branch protection! | |
terraform: | |
- "1.8.5" | |
- "1.9.8" | |
- "1.10.4" | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- run: go mod download | |
- uses: hashicorp/setup-terraform@v3 | |
with: | |
terraform_version: ${{ matrix.terraform }} | |
terraform_wrapper: false | |
- env: | |
# for the time being, only do unit tests, below needs to be changed | |
# to secrets when used with the tunnel.sh script. | |
# TF_ACC: "0" | |
NGROK_URL: ${{ secrets.NGROK_URL }} | |
run: | | |
echo "setting env vars" | |
echo "TF_VAR_address=https://localhost" >>$GITHUB_ENV | |
if [ -n "$NGROK_URL" ]; then | |
echo "TF_ACC=1" >> $GITHUB_ENV | |
echo "TF_VAR_address=${NGROK_URL}" >> $GITHUB_ENV | |
fi | |
- env: | |
TF_VAR_username: ${{ secrets.USERNAME }} | |
TF_VAR_password: ${{ secrets.PASSWORD }} | |
TF_VAR_token: ${{ secrets.TOKEN }} | |
TF_ACC_TERRAFORM_VERSION: ${{ matrix.terraform }} | |
run: go test -timeout 1h -race -v -covermode atomic -coverprofile=covprofile ./internal/... | |
timeout-minutes: 60 | |
- name: Install goveralls | |
run: go install github.com/mattn/goveralls@latest | |
- name: Send coverage | |
env: | |
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: goveralls -coverprofile=covprofile -service=github |