-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.sh
executable file
·57 lines (44 loc) · 1.26 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# Usage: ./test.sh ami-b13170d4
set -exo pipefail
ami_id=${1}
finish() {
code=$?
# Bring down the AWS instance
summon env AMI_ID=${ami_id} bash -c 'docker run \
--rm \
-v "$(pwd)":/opt/ \
-w /opt/ \
-e AMI_ID \
-e AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY \
-v "$SSH_KEY:/root/.ssh/id_rsa" \
test-kitchen kitchen destroy'
return ${code}
}
trap finish EXIT
# Create a Test Kitchen container
docker build -t test-kitchen -f Dockerfile.testkitchen .
echo "Launching test instance from ${ami_id}"
# Converge Test Kitchen to bring up the AL2 instance in AWS
summon env AMI_ID=${ami_id} bash -c 'docker run \
--rm \
-v "$(pwd)":/opt/ \
-w /opt/ \
-e AMI_ID \
-e AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY \
-v "$SSH_KEY:/root/.ssh/id_rsa" \
test-kitchen kitchen converge'
echo "Testing health endpoint"
public_hostname=$(cat .kitchen/default-amazon-linux-2.yml | grep hostname | awk -F ' ' '{print $2}')
sleep 5
response_code=$(curl -k -s -o health.response -w "%{http_code}" https://${public_hostname}/health)
if [ "${response_code}" != "200" ]; then
echo "Expected 200"
echo "Got ${response_code}"
echo "-----"
echo "$(cat health.response)"
exit 1
fi
echo "PASSED!"