Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit 436dc41

Browse files
Add a couple plugin tests
This just adds a "happy path" test, and a test that ensures that we specify at least one secret. Signed-off-by: Christopher Maier <[email protected]>
1 parent 0ab68db commit 436dc41

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

.buildkite/pipeline.verify.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ steps:
1919
command:
2020
- make lint-plugin
2121

22-
# TODO: Add some unit tests!
23-
# - label: ":lint-roller::buildkite: Test Plugin"
24-
# command:
25-
# - make test-plugin
22+
- label: ":lint-roller::buildkite: Test Plugin"
23+
command:
24+
- make test-plugin
2625

2726
- label: ":buildkite::vault: Run Plugin 1"
2827
command: echo 'Hello World'

tests/environment.bats

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bats
2+
3+
load "$BATS_PLUGIN_PATH/load.bash"
4+
5+
# Uncomment to enable stub debugging
6+
# export DOCKER_STUB_DEBUG=/dev/tty
7+
8+
setup() {
9+
export DEFAULT_IMAGE=hashicorp/envconsul
10+
export DEFAULT_TAG=latest
11+
12+
export VAULT_TOKEN=testingtoken
13+
export VAULT_ADDR=default.vault.mycompany.com:8200
14+
export VAULT_NAMESPACE=default_namespace
15+
16+
export BUILDKITE_JOB_ID=2112
17+
}
18+
19+
teardown() {
20+
unset VAULT_TOKEN
21+
unset VAULT_ADDR
22+
unset VAULT_NAMESPACE
23+
24+
unset BUILDKITE_PLUGIN_VAULT_ENV_SECRETS_0
25+
}
26+
27+
@test "The happy path works" {
28+
export BUILDKITE_PLUGIN_VAULT_ENV_SECRETS_0="foo"
29+
30+
docker_vault_cmd="run --env VAULT_TOKEN --name=vault-env-plugin-${BUILDKITE_JOB_ID} -- ${DEFAULT_IMAGE}:${DEFAULT_TAG}"
31+
32+
stub docker \
33+
"${docker_vault_cmd} -secret=foo -once -upcase -pristine -no-prefix=true -vault-addr=${VAULT_ADDR} -vault-namespace=${VAULT_NAMESPACE} -vault-renew-token=false -vault-retry-attempts=1 env : echo 'foo=something_very_secret'" \
34+
"container rm --force vault-env-plugin-2112 : echo 'removing'"
35+
36+
run "${PWD}/hooks/environment"
37+
assert_success
38+
39+
unstub docker
40+
}
41+
42+
@test "Fails if no secrets are specified" {
43+
44+
unset BUILDKITE_PLUGIN_VAULT_ENV_SECRETS_0
45+
46+
run "${PWD}/hooks/environment"
47+
assert_failure
48+
49+
assert_output --partial "At least one secret must be specified"
50+
}

0 commit comments

Comments
 (0)