From bca0e2e8c25bef8e579815ddd3ba4dbf33b91d95 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Tue, 5 May 2015 14:05:19 -0700 Subject: [PATCH] integration: cleanup discovery tests Signed-off-by: Andrea Luzzardi --- ...file-discovery.bats => discovery-file.bats} | 7 +++++-- ...ken-discovery.bats => discovery-token.bats} | 17 ++++++++++------- .../{zk-discovery.bats => discovery-zk.bats} | 18 +++++++++++------- test/integration/helpers.bash | 2 +- 4 files changed, 27 insertions(+), 17 deletions(-) rename test/integration/{file-discovery.bats => discovery-file.bats} (95%) rename test/integration/{token-discovery.bats => discovery-token.bats} (66%) rename test/integration/{zk-discovery.bats => discovery-zk.bats} (65%) diff --git a/test/integration/file-discovery.bats b/test/integration/discovery-file.bats similarity index 95% rename from test/integration/file-discovery.bats rename to test/integration/discovery-file.bats index d2ca80a658..15325e8b4c 100644 --- a/test/integration/file-discovery.bats +++ b/test/integration/discovery-file.bats @@ -5,10 +5,14 @@ load helpers # create a blank temp file for discovery DISCOVERY_FILE=$(mktemp) +function setup() { + start_docker 2 +} + function teardown() { swarm_manage_cleanup - rm -f $DISCOVERY_FILE stop_docker + rm -f $DISCOVERY_FILE } function setup_file_discovery() { @@ -18,7 +22,6 @@ function setup_file_discovery() { } @test "file discovery" { - start_docker 2 setup_file_discovery swarm_manage file://$DISCOVERY_FILE diff --git a/test/integration/token-discovery.bats b/test/integration/discovery-token.bats similarity index 66% rename from test/integration/token-discovery.bats rename to test/integration/discovery-token.bats index 126424ca20..a7c143e4dc 100644 --- a/test/integration/token-discovery.bats +++ b/test/integration/discovery-token.bats @@ -6,6 +6,10 @@ function token_cleanup() { curl -X DELETE https://discovery-stage.hub.docker.com/v1/clusters/$1 } +function setup() { + start_docker 2 +} + function teardown() { swarm_join_cleanup swarm_manage_cleanup @@ -13,18 +17,17 @@ function teardown() { } @test "token discovery" { - start_docker 2 - - TOKEN=$(swarm create) + run swarm create [ "$status" -eq 0 ] - [[ ${TOKEN} =~ ^[0-9a-f]{32}$ ]] + [[ "$output" =~ ^[0-9a-f]{32}$ ]] + TOKEN="$output" - swarm_manage token://$TOKEN - swarm_join token://$TOKEN + swarm_manage "token://$TOKEN" + swarm_join "token://$TOKEN" run docker_swarm info echo $output [[ "$output" == *"Nodes: 2"* ]] - token_cleanup $TOKEN + token_cleanup "$TOKEN" } diff --git a/test/integration/zk-discovery.bats b/test/integration/discovery-zk.bats similarity index 65% rename from test/integration/zk-discovery.bats rename to test/integration/discovery-zk.bats index c21f3daed7..49c245bfc0 100644 --- a/test/integration/zk-discovery.bats +++ b/test/integration/discovery-zk.bats @@ -9,11 +9,18 @@ ZK_HOST=127.0.0.1:$(( ( RANDOM % 1000 ) + 7000 )) ZK_CONTAINER_NAME=swarm_integration_zk function start_zk() { - docker_host run --name $ZK_CONTAINER_NAME -p $ZK_HOST:2181 -d jplock/zookeeper + run docker run --name $ZK_CONTAINER_NAME -p $ZK_HOST:2181 -d jplock/zookeeper + [ "$status" -eq 0 ] } function stop_zk() { - docker_host rm -f -v $ZK_CONTAINER_NAME > /dev/null + run docker rm -f -v $ZK_CONTAINER_NAME + [ "$status" -eq 0 ] +} + +function setup() { + start_zk + start_docker 2 } function teardown() { @@ -23,13 +30,10 @@ function teardown() { stop_zk } -@test "zk discovery" { - start_zk - start_docker 1 - +@test "zookeeperk discovery" { swarm_manage zk://${ZK_HOST}/test swarm_join zk://${ZK_HOST}/test run docker_swarm info - [[ "$output" == *"Nodes: 1"* ]] + [[ "$output" == *"Nodes: 2"* ]] } diff --git a/test/integration/helpers.bash b/test/integration/helpers.bash index 76e85a7798..14197c291b 100644 --- a/test/integration/helpers.bash +++ b/test/integration/helpers.bash @@ -105,7 +105,7 @@ function swarm_join() { # Stops the manager. function swarm_manage_cleanup() { - kill $SWARM_PID + kill $SWARM_PID || true } # Clean up Swarm join processes