forked from buildkite-plugins/detect-clowns-buildkite-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.bats
35 lines (24 loc) · 751 Bytes
/
command.bats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env bats
load "${BATS_PLUGIN_PATH}/load.bash"
tmp_dir=$(mktemp -d -t clowns-checkout.XXXXXXXXXX)
command_hook="$PWD/hooks/command"
function cleanup {
rm -rf "$tmp_dir"
}
trap cleanup EXIT
@test "Command fails if clowns exist" {
export BUILDKITE_BUILD_CHECKOUT_PATH=$tmp_dir
cd "$BUILDKITE_BUILD_CHECKOUT_PATH"
echo "Beware the clowns! 🤡" > "$tmp_dir/code.txt"
run "$command_hook"
assert_failure
assert_output --partial "Detected clowns"
}
@test "Command succeeds if clowns do not exist" {
export BUILDKITE_BUILD_CHECKOUT_PATH=$tmp_dir
cd "$BUILDKITE_BUILD_CHECKOUT_PATH"
echo "There art no clowns!" > "$tmp_dir/code.txt"
run "$command_hook"
assert_success
refute_output --partial "Detected clowns"
}