From ee61f07d9b8efe463c62cc7d74926c8e4c9b98f6 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 15 Jun 2015 21:41:43 +0100 Subject: [PATCH] refactor: extract rm_containers helper cherry-picked from #898 --- test/260_dns_removal_test.sh | 2 +- test/270_use_name_as_hostname_test.sh | 2 +- test/config.sh | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/test/260_dns_removal_test.sh b/test/260_dns_removal_test.sh index 3816a474..9a1ffdb8 100755 --- a/test/260_dns_removal_test.sh +++ b/test/260_dns_removal_test.sh @@ -10,7 +10,7 @@ DOPTS="--name=c2 -h $NAME" check() { assert_dns_record $HOST1 c1 $NAME $C2 - docker_on $HOST1 rm -f c2 >/dev/null + rm_containers $HOST1 c2 assert_no_dns_record $HOST1 c1 $NAME } diff --git a/test/270_use_name_as_hostname_test.sh b/test/270_use_name_as_hostname_test.sh index c58fc254..a7b4ce44 100755 --- a/test/270_use_name_as_hostname_test.sh +++ b/test/270_use_name_as_hostname_test.sh @@ -17,7 +17,7 @@ assert_expected_fqdn() { shift start_container_with_dns $HOST1 "$@" assert "docker_inspect_fqdn $HOST1 $NAME" $EXPECTED_FQDN - docker_on $HOST1 rm -f $NAME >/dev/null + rm_containers $HOST1 $NAME } start_suite "Use container name as hostname" diff --git a/test/config.sh b/test/config.sh index 5efbf5e7..812dde27 100644 --- a/test/config.sh +++ b/test/config.sh @@ -111,6 +111,12 @@ start_container_with_dns() { weave_on $host run --with-dns "$@" -t $DNS_IMAGE /bin/sh } +rm_containers() { + host=$1 + shift + [ $# -eq 0 ] || docker_on $host rm -f "$@" >/dev/null +} + container_ip() { weave_on $1 ps $2 | grep -o -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' } @@ -155,8 +161,7 @@ assert_dns_ptr_record() { start_suite() { for host in $HOST1 $HOST2; do [ -z "$DEBUG" ] || echo "Cleaning up on $host: removing all containers and resetting weave" - containers=$(docker_on $host ps -aq 2>/dev/null) - [ -n "$containers" ] && docker_on $host rm -f $containers >/dev/null 2>&1 + rm_containers $host $(docker_on $host ps -aq 2>/dev/null) weave_on $host reset 2>/dev/null done whitely echo "$@"