Skip to content

Commit

Permalink
Updated tests and validated mandatory variable
Browse files Browse the repository at this point in the history
  • Loading branch information
toote committed Feb 21, 2023
1 parent 7596506 commit a46aa12
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
5 changes: 5 additions & 0 deletions hooks/command
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 35 additions & 8 deletions tests/command.bats
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit a46aa12

Please sign in to comment.