Improve test coverage

This commit is contained in:
Peter Wilmott 2015-07-23 17:56:51 +01:00
parent 39ebf616c4
commit 6e6ee2d3b2
12 changed files with 103 additions and 16 deletions

2
.gitignore vendored
View File

@ -1,3 +1 @@
.vagrant/
base-image/
util-linux/

View File

@ -1,12 +0,0 @@
#!/usr/bin/env bash
exit_code=0
for t in test/test_*; do
bash "$t"
if [[ $? == 0 ]]; then
echo "PASSED: $t"
else
echo "FAILED: $t"
exit_code=1
fi
done
exit "$exit_code"

15
test Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env bash
exit_code=0
for t in tests/test_*; do
bash tests/teardown > /dev/null 2>&1
bash "$t" > /dev/null 2>&1
if [[ $? == 0 ]]; then
echo -e "\e[1;32mPASSED\e[0m : $t"
else
echo -e "\e[1;31mFAILED\e[0m : $t"
exit_code=1
fi
bash tests/teardown > /dev/null 2>&1
done
exit "$exit_code"

View File

@ -1,2 +0,0 @@
#!/usr/bin/env bash
[ "$(wc -l < bocker)" -le 100 ]

10
tests/teardown Normal file
View File

@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
for img in $(./bocker images | grep 'img'); do
./bocker rm "$img"
done
for ps in $(./bocker ps | grep 'ps' | awk '{print $1}'); do
./bocker rm "$ps"
done

21
tests/test_commit Normal file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
img="$(./bocker init ~/base-image | awk '{print $2}')"
./bocker images | grep -qw "$img"
[[ "$?" == 0 ]]
./bocker run "$img" which wget
ps="$(./bocker ps | grep 'which wget' | awk '{print $1}')"
logs="$(./bocker logs "$ps")"
./bocker rm "$ps"
[[ "$logs" == "which: no wget in"* ]]
./bocker run "$img" yum install -y wget
ps="$(./bocker ps | grep 'yum install -y wget' | awk '{print $1}')"
./bocker commit "$ps" "$img"
./bocker run "$img" which wget
ps="$(./bocker ps | grep 'which wget' | awk '{print $1}')"
logs="$(./bocker logs "$ps")"
[[ "$logs" == '/usr/bin/wget' ]]

4
tests/test_images Normal file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
[[ "$(./bocker images | head -n 1)" == 'IMAGE_ID' ]]

4
tests/test_init Normal file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
[[ "$(./bocker init ~/base-image)" == 'Created: img_'* ]]

5
tests/test_length Normal file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
[[ "$(wc -l < bocker)" -le 100 ]]; echo $?
[[ "$(wc -L < bocker)" -le 80 ]]; echo $?

4
tests/test_ps Normal file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
[[ "$(./bocker ps | head -n 1)" == 'CONTAINER_ID COMMAND' ]]

16
tests/test_rm Normal file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
img="$(./bocker init ~/base-image | awk '{print $2}')"
cmd="echo $RANDOM"
./bocker run "$img" "$cmd"
ps="$(./bocker ps | grep "$cmd" | awk '{print $1}')"
[[ "$(./bocker images | grep -c "$img")" == 1 ]]
[[ "$(./bocker ps | grep -c "$cmd")" == 1 ]]
./bocker rm "$img"
./bocker rm "$ps"
[[ "$(./bocker images | grep -c "$img")" == 0 ]]
[[ "$(./bocker ps | grep -c "$cmd")" == 0 ]]

24
tests/test_run Normal file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
function bocker_run_test() {
./bocker run "$1" "$2" > /dev/null
ps="$(./bocker ps | grep "$2" | awk '{print $1}')"
logs="$(./bocker logs "$ps")"
if [[ "$logs" == *"$3"* ]]; then
echo 0
else
echo 1
fi
}
img="$(./bocker init ~/base-image | awk '{print $2}')"
./bocker images | grep -qw "$img"
[[ "$?" == 0 ]]
[[ "$(bocker_run_test "$img" 'echo foo' 'foo')" == 0 ]]
[[ "$(bocker_run_test "$img" 'uname' 'Linux')" == 0 ]]
[[ "$(bocker_run_test "$img" 'cat /proc/self/stat' '3 (cat)')" == 0 ]]
[[ "$(bocker_run_test "$img" 'ip addr' 'veth1_ps_')" == 0 ]]
[[ "$(bocker_run_test "$img" 'ping -c 1 8.8.8.8' '0% packet loss')" == 0 ]]
[[ "$(bocker_run_test "$img" 'ping -c 1 google.com' '0% packet loss')" == 0 ]]