diff --git a/test/integration/core/certs-extra-san.bats b/test/integration/core/certs-extra-san.bats index 4973fb5259..8e32080c04 100644 --- a/test/integration/core/certs-extra-san.bats +++ b/test/integration/core/certs-extra-san.bats @@ -2,6 +2,9 @@ load ${BASE_TEST_DIR}/helpers.bash +if [[ -z "$NAME" ]]; then + export NAME="$(unique_machine_name)" +fi @test "$DRIVER: create" { run machine create --tls-san foo.bar.tld --tls-san 10.42.42.42 -d $DRIVER $NAME diff --git a/test/integration/core/core-commands.bats b/test/integration/core/core-commands.bats index 7615ad1274..43e8bd246c 100644 --- a/test/integration/core/core-commands.bats +++ b/test/integration/core/core-commands.bats @@ -2,17 +2,15 @@ load ${BASE_TEST_DIR}/helpers.bash +if [[ -z "$NAME" ]]; then + export NAME="$(shared_machine_name)" +fi + @test "$DRIVER: machine should not exist" { - run machine inspect $NAME + run machine inspect UNKNOWN echo ${output} [ "$status" -eq 1 ] - [[ ${lines[0]} =~ "Host does not exist: \"$NAME\"" ]] -} - -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME - echo ${output} - [ "$status" -eq 0 ] + [[ ${lines[0]} =~ "Host does not exist: \"UNKNOWN\"" ]] } @test "$DRIVER: appears with ls" { diff --git a/test/integration/core/engine-options.bats b/test/integration/core/engine-options.bats index 8f74098533..c338dc0755 100644 --- a/test/integration/core/engine-options.bats +++ b/test/integration/core/engine-options.bats @@ -2,6 +2,10 @@ load ${BASE_TEST_DIR}/helpers.bash +if [[ -z "$NAME" ]]; then + export NAME="$(unique_machine_name)" +fi + @test "$DRIVER: create with supported engine options" { run machine create -d $DRIVER \ --engine-label spam=eggs \ diff --git a/test/integration/core/env_shell.bats b/test/integration/core/env_shell.bats index e290997e4e..1d4dd577f1 100644 --- a/test/integration/core/env_shell.bats +++ b/test/integration/core/env_shell.bats @@ -2,10 +2,9 @@ load ${BASE_TEST_DIR}/helpers.bash -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME - [ "$status" -eq 0 ] -} +if [[ -z "$NAME" ]]; then + export NAME="$(shared_machine_name)" +fi @test "$DRIVER: test basic bash / zsh notation" { run machine env $NAME diff --git a/test/integration/core/inspect_format.bats b/test/integration/core/inspect_format.bats index e5267f25e5..b7705fc185 100644 --- a/test/integration/core/inspect_format.bats +++ b/test/integration/core/inspect_format.bats @@ -2,10 +2,9 @@ load ${BASE_TEST_DIR}/helpers.bash -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME - [ "$status" -eq 0 ] -} +if [[ -z "$NAME" ]]; then + export NAME="$(shared_machine_name)" +fi @test "$DRIVER: inspect format template" { run machine inspect -f '{{.DriverName}}' $NAME diff --git a/test/integration/core/regenerate-certs.bats b/test/integration/core/regenerate-certs.bats index e7ca5dde84..0bd189f3c7 100644 --- a/test/integration/core/regenerate-certs.bats +++ b/test/integration/core/regenerate-certs.bats @@ -2,9 +2,9 @@ load ${BASE_TEST_DIR}/helpers.bash -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME -} +if [[ -z "$NAME" ]]; then + export NAME="$(shared_machine_name)" +fi @test "$DRIVER: regenerate the certs" { run machine regenerate-certs -f $NAME diff --git a/test/integration/core/scp.bats b/test/integration/core/scp.bats index 0f1f8968c9..8e36430029 100644 --- a/test/integration/core/scp.bats +++ b/test/integration/core/scp.bats @@ -2,12 +2,10 @@ load ${BASE_TEST_DIR}/helpers.bash -export SECOND_MACHINE="$NAME-2" - -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME - [[ ${status} -eq 0 ]] -} +if [[ -z "$NAME" ]]; then + export NAME="$(shared_machine_name)" + export SECOND_MACHINE="$NAME-2" +fi @test "$DRIVER: test machine scp command from remote to host" { machine ssh $NAME 'echo A file created remotely! >/tmp/foo.txt' diff --git a/test/integration/core/ssh-backends.bats b/test/integration/core/ssh-backends.bats index 7fc1fba0d9..b4399b3f4d 100644 --- a/test/integration/core/ssh-backends.bats +++ b/test/integration/core/ssh-backends.bats @@ -2,12 +2,9 @@ load ${BASE_TEST_DIR}/helpers.bash -# Basic smoke test for SSH backends - -@test "$DRIVER: create SSH test box" { - run machine create -d $DRIVER $NAME - [[ "$status" -eq 0 ]] -} +if [[ -z "$NAME" ]]; then + export NAME="$(shared_machine_name)" +fi @test "$DRIVER: test external ssh backend" { run machine ssh $NAME df -h diff --git a/test/integration/helpers.bash b/test/integration/helpers.bash index f97528fa60..1276c70e33 100644 --- a/test/integration/helpers.bash +++ b/test/integration/helpers.bash @@ -1,6 +1,6 @@ #!/bin/bash -echo_to_log() { +function echo_to_log { echo "$BATS_TEST_NAME ---------- $output @@ -9,27 +9,38 @@ $output " >> ${BATS_LOG} } -teardown() { +function teardown { echo_to_log } -function errecho () { +function errecho { >&2 echo "$@" } -function only_if_env () { +function only_if_env { if [[ ${!1} != "$2" ]]; then errecho "This test requires the $1 environment variable to be set to $2. Skipping..." skip fi } -function require_env () { +function require_env { if [[ -z ${!1} ]]; then errecho "This test requires the $1 environment variable to be set in order to run." exit 1 fi } +function unique_machine_name { + echo "bats-$DRIVER-test-$(date +%s)" +} + +function shared_machine_name { + if [[ $(machine ls -q --filter name=$SHARED_NAME | wc -l) -eq 0 ]]; then + machine create -d $DRIVER $SHARED_NAME &>/dev/null + fi + echo "$SHARED_NAME" +} + # Make sure these aren't set while tests run (can cause confusing behavior) unset DOCKER_HOST DOCKER_TLS_VERIFY DOCKER_CERT_DIR diff --git a/test/integration/run-bats.sh b/test/integration/run-bats.sh index f3390f3ce5..97ce41cd20 100755 --- a/test/integration/run-bats.sh +++ b/test/integration/run-bats.sh @@ -14,9 +14,11 @@ function quiet_run () { } function cleanup_machines() { - if [[ $(machine ls -q | wc -l) -ne 0 ]]; then - quiet_run machine rm -f $(machine ls -q) - fi + for MACHINE_NAME in $(machine ls -q); do + if [[ "$MACHINE_NAME" != "$SHARED_NAME" ]] || [[ "$1" == "ALL" ]]; then + quiet_run machine rm -f $MACHINE_NAME + fi + done } function cleanup_store() { @@ -26,18 +28,15 @@ function cleanup_store() { } function machine() { - export PATH="$MACHINE_ROOT"/bin:$PATH "$MACHINE_ROOT"/bin/"$MACHINE_BIN_NAME" "$@" } function run_bats() { for bats_file in $(find "$1" -name \*.bats); do - export NAME="bats-$DRIVER-test-$(date +%s)" - - # BATS returns non-zero to indicate the tests have failed, we shouldn't - # neccesarily bail in this case, so that's the reason for the e toggle. echo "=> $bats_file" + # BATS returns non-zero to indicate the tests have failed, we shouldn't + # necessarily bail in this case, so that's the reason for the e toggle. set +e bats "$bats_file" if [[ $? -ne 0 ]]; then @@ -88,13 +87,14 @@ export MACHINE_STORAGE_PATH="/tmp/machine-bats-test-$DRIVER" export MACHINE_BIN_NAME=docker-machine export BATS_LOG="$MACHINE_ROOT/bats.log" export B2D_LOCATION=~/.docker/machine/cache/boot2docker.iso +export SHARED_NAME="bats-$DRIVER-test-shared-$(date +%s)" # This function gets used in the integration tests, so export it. export -f machine > "$BATS_LOG" -cleanup_machines +cleanup_machines "ALL" cleanup_store if [[ -f "$B2D_LOCATION" ]]; then @@ -108,6 +108,7 @@ fi run_bats "$BATS_FILE" +cleanup_machines "ALL" cleanup_store exit ${EXIT_STATUS} diff --git a/test/integration/virtualbox/bad-create-iso.bats b/test/integration/virtualbox/bad-create-iso.bats index f10d530ef3..ab633cc6da 100644 --- a/test/integration/virtualbox/bad-create-iso.bats +++ b/test/integration/virtualbox/bad-create-iso.bats @@ -4,6 +4,10 @@ load ${BASE_TEST_DIR}/helpers.bash only_if_env DRIVER virtualbox +if [[ -z "$NAME" ]]; then + export NAME="$(unique_machine_name)" +fi + export BAD_URL="http://dev.null:9111/bad.iso" @test "$DRIVER: Should not allow machine creation with bad ISO" { diff --git a/test/integration/virtualbox/certs-checksum.bats b/test/integration/virtualbox/certs-checksum.bats index e2e48e7f3f..a9a8a6531f 100644 --- a/test/integration/virtualbox/certs-checksum.bats +++ b/test/integration/virtualbox/certs-checksum.bats @@ -4,9 +4,9 @@ load ${BASE_TEST_DIR}/helpers.bash only_if_env DRIVER virtualbox -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME -} +if [[ -z "$NAME" ]]; then + export NAME="$(shared_machine_name)" +fi @test "$DRIVER: verify that server cert checksum matches local checksum" { # TODO: This test is tightly coupled to VirtualBox right now, but should be diff --git a/test/integration/virtualbox/custom-mem-disk.bats b/test/integration/virtualbox/custom-mem-disk.bats index a7c1a6560c..eb973a3aed 100644 --- a/test/integration/virtualbox/custom-mem-disk.bats +++ b/test/integration/virtualbox/custom-mem-disk.bats @@ -4,6 +4,10 @@ load ${BASE_TEST_DIR}/helpers.bash only_if_env DRIVER virtualbox +if [[ -z "$NAME" ]]; then + export NAME="$(unique_machine_name)" +fi + # Default memsize is 1024MB and disksize is 20000MB # These values are defined in drivers/virtualbox/virtualbox.go export DEFAULT_MEMSIZE=1024 diff --git a/test/integration/virtualbox/dns.bats b/test/integration/virtualbox/dns.bats index 802548baf0..69107c80e2 100644 --- a/test/integration/virtualbox/dns.bats +++ b/test/integration/virtualbox/dns.bats @@ -4,6 +4,10 @@ load ${BASE_TEST_DIR}/helpers.bash only_if_env DRIVER virtualbox +if [[ -z "$NAME" ]]; then + export NAME="$(unique_machine_name)" +fi + @test "$DRIVER: Create a vm with a dns proxy set" { run machine create -d $DRIVER --virtualbox-dns-proxy=true $NAME [[ ${status} -eq 0 ]] diff --git a/test/integration/virtualbox/pause-save-start.bats b/test/integration/virtualbox/pause-save-start.bats index cdab7621e9..0f865c27e8 100644 --- a/test/integration/virtualbox/pause-save-start.bats +++ b/test/integration/virtualbox/pause-save-start.bats @@ -4,10 +4,9 @@ load ${BASE_TEST_DIR}/helpers.bash only_if_env DRIVER virtualbox -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME - [ "$status" -eq 0 ] -} +if [[ -z "$NAME" ]]; then + export NAME="$(shared_machine_name)" +fi @test "$DRIVER: VBoxManage pause" { run VBoxManage controlvm $NAME pause diff --git a/test/integration/virtualbox/upgrade.bats b/test/integration/virtualbox/upgrade.bats index 893fea4e0a..5233b79bc5 100644 --- a/test/integration/virtualbox/upgrade.bats +++ b/test/integration/virtualbox/upgrade.bats @@ -4,6 +4,10 @@ load ${BASE_TEST_DIR}/helpers.bash only_if_env DRIVER virtualbox +if [[ -z "$NAME" ]]; then + export NAME="$(unique_machine_name)" +fi + export OLD_ISO_URL="https://github.com/boot2docker/boot2docker/releases/download/v1.4.1/boot2docker.iso" @test "$DRIVER: create for upgrade" {