From 2b51aedca9fc38f156aec6818d74cd2fbc5101f6 Mon Sep 17 00:00:00 2001 From: Nuru Date: Thu, 28 Apr 2022 11:26:42 -0700 Subject: [PATCH] Fix Disabled test (#24) --- .github/workflows/auto-readme.yml | 22 +++++++++++++++++++--- Makefile | 2 +- test/src/Makefile | 2 +- test/src/examples_complete_test.go | 13 +++++-------- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/.github/workflows/auto-readme.yml b/.github/workflows/auto-readme.yml index 03232cd..6f25b8d 100644 --- a/.github/workflows/auto-readme.yml +++ b/.github/workflows/auto-readme.yml @@ -1,5 +1,7 @@ name: "auto-readme" on: + workflow_dispatch: + schedule: # Example of job definition: # .---------------- minute (0 - 59) @@ -15,21 +17,35 @@ on: jobs: update: - if: github.event_name == 'schedule' + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - name: Find default branch name + id: defaultBranch + shell: bash + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + run: | + default_branch=$(gh repo view --json defaultBranchRef --jq .defaultBranchRef.name) + printf "::set-output name=defaultBranch::%s\n" "${default_branch}" + printf "defaultBranchRef.name=%s\n" "${default_branch}" + - name: Update readme shell: bash id: update env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + DEF: "${{ steps.defaultBranch.outputs.defaultBranch }}" run: | make init make readme/build # Ignore changes if they are only whitespace - git diff --ignore-all-space --ignore-blank-lines --quiet README.md && { git restore README.md; echo Ignoring whitespace-only changes in README; } + if ! git diff --quiet README.md && git diff --ignore-all-space --ignore-blank-lines --quiet README.md; then + git restore README.md + echo Ignoring whitespace-only changes in README + fi - name: Create Pull Request # This action will not create or change a pull request if there are no changes to make. @@ -47,7 +63,7 @@ jobs: To have most recent changes of README.md and doc from origin templates branch: auto-update/readme - base: main + base: ${{ steps.defaultBranch.outputs.defaultBranch }} delete-branch: true labels: | auto-update diff --git a/Makefile b/Makefile index 97d8087..1cfc68f 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ SHELL := /bin/bash # List of targets the `readme` target should call before generating the readme export README_DEPS ?= docs/targets.md docs/terraform.md --include $(shell curl -sSL -o .build-harness "https://git.io/build-harness"; echo .build-harness) +-include $(shell curl -sSL -o .build-harness "https://cloudposse.tools/build-harness"; echo .build-harness) ## Lint terraform code lint: diff --git a/test/src/Makefile b/test/src/Makefile index 677c05a..81c71b6 100644 --- a/test/src/Makefile +++ b/test/src/Makefile @@ -15,7 +15,7 @@ init: ## Run tests test: init go mod download - go test -v -timeout 60m -run TestExamplesComplete + go test -v -timeout 60m ## Run tests in docker container docker/test: diff --git a/test/src/examples_complete_test.go b/test/src/examples_complete_test.go index ffd4aca..58e9d00 100644 --- a/test/src/examples_complete_test.go +++ b/test/src/examples_complete_test.go @@ -92,8 +92,8 @@ func TestExamplesComplete(t *testing.T) { func TestExamplesCompleteDisabled(t *testing.T) { t.Parallel() - randId := strings.ToLower(random.UniqueId()) - attributes := []string{randId} + randID := strings.ToLower(random.UniqueId()) + attributes := []string{randID} rootFolder := "../../" terraformFolderRelativeToRoot := "examples/complete" @@ -117,11 +117,8 @@ func TestExamplesCompleteDisabled(t *testing.T) { defer cleanup(t, terraformOptions, tempTestFolder) // This will run `terraform init` and `terraform apply` and fail the test if there are any errors - terraform.InitAndApply(t, terraformOptions) + results := terraform.InitAndApply(t, terraformOptions) - // Get all the output and lookup a field. Pass if the field is missing or empty. - example := terraform.OutputAll(t, terraformOptions)["example"] - - // Verify we're getting back the outputs we expect - assert.Empty(t, example, "When disabled, module should have no outputs.") + // Should complete successfully without creating or changing any resources + assert.Contains(t, results, "Resources: 0 added, 0 changed, 0 destroyed.") }