Add input checks to exec; Make exec's grep more robust; Added tests for exec

This commit is contained in:
Peter Wilmott
2015-08-05 20:09:25 +01:00
parent 25029b4f07
commit 7911226036
2 changed files with 31 additions and 7 deletions

23
tests/test_exec Normal file
View File

@@ -0,0 +1,23 @@
#!/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 ]]
# ▼ ▼ ▼ Race condition waiting to happen ▼ ▼ ▼
./bocker run "$img" "sleep 5 && ps aux" &
sleep 2
ps="$(./bocker ps | grep 'sleep 5' | awk '{print $1}')"
exec="$(./bocker exec "$ps" ps aux | wc -l)"
[[ "$exec" == "4" ]]
sleep 3
# ▲ ▲ ▲ Race condition waiting to happen ▲ ▲ ▲
./bocker run "$img" ps aux
ps="$(./bocker ps | grep 'ps aux' | awk '{print $1}')"
exec="$(./bocker exec "$ps" ps aux)" || true
[[ "$exec" == "Container '$ps' exists but is not running" ]]
exec="$(./bocker exec foo ps aux)" || true
[[ "$exec" == "No container named 'foo' exists" ]]