This repository was archived by the owner on Dec 26, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +53
-4
lines changed Expand file tree Collapse file tree 2 files changed +53
-4
lines changed Original file line number Diff line number Diff line change @@ -19,10 +19,9 @@ steps:
19
19
command :
20
20
- make lint-plugin
21
21
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
26
25
27
26
- label : " :buildkite::vault: Run Plugin 1"
28
27
command : echo 'Hello World'
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments