Skip to content

Commit

Permalink
Refactor integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
okushchenko committed Nov 20, 2017
1 parent dfd08bf commit 6a913de
Show file tree
Hide file tree
Showing 21 changed files with 116 additions and 50 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ before_install:
- sudo mv etcd-v${ETCD_VERSION}-linux-amd64/etcdctl /bin/
- etcd &
# install DynamoDB
- sudo pip install awscli
- mkdir /tmp/dynamodb
- wget -O - https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_${DYNAMODB_VERSION}.tar.gz | tar xz --directory /tmp/dynamodb
- java -Djava.library.path=/tmp/dynamodb/DynamoDBLocal_lib -jar /tmp/dynamodb/DynamoDBLocal.jar -inMemory &
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ test:

integration:
@echo "Running integration tests..."
@find ./integration -name test.sh -exec bash {} \;
@for i in `find ./integration -name test.sh`; do \
echo "Running $$i"; \
bash $$i || exit 1; \
bash integration/expect/check.sh || exit 1; \
rm /tmp/confd-*; \
done

dep:
@dep ensure
Expand Down
10 changes: 5 additions & 5 deletions integration/confdir/templates/basic.conf.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
hostname: {{getenv "HOSTNAME"}}
hostname: {{ getenv "HOSTNAME" }}
[database]
host={{getv "/database/host"}}
password={{getv "/database/password"}}
port={{getv "/database/port"}}
username={{getv "/database/username"}}
host={{ getv "/database/host" }}
password={{ getv "/database/password" }}
port={{ getv "/database/port" }}
username={{ getv "/database/username" }}
10 changes: 2 additions & 8 deletions integration/confdir/templates/exists-test.conf.tmpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
{{if exists "/key"}}
value: {{getv "/key"}}
{{end}}

{{if exists "/doesnotexist"}}
This line will not be printed
value: {{getv "/key"}}
{{end}}
{{ if exists "/key" }}value: {{ getv "/key" }}{{ end }}
{{- if exists "/doesnotexist" }}This line will not be printed value: {{ getv "/key" }}{{ end }}
6 changes: 3 additions & 3 deletions integration/confdir/templates/iteration.conf.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
upstream app {
{{range gets "/upstream/*"}}
server {{.Value}};
{{end}}
{{- range gets "/upstream/*" }}
server {{ .Value }};
{{- end }}
}

server {
Expand Down
10 changes: 5 additions & 5 deletions integration/confdir/templates/nested.conf.tmpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
upstream app {
{{range gets "/nested/*"}}
{{range gets .Key}}
server {{.Value}};
{{end}}
{{end}}
{{ range gets "/nested/*" }}
{{ range gets .Key }}
server {{ .Value }};
{{ end }}
{{ end }}
}

server {
Expand Down
13 changes: 13 additions & 0 deletions integration/consul/test.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
#!/bin/bash

export HOSTNAME="localhost"

# Configure consul
curl -X PUT http://127.0.0.1:8500/v1/kv/key -d 'foobar'
curl -X PUT http://127.0.0.1:8500/v1/kv/database/host -d '127.0.0.1'
curl -X PUT http://127.0.0.1:8500/v1/kv/database/password -d 'p@sSw0rd'
curl -X PUT http://127.0.0.1:8500/v1/kv/database/port -d '3306'
curl -X PUT http://127.0.0.1:8500/v1/kv/database/username -d 'confd'
curl -X PUT http://127.0.0.1:8500/v1/kv/upstream/app1 -d '10.0.1.10:8080'
curl -X PUT http://127.0.0.1:8500/v1/kv/upstream/app2 -d '10.0.1.11:8080'
curl -X PUT http://127.0.0.1:8500/v1/kv/nested/east/app1 -d '10.0.1.10:8080'
curl -X PUT http://127.0.0.1:8500/v1/kv/nested/west/app2 -d '10.0.1.11:8080'
curl -X PUT http://127.0.0.1:8500/v1/kv/prefix/database/host -d '127.0.0.1'
curl -X PUT http://127.0.0.1:8500/v1/kv/prefix/database/password -d 'p@sSw0rd'
curl -X PUT http://127.0.0.1:8500/v1/kv/prefix/database/port -d '3306'
curl -X PUT http://127.0.0.1:8500/v1/kv/prefix/database/username -d 'confd'
curl -X PUT http://127.0.0.1:8500/v1/kv/prefix/upstream/app1 -d '10.0.1.10:8080'
curl -X PUT http://127.0.0.1:8500/v1/kv/prefix/upstream/app2 -d '10.0.1.11:8080'
curl -X PUT http://127.0.0.1:8500/v1/kv/prefix/nested/east/app1 -d '10.0.1.10:8080'
curl -X PUT http://127.0.0.1:8500/v1/kv/prefix/nested/west/app2 -d '10.0.1.11:8080'

# Run confd
confd --onetime --log-level debug --confdir ./integration/confdir --backend consul --node 127.0.0.1:8500
11 changes: 6 additions & 5 deletions integration/dynamodb/test.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/bin/bash

export DYNAMODB_LOCAL=1
export AWS_ACCESS_KEY_ID=foo
export AWS_SECRET_ACCESS_KEY=bar
export AWS_REGION=eu-west-1
export AWS_DEFAULT_REGION=eu-west-1
export HOSTNAME="localhost"
export DYNAMODB_LOCAL="1"
export AWS_ACCESS_KEY_ID="foo"
export AWS_SECRET_ACCESS_KEY="bar"
export AWS_REGION="eu-west-1"
export AWS_DEFAULT_REGION="eu-west-1"

aws dynamodb create-table \
--region eu-west-1 --table-name confd \
Expand Down
1 change: 1 addition & 0 deletions integration/env/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

export HOSTNAME="localhost"
export KEY="foobar"
export DATABASE_HOST="127.0.0.1"
export DATABASE_PASSWORD="p@sSw0rd"
Expand Down
3 changes: 2 additions & 1 deletion integration/etcd/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

export HOSTNAME="localhost"

curl -L -X PUT http://127.0.0.1:2379/v2/keys/key -d value=foobar
curl -L -X PUT http://127.0.0.1:2379/v2/keys/database/host -d value=127.0.0.1
curl -L -X PUT http://127.0.0.1:2379/v2/keys/database/password -d value=p@sSw0rd
Expand All @@ -18,6 +20,5 @@ curl -L -X PUT http://127.0.0.1:2379/v2/keys/prefix/upstream/app2 -d value=10.0.
curl -L -X PUT http://127.0.0.1:2379/v2/keys/prefix/nested/east/app1 -d value=10.0.1.10:8080
curl -L -X PUT http://127.0.0.1:2379/v2/keys/prefix/nested/west/app2 -d value=10.0.1.11:8080


# Run confd
confd --onetime --log-level debug --confdir ./integration/confdir --backend etcd --node http://127.0.0.1:2379 --watch
28 changes: 15 additions & 13 deletions integration/etcdv3/test.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#!/bin/bash

ETCDCTL_API=3 etcdctl put /key foobar
ETCDCTL_API=3 etcdctl put /database/host 127.0.0.1
ETCDCTL_API=3 etcdctl put /database/password p@sSw0rd
ETCDCTL_API=3 etcdctl put /database/port 3306
ETCDCTL_API=3 etcdctl put /database/username confd
ETCDCTL_API=3 etcdctl put /upstream/app1 10.0.1.10:8080
ETCDCTL_API=3 etcdctl put /upstream/app2 10.0.1.11:8080
ETCDCTL_API=3 etcdctl put /prefix/database/host 127.0.0.1
ETCDCTL_API=3 etcdctl put /prefix/database/password p@sSw0rd
ETCDCTL_API=3 etcdctl put /prefix/database/port 3306
ETCDCTL_API=3 etcdctl put /prefix/database/username confd
ETCDCTL_API=3 etcdctl put /prefix/upstream/app1 10.0.1.10:8080
ETCDCTL_API=3 etcdctl put /prefix/upstream/app2 10.0.1.11:8080
export HOSTNAME="localhost"
export ETCDCTL_API="3"

etcdctl put /key foobar
etcdctl put /database/host 127.0.0.1
etcdctl put /database/password p@sSw0rd
etcdctl put /database/port 3306
etcdctl put /database/username confd
etcdctl put /upstream/app1 10.0.1.10:8080
etcdctl put /upstream/app2 10.0.1.11:8080
etcdctl put /prefix/database/host 127.0.0.1
etcdctl put /prefix/database/password p@sSw0rd
etcdctl put /prefix/database/port 3306
etcdctl put /prefix/database/username confd
etcdctl put /prefix/upstream/app1 10.0.1.10:8080
etcdctl put /prefix/upstream/app2 10.0.1.11:8080

# Run confd
confd --onetime --log-level debug --confdir ./integration/confdir --backend etcdv3 --node http://127.0.0.1:2379 --watch
6 changes: 6 additions & 0 deletions integration/expect/basic.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
hostname: localhost
[database]
host=127.0.0.1
password=p@sSw0rd
port=3306
username=confd
6 changes: 6 additions & 0 deletions integration/expect/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -ex

diff /tmp/confd-basic-test.conf integration/expect/basic.conf
diff /tmp/confd-exists-test.conf integration/expect/exists-test.conf
diff /tmp/confd-iteration-test.conf integration/expect/iteration.conf
1 change: 1 addition & 0 deletions integration/expect/exists-test.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
value: foobar
15 changes: 15 additions & 0 deletions integration/expect/iteration.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
upstream app {
server 10.0.1.10:8080;
server 10.0.1.11:8080;
}

server {
server_name www.example.com;
location / {
proxy_pass http://app;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
2 changes: 2 additions & 0 deletions integration/file/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

export HOSTNAME="localhost"

cat <<EOT >> test.yaml
key: foobar
database:
Expand Down
2 changes: 2 additions & 0 deletions integration/rancher/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

export HOSTNAME="localhost"

cat > ./rancher-answers.json<<EOF
{
"2015-07-25": {
Expand Down
12 changes: 12 additions & 0 deletions integration/redis/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

export HOSTNAME="localhost"

redis-cli set /key foobar
redis-cli set /database/host 127.0.0.1
redis-cli set /database/password p@sSw0rd
Expand All @@ -20,5 +22,15 @@ if [ $? -eq 0 ]
then
exit 1
fi

confd --onetime --log-level debug --confdir ./integration/confdir --interval 5 --backend redis --node 127.0.0.1:6379
if [ $? -ne 0 ]
then
exit 1
fi

confd --onetime --log-level debug --confdir ./integration/confdir --interval 5 --backend redis --node 127.0.0.1:6379/0
if [ $? -ne 0 ]
then
exit 1
fi
13 changes: 7 additions & 6 deletions integration/ssm/test.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/bin/bash

export SSM_LOCAL=1
export AWS_ACCESS_KEY_ID=foo
export AWS_SECRET_ACCESS_KEY=bar
export AWS_DEFAULT_REGION=us-east-1
export AWS_REGION=us-east-1
export SSM_ENDPOINT_URL=http://localhost:8001
export HOSTNAME="localhost"
export SSM_LOCAL="1"
export AWS_ACCESS_KEY_ID="foo"
export AWS_SECRET_ACCESS_KEY="bar"
export AWS_DEFAULT_REGION="us-east-1"
export AWS_REGION="us-east-1"
export SSM_ENDPOINT_URL="http://localhost:8001"

aws ssm put-parameter --name "/key" --type "String" --value "foobar" --endpoint-url $SSM_ENDPOINT_URL
aws ssm put-parameter --name "/database/host" --type "String" --value "127.0.0.1" --endpoint-url $SSM_ENDPOINT_URL
Expand Down
5 changes: 3 additions & 2 deletions integration/vault/test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
set -e
ROOT_TOKEN=$(vault read -field id auth/token/lookup-self)

export HOSTNAME="localhost"
export ROOT_TOKEN="$(vault read -field id auth/token/lookup-self)"

vault mount -path database generic
vault mount -path key generic
Expand Down
4 changes: 3 additions & 1 deletion integration/zookeeper/test.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/bin/bash

export HOSTNAME="localhost"

# feed zookeeper
export ZK_PATH="`dirname \"$0\"`"
sh -c "cd $ZK_PATH ; go run main.go"
sh -c "cd $ZK_PATH; go run main.go"

# Run confd
confd --onetime --log-level debug --confdir ./integration/confdir --interval 5 --backend zookeeper --node 127.0.0.1:2181 -watch

0 comments on commit 6a913de

Please sign in to comment.