-
Notifications
You must be signed in to change notification settings - Fork 3
/
command.bats
115 lines (81 loc) · 5.07 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env bats
load '/usr/local/lib/bats/load.bash'
tmp_dir=$(mktemp -d -t codecov-checkout.XXXXXXXXXX)
post_command_hook="$PWD/hooks/post-command"
pre_exit_hook="$PWD/hooks/pre-exit"
function cleanup {
rm -rf "$tmp_dir"
}
trap cleanup EXIT
setup() {
export BUILDKITE_BUILD_CHECKOUT_PATH=$tmp_dir
cp ./pgp_keys.asc $tmp_dir
export BUILDKITE_JOB_ID=0
export BUILDKITE_COMMAND=my-command
export codecov_command="/tmp/codecov-buildkite-plugin/alpine/latest/codecov"
}
@test "Post-command succeeds" {
stub docker \
"run -e CODECOV_ENV -e CODECOV_TOKEN -e CODECOV_URL -e CODECOV_SLUG -e VCS_COMMIT_ID -e VCS_BRANCH_NAME -e VCS_PULL_REQUEST -e VCS_SLUG -e VCS_TAG -e CI_BUILD_URL -e CI_BUILD_ID -e CI_JOB_ID --label com.buildkite.job-id=${BUILDKITE_JOB_ID} --workdir=/workdir --volume=${BUILDKITE_BUILD_CHECKOUT_PATH}:/workdir --volume=/tmp:/tmp -it --rm buildpack-deps:jessie-scm bash -c '${codecov_command} ' : echo Ran Codecov in docker"
run "$post_command_hook"
assert_success
assert_output --partial "Ran Codecov in docker"
}
@test "Post-command succeeds with arguments" {
export BUILDKITE_PLUGIN_CODECOV_ARGS_0="-v"
export BUILDKITE_PLUGIN_CODECOV_ARGS_1="-F my_flag"
stub docker \
"run -e CODECOV_ENV -e CODECOV_TOKEN -e CODECOV_URL -e CODECOV_SLUG -e VCS_COMMIT_ID -e VCS_BRANCH_NAME -e VCS_PULL_REQUEST -e VCS_SLUG -e VCS_TAG -e CI_BUILD_URL -e CI_BUILD_ID -e CI_JOB_ID --label com.buildkite.job-id=${BUILDKITE_JOB_ID} --workdir=/workdir --volume=${BUILDKITE_BUILD_CHECKOUT_PATH}:/workdir --volume=/tmp:/tmp -it --rm buildpack-deps:jessie-scm bash -c '${codecov_command} -v -F my_flag' : echo Ran Codecov in docker"
run "$post_command_hook"
assert_success
assert_output --partial "Ran Codecov in docker"
}
@test "Post-command succeeds with custom docker image" {
export BUILDKITE_PLUGIN_CODECOV_DOCKER_IMAGE="my/library/buildpack-deps:jessie-scm"
stub docker \
"run -e CODECOV_ENV -e CODECOV_TOKEN -e CODECOV_URL -e CODECOV_SLUG -e VCS_COMMIT_ID -e VCS_BRANCH_NAME -e VCS_PULL_REQUEST -e VCS_SLUG -e VCS_TAG -e CI_BUILD_URL -e CI_BUILD_ID -e CI_JOB_ID --label com.buildkite.job-id=${BUILDKITE_JOB_ID} --workdir=/workdir --volume=${BUILDKITE_BUILD_CHECKOUT_PATH}:/workdir --volume=/tmp:/tmp -it --rm my/library/buildpack-deps:jessie-scm bash -c '${codecov_command} ' : echo Ran Codecov in docker"
run "$post_command_hook"
assert_success
assert_output --partial "Ran Codecov in docker"
}
@test "Post-command succeeds with custom PGP public key URL" {
export BUILDKITE_PLUGIN_CODECOV_PGP_PUBLIC_KEY_URL="https://keybase.io/codecovsecurity/pgp_keys.asc"
stub docker \
"run -e CODECOV_ENV -e CODECOV_TOKEN -e CODECOV_URL -e CODECOV_SLUG -e VCS_COMMIT_ID -e VCS_BRANCH_NAME -e VCS_PULL_REQUEST -e VCS_SLUG -e VCS_TAG -e CI_BUILD_URL -e CI_BUILD_ID -e CI_JOB_ID --label com.buildkite.job-id=${BUILDKITE_JOB_ID} --workdir=/workdir --volume=${BUILDKITE_BUILD_CHECKOUT_PATH}:/workdir --volume=/tmp:/tmp -it --rm buildpack-deps:jessie-scm bash -c '${codecov_command} ' : echo Ran Codecov in docker"
run "$post_command_hook"
assert_success
assert_output --partial "Ran Codecov in docker"
}
@test "Post-command succeeds with empty PGP public key URL" {
export BUILDKITE_PLUGIN_CODECOV_PGP_PUBLIC_KEY_URL=""
stub docker \
"run -e CODECOV_ENV -e CODECOV_TOKEN -e CODECOV_URL -e CODECOV_SLUG -e VCS_COMMIT_ID -e VCS_BRANCH_NAME -e VCS_PULL_REQUEST -e VCS_SLUG -e VCS_TAG -e CI_BUILD_URL -e CI_BUILD_ID -e CI_JOB_ID --label com.buildkite.job-id=${BUILDKITE_JOB_ID} --workdir=/workdir --volume=${BUILDKITE_BUILD_CHECKOUT_PATH}:/workdir --volume=/tmp:/tmp -it --rm buildpack-deps:jessie-scm bash -c '${codecov_command} ' : echo Ran Codecov in docker"
run "$post_command_hook"
assert_success
assert_output --partial "Ran Codecov in docker"
}
@test "Post-command succeeds with -Z" {
export BUILDKITE_PLUGIN_CODECOV_ARGS_0="-Z"
stub docker \
"run -e CODECOV_ENV -e CODECOV_TOKEN -e CODECOV_URL -e CODECOV_SLUG -e VCS_COMMIT_ID -e VCS_BRANCH_NAME -e VCS_PULL_REQUEST -e VCS_SLUG -e VCS_TAG -e CI_BUILD_URL -e CI_BUILD_ID -e CI_JOB_ID --label com.buildkite.job-id=${BUILDKITE_JOB_ID} --workdir=/workdir --volume=${BUILDKITE_BUILD_CHECKOUT_PATH}:/workdir --volume=/tmp:/tmp -it --rm buildpack-deps:jessie-scm bash -c '${codecov_command} -Z' : echo Ran Codecov in docker"
run "$post_command_hook"
assert_success
assert_output --partial "Ran Codecov in docker"
}
@test "Post-command is skipped if command failed and skip_on_fail=true" {
export BUILDKITE_PLUGIN_CODECOV_SKIP_ON_FAIL=true
export BUILDKITE_COMMAND_EXIT_STATUS=123
run "$post_command_hook"
assert_success
assert_output "Codecov upload is skipped because step failed with status ${BUILDKITE_COMMAND_EXIT_STATUS}"
}
@test "Pre-exit succeeds" {
cd "$BUILDKITE_BUILD_CHECKOUT_PATH"
stub docker \
"ps -a -q --filter label=com.buildkite.job-id=${BUILDKITE_JOB_ID} : echo my-container" \
"stop my-container : echo my-container stopped"
run "$pre_exit_hook"
assert_success
assert_output --partial "~~~ Cleaning up left-over container my-container"
assert_output --partial "my-container stopped"
}