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 4, 2017
1 parent e7f3063 commit 72befc4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
11 changes: 8 additions & 3 deletions libkv/libkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import (
"strconv"
"time"

yaml "gopkg.in/yaml.v2"

"github.com/blang/vfs"
"github.com/docker/libkv"
"github.com/docker/libkv/store"
"github.com/docker/libkv/store/boltdb"
"github.com/docker/libkv/store/consul"
"github.com/hairyhenderson/gomplate"
"github.com/hairyhenderson/gomplate/env"
"github.com/hairyhenderson/gomplate/vault"
consulapi "github.com/hashicorp/consul/api"
Expand Down Expand Up @@ -116,9 +117,13 @@ func setupConsul(url *url.URL, enableTLS bool) (*SetupDetails, error) {
return nil, err
}

decoded := &gomplate.TypeConv{}.JSON(string(data))
decoded := make(map[string]interface{})
err = yaml.Unmarshal(data, &decoded)
if err != nil {
return nil, err
}

var token = decoded.token
var token = decoded["token"].(string)

client.Logout()

Expand Down
13 changes: 13 additions & 0 deletions test/integration/datasources_consul.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function setup () {
function teardown () {
rm -rf $tmpdir
consul kv delete foo
vault unmount consul
}

@test "Testing consul" {
Expand All @@ -33,3 +34,15 @@ function teardown () {
[ "$status" -eq 0 ]
[[ "${output}" == "$BATS_TEST_DESCRIPTION" ]]
}

@test "Consul datasource works with hostname in URL" {
vault mount consul
vault write consul/config/access address=127.0.0.1:8500 token=${CONSUL_ROOT_TOKEN}
POLICY='key "" { policy = "read" }'
echo $POLICY | base64 | vault write consul/roles/readonly policy=-
consul kv put foo "$BATS_TEST_DESCRIPTION"
unset CONSUL_HTTP_ADDR
CONSUL_VAULT_ROLE=readonly gomplate -d consul=consul:// -i '{{(datasource "consul" "foo")}}'
[ "$status" -eq 0 ]
[[ "${output}" == "$BATS_TEST_DESCRIPTION" ]]
}
7 changes: 6 additions & 1 deletion test/integration/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ export VAULT_ROOT_TOKEN=00000000-1111-2222-3333-444455556666
vault server -dev -dev-root-token-id=${VAULT_ROOT_TOKEN} -log-level=err >&/dev/null &

export CONSUL_HTTP_ADDR=http://127.0.0.1:8500
export CONSUL_ROOT_TOKEN=00000000-1111-2222-3333-444455556666

consul agent -dev -log-level=err >&/dev/null &
tmpdir=$(mktemp -d)
echo "{\"acl_datacenter\": \"dc1\", \"acl_master_token\": \"${CONSUL_ROOT_TOKEN}\"}" >> $tmpdir/config.json
consul agent -dev -config-file=$tmpdir/config.json -log-level=err >&/dev/null &
sleep 2
rm -rf $tmpdir

bats $(dirname $0)

0 comments on commit 72befc4

Please sign in to comment.