diff --git a/hooks/command b/hooks/command index 7f7c764..42a44d7 100755 --- a/hooks/command +++ b/hooks/command @@ -2,6 +2,11 @@ set -euo pipefail +if [ -z "${BUILDKITE_PLUGIN_PLUGIN_LINTER_ID:-}" ]; then + echo ':boom: Missing id parameter in plugin configuration' + exit 1 +fi + echo "--- :docker: Fetching the latest buildkite/plugin-linter" docker pull buildkite/plugin-linter diff --git a/tests/command.bats b/tests/command.bats index 196efcc..2691381 100644 --- a/tests/command.bats +++ b/tests/command.bats @@ -1,18 +1,31 @@ #!/usr/bin/env bats -load '/usr/local/lib/bats/load.bash' - # Uncomment the following to get more detail on failures of stubs # export DOCKER_STUB_DEBUG=/dev/tty -@test "Runs the linter via Docker" { +setup() { + load "${BATS_PLUGIN_PATH}/load.bash" + export BUILDKITE_PLUGIN_PLUGIN_LINTER_ID=my-plugin + # defining specific version to make all the tests not dependent on default + export BUILDKITE_PLUGIN_PLUGIN_LINTER_IMAGE_VERSION='latest' +} + +@test "Missing id parameter is a failure" { + unset BUILDKITE_PLUGIN_PLUGIN_LINTER_ID + + run "$PWD"/hooks/command + assert_failure + assert_output --partial 'Missing id parameter in plugin configuration' +} + +@test "Runs the linter via Docker" { stub docker \ "pull buildkite/plugin-linter : echo pulled image" \ - "run -it --rm --volume /plugin:/plugin:ro --env PLUGIN_ID=my-plugin buildkite/plugin-linter : echo linted" + "run -it --rm --volume /plugin:/plugin:ro --env PLUGIN_ID=my-plugin buildkite/plugin-linter:latest : echo linted" - run $PWD/hooks/command + run "$PWD"/hooks/command assert_success assert_output --partial "pulled image" @@ -21,14 +34,28 @@ load '/usr/local/lib/bats/load.bash' } @test "Supports the readme option" { - export BUILDKITE_PLUGIN_PLUGIN_LINTER_ID=my-plugin export BUILDKITE_PLUGIN_PLUGIN_LINTER_README=some-readme.yml stub docker \ "pull buildkite/plugin-linter : echo pulled image" \ - "run -it --rm --volume /plugin:/plugin:ro --env PLUGIN_ID=my-plugin --env PLUGIN_README=some-readme.yml buildkite/plugin-linter : echo linted" + "run -it --rm --volume /plugin:/plugin:ro --env PLUGIN_ID=my-plugin --env PLUGIN_README=some-readme.yml buildkite/plugin-linter:latest : echo linted" + + run "$PWD"/hooks/command + + assert_success + assert_output --partial "pulled image" + assert_output --partial "linted" + unstub docker +} + +@test "Support not specifying a tag" { + unset BUILDKITE_PLUGIN_PLUGIN_LINTER_IMAGE_VERSION + + stub docker \ + "pull buildkite/plugin-linter : echo pulled image" \ + "run -it --rm --volume /plugin:/plugin:ro --env PLUGIN_ID=my-plugin buildkite/plugin-linter:v2.0.1 : echo linted" - run $PWD/hooks/command + run "$PWD"/hooks/command assert_success assert_output --partial "pulled image"