Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit 531f964

Browse files
author
David Chung
authored
Integration test to verify docker container builds (#348)
Signed-off-by: David Chung <[email protected]>
1 parent f1db170 commit 531f964

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ build-docker:
5050
@docker build ${DOCKER_BUILD_FLAGS} \
5151
-t ${DOCKER_IMAGE}:${DOCKER_TAG} \
5252
-f ${CURDIR}/dockerfiles/Dockerfile.bundle .
53+
@echo "Running tests -- scripts/container-test to verify the binaries"
54+
@scripts/container-test
5355
ifeq (${DOCKER_PUSH},true)
5456
@docker push ${DOCKER_IMAGE}:${DOCKER_TAG}
5557
ifeq (${DOCKER_TAG_LATEST},true)

scripts/container-test

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
7+
cd "$HERE/.."
8+
9+
10+
TEST_DIR=$(pwd)/container-test
11+
DOCKER_IMAGE="${DOCKER_IMAGE:-infrakit/devbundle}"
12+
DOCKER_TAG="${DOCKER_TAG:-dev}"
13+
14+
cleanup() {
15+
docker ps | grep devbundle | awk '{print $1}' | xargs docker stop
16+
rm -rf $TEST_DIR
17+
}
18+
trap cleanup EXIT
19+
20+
mkdir -p $TEST_DIR/plugins
21+
mkdir -p $TEST_DIR/tutorial
22+
23+
volumes="-v $TEST_DIR:/root -v $PWD/docs:/root/docs"
24+
25+
# set the environment variable to use a shorter path so we don't have
26+
# problems with Docker for Mac. See https://github.com/docker/docker/issues/23545
27+
envs="-e INFRAKIT_PLUGINS_DIR=/root"
28+
29+
server() {
30+
docker run -d --rm --name $1 $envs $volumes $DOCKER_IMAGE:$DOCKER_TAG $@
31+
}
32+
33+
run() {
34+
docker run --rm $envs $volumes $DOCKER_IMAGE:$DOCKER_TAG $@
35+
}
36+
37+
server infrakit-instance-file --dir /root/tutorial/
38+
server infrakit-group-default --poll-interval 500ms
39+
server infrakit-flavor-vanilla
40+
41+
sleep 1
42+
43+
expect_exact_output() {
44+
message=$1
45+
cmd=$2
46+
expected_output=$3
47+
48+
actual_output="$($2)"
49+
echo -n "--> $message: "
50+
if [ "$actual_output" = "$3" ]
51+
then
52+
echo 'PASS'
53+
else
54+
echo 'FAIL'
55+
echo "Expected output: $expected_output"
56+
echo "Actual output: $actual_output"
57+
exit 1
58+
fi
59+
}
60+
61+
expect_output_lines() {
62+
message=$1
63+
cmd=$2
64+
expected_lines=$3
65+
66+
actual_line_count=$($2 | wc -l)
67+
echo -n "--> $message: "
68+
if [ "$actual_line_count" -eq "$3" ]
69+
then
70+
echo 'PASS'
71+
else
72+
echo 'FAIL'
73+
echo "Expected line count: $expected_lines"
74+
echo "Actual line count: $actual_line_count"
75+
exit 1
76+
fi
77+
}
78+
79+
expect_output_lines "3 plugins should be discoverable" "run infrakit plugin ls -q" "3"
80+
81+
expect_output_lines "0 instances should exist" "run infrakit instance describe -q --name instance-file" "0"
82+
83+
run infrakit group commit /root/docs/cattle.json
84+
85+
echo 'Waiting for group to be provisioned'
86+
sleep 2
87+
88+
expect_output_lines "5 instances should exist in group" "run infrakit group describe cattle -q" "5"
89+
expect_output_lines "5 instances should exist" "run infrakit instance describe -q --name instance-file" "5"
90+
91+
run infrakit group free cattle
92+
run infrakit group commit /root/docs/cattle.json
93+
94+
expect_exact_output "Should be watching one group" "run infrakit group ls -q" "cattle"
95+
96+
expect_exact_output \
97+
"Update should roll 5 and scale group to 10" \
98+
"run infrakit group commit /root/docs/cattle2.json --pretend" \
99+
"Committing cattle would involve: Performing a rolling update on 5 instances, then adding 5 instances to increase the group size to 10"
100+
101+
run infrakit group commit /root/docs/cattle2.json
102+
103+
sleep 5
104+
105+
expect_output_lines "10 instances should exist in group" "run infrakit group describe cattle -q" "10"
106+
107+
# Terminate 3 instances.
108+
pushd $TEST_DIR/tutorial
109+
rm $(ls | head -3)
110+
popd
111+
112+
sleep 5
113+
114+
expect_output_lines "10 instances should exist in group" "run infrakit group describe cattle -q" "10"
115+
116+
run infrakit group destroy cattle
117+
expect_output_lines "0 instances should exist" "run infrakit instance describe -q --name instance-file" "0"
118+
119+
echo 'ALL TESTS PASSED'

0 commit comments

Comments
 (0)