From db70484bb372a0767f3c785e265256285872306a Mon Sep 17 00:00:00 2001 From: lizrabuya <115472349+lizrabuya@users.noreply.github.com> Date: Mon, 18 Sep 2023 16:03:45 +1000 Subject: [PATCH] test with running tests using run bash -c --- .github/workflows/unit-tests.yml | 11 ++++++----- tests/entrypoint.bats | 32 ++++++++++++++++---------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 2cefc7f..9828ad2 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -8,15 +8,16 @@ jobs: runs-on: ubuntu-latest steps: + - name: Check out code + uses: actions/checkout@v3 + - name: Setup BATS uses: mig4/setup-bats@v1 with: bats-version: 1.2.1 - - name: Check out code - uses: actions/checkout@v1 + - name: Verify that the Docker image for the action builds + run: docker build . --file Dockerfile - name: Test - run: bats -r tests/ - env: - BATS_PLUGIN_PATH: /usr/lib/bats + run: bats -r tests/ diff --git a/tests/entrypoint.bats b/tests/entrypoint.bats index 5b5caff..930fa85 100644 --- a/tests/entrypoint.bats +++ b/tests/entrypoint.bats @@ -1,6 +1,6 @@ #!/usr/bin/env bats -load "${BATS_PLUGIN_PATH}/load.bash" +# load "${BATS_PLUGIN_PATH}/load.bash" # Uncomment to enable stub debugging # export CURL_STUB_DEBUG=/dev/tty @@ -21,7 +21,7 @@ teardown() { } @test "Prints error and fails if \$BUILDKITE_API_ACCESS_TOKEN isn't set" { - run "${PWD}"/entrypoint.sh + run bash -c "${PWD}"/entrypoint.sh assert_output --partial "You must set the BUILDKITE_API_ACCESS_TOKEN environment variable" assert_failure @@ -30,7 +30,7 @@ teardown() { @test "Prints error and fails if \${{ inputs.pipeline }} isn't set" { export BUILDKITE_API_ACCESS_TOKEN="123" - run "${PWD}"/entrypoint.sh + run bash -c "${PWD}"/entrypoint.sh assert_output --partial "You must set the INPUT_PIPELINE environment variable" assert_failure @@ -46,7 +46,7 @@ teardown() { stub curl "--fail-with-body --silent --show-error -X POST -H \"Authorization: Bearer 123\" https://api.buildkite.com/v2/organizations/my-org/pipelines/my-pipeline/builds -d '$EXPECTED_JSON' : echo '$RESPONSE_JSON'" - run "${PWD}"/entrypoint.sh + run bash -c "${PWD}"/entrypoint.sh assert_output --partial "Build created:" assert_output --partial "https://buildkite.com/build-url" @@ -69,7 +69,7 @@ teardown() { stub curl "--fail-with-body --silent --show-error -X POST -H \"Authorization: Bearer 123\" https://api.buildkite.com/v2/organizations/my-org/pipelines/my-pipeline/builds -d '$EXPECTED_JSON' : echo '$RESPONSE_JSON'" - run "${PWD}"/entrypoint.sh + run bash -c "${PWD}"/entrypoint.sh assert_output --partial "Build created:" assert_output --partial "https://buildkite.com/build-url" @@ -92,7 +92,7 @@ teardown() { stub curl "--fail-with-body --silent --show-error -X POST -H \"Authorization: Bearer 123\" https://api.buildkite.com/v2/organizations/my-org/pipelines/my-pipeline/builds -d '$EXPECTED_JSON' : echo '$RESPONSE_JSON'" - run "${PWD}"/entrypoint.sh + run bash -c "${PWD}"/entrypoint.sh assert_output --partial "Build created:" assert_output --partial "https://buildkite.com/build-url" @@ -115,7 +115,7 @@ teardown() { stub curl "--fail-with-body --silent --show-error -X POST -H \"Authorization: Bearer 123\" https://api.buildkite.com/v2/organizations/my-org/pipelines/my-pipeline/builds -d '$EXPECTED_JSON' : echo '$RESPONSE_JSON'" - run "${PWD}"/entrypoint.sh + run bash -c "${PWD}"/entrypoint.sh assert_output --partial "Build created:" assert_output --partial "https://buildkite.com/build-url" @@ -138,7 +138,7 @@ teardown() { stub curl "--fail-with-body --silent --show-error -X POST -H \"Authorization: Bearer 123\" https://api.buildkite.com/v2/organizations/my-org/pipelines/my-pipeline/builds -d '$EXPECTED_JSON' : echo '$RESPONSE_JSON'" - run "${PWD}"/entrypoint.sh + run bash -c "${PWD}"/entrypoint.sh assert_output --partial "Build created:" assert_output --partial "https://buildkite.com/build-url" @@ -161,7 +161,7 @@ teardown() { stub curl "--fail-with-body --silent --show-error -X POST -H \"Authorization: Bearer 123\" https://api.buildkite.com/v2/organizations/my-org/pipelines/my-pipeline/builds -d '$EXPECTED_JSON' : echo '$RESPONSE_JSON'" - run "${PWD}"/entrypoint.sh + run bash -c "${PWD}"/entrypoint.sh assert_output --partial "Build created:" assert_output --partial "https://buildkite.com/build-url" @@ -184,7 +184,7 @@ teardown() { stub curl "--fail-with-body --silent --show-error -X POST -H \"Authorization: Bearer 123\" https://api.buildkite.com/v2/organizations/my-org/pipelines/my-pipeline/builds -d '$EXPECTED_JSON' : echo '$RESPONSE_JSON'" - run "${PWD}"/entrypoint.sh + run bash -c "${PWD}"/entrypoint.sh assert_output --partial "Build created:" assert_output --partial "https://buildkite.com/build-url" @@ -237,7 +237,7 @@ teardown() { assert_file_not_exist $GITHUB_OUTPUT assert_not_exist $GITHUB_OUTPUT - run "${PWD}"/entrypoint.sh + run bash -c "${PWD}"/entrypoint.sh assert_output --partial "Build created:" assert_output --partial "https://buildkite.com/build-url" @@ -262,7 +262,7 @@ teardown() { stub curl "--fail-with-body --silent --show-error -X POST -H \"Authorization: Bearer 123\" https://api.buildkite.com/v2/organizations/my-org/pipelines/my-pipeline/builds -d '$EXPECTED_JSON' : echo 'curl: (22) The requested URL returned error: 401' >&2; exit 22" - run "${PWD}"/entrypoint.sh + run bash -c "${PWD}"/entrypoint.sh assert_output --partial "curl: (22) The requested URL returned error: 401" refute_output --partial "Buildkite API call failed" @@ -282,7 +282,7 @@ teardown() { stub curl "--fail-with-body --silent --show-error -X POST -H \"Authorization: Bearer 123\" https://api.buildkite.com/v2/organizations/my-org/pipelines/my-pipeline/builds -d '$EXPECTED_JSON' : echo '$RESPONSE_HTML'; echo 'curl: (22) The requested URL returned error: 401' >&2; exit 22" - run "${PWD}"/entrypoint.sh + run bash -c "${PWD}"/entrypoint.sh assert_output --partial "curl: (22) The requested URL returned error: 401" refute_output --partial "Buildkite API call failed" @@ -303,7 +303,7 @@ teardown() { stub curl "--fail-with-body --silent --show-error -X POST -H \"Authorization: Bearer 123\" https://api.buildkite.com/v2/organizations/my-org/pipelines/my-pipeline/builds -d '$EXPECTED_JSON' : echo '$RESPONSE_JSON'; echo 'curl: (22) The requested URL returned error: 401' >&2; exit 22" - run "${PWD}"/entrypoint.sh + run bash -c "${PWD}"/entrypoint.sh assert_output --partial "curl: (22) The requested URL returned error: 401" refute_output --partial "Buildkite API call failed" @@ -323,7 +323,7 @@ teardown() { stub curl "--fail-with-body --silent --show-error -X POST -H \"Authorization: Bearer 123\" https://api.buildkite.com/v2/organizations/my-org/pipelines/my-pipeline/builds -d '$EXPECTED_JSON' : echo '$RESPONSE_JSON'; echo 'curl: (22) The requested URL returned error: 401' >&2; exit 22" - run "${PWD}"/entrypoint.sh + run bash -c "${PWD}"/entrypoint.sh assert_output --partial "curl: (22) The requested URL returned error: 401" assert_output --partial 'Buildkite API call failed: "Error Message."' @@ -339,7 +339,7 @@ teardown() { export BUILD_ENV_VARS="broken" export GITHUB_EVENT_NAME="create" - run "${PWD}"/entrypoint.sh + run bash -c "${PWD}"/entrypoint.sh assert_output --partial "Error: BUILD_ENV_VARS provided invalid JSON: broken"