Skip to content

Commit

Permalink
test with running tests using run bash -c
Browse files Browse the repository at this point in the history
  • Loading branch information
lizrabuya committed Sep 18, 2023
1 parent 7158e14 commit db70484
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
32 changes: 16 additions & 16 deletions tests/entrypoint.bats
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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."'
Expand All @@ -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"

Expand Down

0 comments on commit db70484

Please sign in to comment.