Skip to content

Commit

Permalink
Add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
stuart-c committed Aug 6, 2017
1 parent a0d9504 commit 243ebbf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
14 changes: 13 additions & 1 deletion test/integration/datasources_consul.bats
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ function setup () {
}

function teardown () {
export CONSUL_HTTP_ADDR=http://127.0.0.1:8501
consul kv delete foo
unset CONSUL_HTTP_ADDR
vault unmount consul
stop_consul
}

Expand All @@ -35,3 +36,14 @@ function teardown () {
[ "$status" -eq 0 ]
[[ "${output}" == "$BATS_TEST_DESCRIPTION" ]]
}

@test "Consul datasource works with Vault auth" {
vault mount consul
vault write consul/config/access address=127.0.0.1:8501 token=${CONSUL_ROOT_TOKEN}
POLICY='key "" { policy = "read" }'
vault write consul/roles/readonly policy=`echo $POLICY | base64`
consul kv put foo "$BATS_TEST_DESCRIPTION"
CONSUL_VAULT_ROLE=readonly gomplate -d consul=consul:// -i '{{(datasource "consul" "foo")}}'
[ "$status" -eq 0 ]
[[ "${output}" == "$BATS_TEST_DESCRIPTION" ]]
}
7 changes: 5 additions & 2 deletions test/integration/helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ function start_consul () {
fi
PID_FILE=/tmp/gomplate-test-consul.pid
rm -f $PID_FILE || true
consul agent -dev -log-level=err -http-port=$port -pid-file=$PID_FILE >/dev/null &
export CONSUL_ROOT_TOKEN=00000000-1111-2222-3333-444455556666
echo "{\"acl_datacenter\": \"dc1\", \"acl_master_token\": \"${CONSUL_ROOT_TOKEN}\"}" >> /tmp/gomplate-test-consul.json
consul agent -dev -config-file=/tmp/gomplate-test-consul.json -log-level=err -http-port=$port -pid-file=$PID_FILE >/dev/null &
wait_for_url http://127.0.0.1:$port/v1/status/leader
}

function stop_consul () {
PID_FILE=/tmp/gomplate-test-consul.pid
kill $(cat $PID_FILE) &>/dev/null
}
rm /tmp/gomplate-test-consul.json
}

0 comments on commit 243ebbf

Please sign in to comment.