From ed01843dc9862e220a2723546479bf63daa35c92 Mon Sep 17 00:00:00 2001 From: Nathan LeClaire Date: Tue, 12 May 2015 11:02:44 -0700 Subject: [PATCH] Refactor integration tests Signed-off-by: Nathan LeClaire --- CONTRIBUTING.md | 143 ++++-- test/integration/{cli.bats => cli/help.bats} | 2 +- test/integration/{ => cli}/ls.bats | 12 +- .../core/arbitrary-engine-options.bats | 16 + .../{ => core}/certs-checksum.bats | 6 +- .../core-commands.bats} | 38 +- .../{ => core}/regenerate-certs.bats | 6 +- test/integration/{ => core}/scp.bats | 10 +- test/integration/{ => core}/ssh-backends.bats | 17 +- .../core/supported-engine-options.bats | 33 ++ .../integration/{ => core}/swarm-options.bats | 10 +- test/integration/driver-amazonec2.bats | 157 ------- test/integration/driver-azure.bats | 104 ----- test/integration/driver-digitalocean.bats | 164 ------- test/integration/driver-exoscale.bats | 109 ----- test/integration/driver-google.bats | 104 ----- test/integration/driver-hyperv.bats | 104 ----- test/integration/driver-rackspace.bats | 82 ---- test/integration/driver-softlayer.bats | 104 ----- test/integration/driver-virtualbox.bats | 408 ------------------ test/integration/driver-vmwarevcloudair.bats | 104 ----- .../drivers/virtualbox/bad-create-iso.bats | 10 + .../drivers/virtualbox/custom-mem-disk.bats | 54 +++ .../drivers/virtualbox/pause-save-start.bats | 53 +++ .../drivers/virtualbox/upgrade.bats | 26 ++ test/integration/helpers.bash | 39 -- test/integration/run-bats.sh | 108 +++++ 27 files changed, 429 insertions(+), 1594 deletions(-) rename test/integration/{cli.bats => cli/help.bats} (98%) rename test/integration/{ => cli}/ls.bats (79%) create mode 100644 test/integration/core/arbitrary-engine-options.bats rename test/integration/{ => core}/certs-checksum.bats (85%) rename test/integration/{driver-vmwarefusion.bats => core/core-commands.bats} (78%) rename test/integration/{ => core}/regenerate-certs.bats (74%) rename test/integration/{ => core}/scp.bats (84%) rename test/integration/{ => core}/ssh-backends.bats (64%) create mode 100644 test/integration/core/supported-engine-options.bats rename test/integration/{ => core}/swarm-options.bats (69%) delete mode 100644 test/integration/driver-amazonec2.bats delete mode 100644 test/integration/driver-azure.bats delete mode 100644 test/integration/driver-digitalocean.bats delete mode 100644 test/integration/driver-exoscale.bats delete mode 100644 test/integration/driver-google.bats delete mode 100644 test/integration/driver-hyperv.bats delete mode 100644 test/integration/driver-rackspace.bats delete mode 100644 test/integration/driver-softlayer.bats delete mode 100644 test/integration/driver-virtualbox.bats delete mode 100644 test/integration/driver-vmwarevcloudair.bats create mode 100644 test/integration/drivers/virtualbox/bad-create-iso.bats create mode 100644 test/integration/drivers/virtualbox/custom-mem-disk.bats create mode 100644 test/integration/drivers/virtualbox/pause-save-start.bats create mode 100644 test/integration/drivers/virtualbox/upgrade.bats create mode 100755 test/integration/run-bats.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8cb49984fd..9b6770ec8f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -87,60 +87,127 @@ the coverage for the VirtualBox driver's package, browse to `/drivers/virtualbox You can hit `CTRL+C` to stop the server. ## Integration Tests -We utilize [BATS](https://github.com/sstephenson/bats) for integration testing. -This runs tests against the generated binary. To use, make sure to install -BATS (use that link). Then run `./script/build` to generate the binary. Once -you have the binary, you can run test against a specified driver: -``` -$ bats test/integration/driver-virtualbox.bats +### Setup + +We utilize [BATS](https://github.com/sstephenson/bats) for integration testing. +This runs tests against the generated binary. To use, first make sure to +[install BATS](https://github.com/sstephenson/bats). Then run `./script/build` +to generate the binary for your system. + +### Basic Usage + +Once you have the binary, the integration tests can be invoked using the +`test/integration/run-bats.sh` wrapper script. + +Using this wrapper script, you can invoke a test or subset of tests for a +particular driver. To set the driver, use the `DRIVER` environment variable. + +The following examples are all shown relative to the project's root directory, +but you should be able to invoke them from any directory without issue. + +To invoke just one test: + +```console +$ DRIVER=virtualbox ./test/integration/run-bats.sh test/integration/core/core-commands.bats ✓ virtualbox: machine should not exist - ✓ virtualbox: VM should not exist ✓ virtualbox: create - ✓ virtualbox: active ✓ virtualbox: ls - ✓ virtualbox: run busybox container + ✓ virtualbox: run busybox container ✓ virtualbox: url ✓ virtualbox: ip ✓ virtualbox: ssh + ✓ virtualbox: docker commands with the socket should work ✓ virtualbox: stop - ✓ virtualbox: machine should show stopped + ✓ virtualbox: machine should show stopped after stop + ✓ virtualbox: machine should now allow upgrade when stopped ✓ virtualbox: start ✓ virtualbox: machine should show running after start + ✓ virtualbox: kill + ✓ virtualbox: machine should show stopped after kill ✓ virtualbox: restart ✓ virtualbox: machine should show running after restart - ✓ virtualbox: remove - ✓ virtualbox: machine should not exist - ✓ virtualbox: VM should not exist - -15 tests, 0 failures -``` - -You can also run the general `cli` tests: - -``` -$ bats test/integration/cli.bats - ✓ cli: show info - ✓ cli: show active help - ✓ cli: show config help - ✓ cli: show inspect help - ✓ cli: show ip help - ✓ cli: show kill help - ✓ cli: show ls help - ✓ cli: show restart help - ✓ cli: show rm help - ✓ cli: show env help - ✓ cli: show ssh help - ✓ cli: show start help - ✓ cli: show stop help - ✓ cli: show upgrade help - ✓ cli: show url help - ✓ flag: show version - ✓ flag: show help 17 tests, 0 failures +Cleaning up machines... +Successfully removed bats-virtualbox-test ``` + +To invoke a shared test with a different driver: + +```console +$ DRIVER=digitalocean ./test/integration/run-bats.sh test/integration/core/core-commands.bats +... +``` + +To invoke a directory of tests recursively: + +```console +$ DRIVER=virtualbox ./test/integration/run-bats.sh test/integration/core/ +... +``` + +If you want to invoke a group of tests across two or more different drivers at +once (e.g. every test in the `drivers` directory), at the time of writing there +is no first-class support to do so - you will have to write your own wrapper +scripts, bash loops, etc. However, in the future, this may gain first-class +support as usage patterns become more clear. + +### Extra Create Arguments + +In some cases, for instance to test the creation of a specific base OS (e.g. +RHEL) as opposed to the default with the common tests, you may want to run +common tests with different create arguments than you get out of the box. + +Keep in mind that Machine supports environment variables for many of these +flags. So, for instance, you could run the command (substituting, of course, +the proper secrets): + +``` +$ DRIVER=amazonec2 \ + AWS_VPC_ID=vpc-xxxxxxx \ + AWS_SECRET_ACCESS_KEY=yyyyyyyyyyyyy \ + AWS_ACCESS_KEY_ID=zzzzzzzzzzzzzzzz \ + AWS_AMI=ami-12663b7a \ + AWS_SSH_USER=ec2-user \ + ./test/integration/run-bats.sh test/integration/core +``` + +in order to run the core tests on Red Hat Enterprise Linux on Amazon. + +### Layout + +The `test/integration` directory is layed out to divide up tests based on the +areas which the test. If you are uncertain where to put yours, we are happy to +guide you. + +At the time of writing, there is: + +1. A `core` directory which contains tests that are applicable to all drivers. +2. A `drivers` directory which contains tests that are applicable only to +specific drivers with sub-directories for each provider. +3. A `cli` directory which is meant for testing functionality of the command +line interface, without much regard for driver-specific details. + +### Guidelines + +The best practices for writing integration tests on Docker Machine are still a +work in progress, but here are some general guidelines from the maintainers: + +1. Ideally, each test file should have only one concern. +2. Tests generally should not spin up more than one machine unless the test is +deliberately testing something which involves multiple machines, such as an `ls` +test which involves several machines, or a test intended to create and check +some property of a Swarm cluster. +3. BATS will print the output of commands executed during a test if the test +fails. This can be useful, for instance to dump the magic `$output` variable +that BATS provides and/or to get debugging information. +4. It is not strictly needed to clean up the machines as part of the test. The +BATS wrapper script has a hook to take care of cleaning up all created machines +after each test. + # Drivers + Docker Machine has several included drivers that supports provisioning hosts in various providers. If you wish to contribute a driver, we ask the following to ensure we keep the driver in a consistent and stable state: diff --git a/test/integration/cli.bats b/test/integration/cli/help.bats similarity index 98% rename from test/integration/cli.bats rename to test/integration/cli/help.bats index 5589f47169..f30c8f2806 100644 --- a/test/integration/cli.bats +++ b/test/integration/cli/help.bats @@ -1,6 +1,6 @@ #!/usr/bin/env bats -load helpers +load ${BASE_TEST_DIR}/helpers.bash @test "cli: show info" { run machine diff --git a/test/integration/ls.bats b/test/integration/cli/ls.bats similarity index 79% rename from test/integration/ls.bats rename to test/integration/cli/ls.bats index cf16832873..6f0ea0ca87 100644 --- a/test/integration/ls.bats +++ b/test/integration/cli/ls.bats @@ -1,15 +1,9 @@ #!/usr/bin/env bats -load helpers +load ${BASE_TEST_DIR}/helpers.bash -teardown() { - echo "$BATS_TEST_NAME ----------- -$output ----------- - -" >> ${BATS_LOG} - machine rm -f testmachine +teardown () { + machine rm testmachine } @test "ls: filter on driver" { diff --git a/test/integration/core/arbitrary-engine-options.bats b/test/integration/core/arbitrary-engine-options.bats new file mode 100644 index 0000000000..afdee75824 --- /dev/null +++ b/test/integration/core/arbitrary-engine-options.bats @@ -0,0 +1,16 @@ +#!/usr/bin/env bats + +load ${BASE_TEST_DIR}/helpers.bash + +@test "$DRIVER: create with arbitrary engine option" { + run machine create -d $DRIVER \ + --engine-opt log-driver=none \ + $NAME + [ $status -eq 0 ] +} + +@test "$DRIVER: check created engine option (log driver)" { + docker $(machine config $NAME) run --name nolog busybox echo this should not be logged + run docker $(machine config $NAME) logs nolog + [ $status -eq 1 ] +} diff --git a/test/integration/certs-checksum.bats b/test/integration/core/certs-checksum.bats similarity index 85% rename from test/integration/certs-checksum.bats rename to test/integration/core/certs-checksum.bats index b53e33b31a..d5f47f57d4 100644 --- a/test/integration/certs-checksum.bats +++ b/test/integration/core/certs-checksum.bats @@ -1,10 +1,6 @@ #!/usr/bin/env bats -load helpers - -export DRIVER=virtualbox -export NAME="bats-$DRIVER-test" -export MACHINE_STORAGE_PATH=/tmp/machine-bats-test-$DRIVER +load ${BASE_TEST_DIR}/helpers.bash @test "$DRIVER: create" { run machine create -d $DRIVER $NAME diff --git a/test/integration/driver-vmwarefusion.bats b/test/integration/core/core-commands.bats similarity index 78% rename from test/integration/driver-vmwarefusion.bats rename to test/integration/core/core-commands.bats index 8593031c9e..70c220ce5e 100644 --- a/test/integration/driver-vmwarefusion.bats +++ b/test/integration/core/core-commands.bats @@ -1,18 +1,10 @@ #!/usr/bin/env bats -load helpers - -export DRIVER=vmwarefusion -export NAME="bats-$DRIVER-test" -export MACHINE_STORAGE_PATH=/tmp/docker-machine-bats-test-$DRIVER - -function setup() { - # add sleep because vbox; ugh - sleep 1 -} +load ${BASE_TEST_DIR}/helpers.bash @test "$DRIVER: machine should not exist" { run machine inspect $NAME + echo ${output} [ "$status" -eq 1 ] } @@ -48,6 +40,10 @@ function setup() { [[ ${lines[0]} =~ "total" ]] } +@test "$DRIVER: docker commands with the socket should work" { + run machine ssh $NAME -- docker version +} + @test "$DRIVER: stop" { run machine stop $NAME [ "$status" -eq 0 ] @@ -62,7 +58,7 @@ function setup() { @test "$DRIVER: url should show an error when machine is stopped" { run machine url $NAME [ "$status" -eq 1 ] - [[ ${output} == "host is not running" ]] + [[ ${output} == *"not running"* ]] } @test "$DRIVER: env should show an error when machine is stopped" { @@ -71,6 +67,11 @@ function setup() { [[ ${output} == *"not running. Please start this with"* ]] } +@test "$DRIVER: machine should not allow upgrade when stopped" { + run machine upgrade $NAME + [[ "$status" -eq 1 ]] +} + @test "$DRIVER: start" { run machine start $NAME [ "$status" -eq 0 ] @@ -103,18 +104,3 @@ function setup() { [ "$status" -eq 0 ] [[ ${lines[1]} == *"Running"* ]] } - -@test "$DRIVER: remove" { - run machine rm -f $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should not exist" { - run machine inspect $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: cleanup" { - run rm -rf $MACHINE_STORAGE_PATH - [ "$status" -eq 0 ] -} diff --git a/test/integration/regenerate-certs.bats b/test/integration/core/regenerate-certs.bats similarity index 74% rename from test/integration/regenerate-certs.bats rename to test/integration/core/regenerate-certs.bats index 4a51eeba64..c6302389ee 100644 --- a/test/integration/regenerate-certs.bats +++ b/test/integration/core/regenerate-certs.bats @@ -1,10 +1,6 @@ #!/usr/bin/env bats -load helpers - -export DRIVER=virtualbox -export NAME="bats-$DRIVER-test" -export MACHINE_STORAGE_PATH=/tmp/machine-bats-test-$DRIVER +load ${BASE_TEST_DIR}/helpers.bash @test "$DRIVER: create" { run machine create -d $DRIVER $NAME diff --git a/test/integration/scp.bats b/test/integration/core/scp.bats similarity index 84% rename from test/integration/scp.bats rename to test/integration/core/scp.bats index e4332166b1..aaa68a63f2 100644 --- a/test/integration/scp.bats +++ b/test/integration/core/scp.bats @@ -1,10 +1,7 @@ #!/usr/bin/env bats -load helpers +load ${BASE_TEST_DIR}/helpers.bash -export DRIVER=virtualbox -export NAME="bats-$DRIVER-test" -export MACHINE_STORAGE_PATH=/tmp/machine-bats-test-$DRIVER export SECOND_MACHINE="$NAME-2" @test "$DRIVER: create" { @@ -34,8 +31,3 @@ export SECOND_MACHINE="$NAME-2" run machine scp $NAME:/tmp/foo.txt $SECOND_MACHINE:/tmp/foo.txt [[ $(machine ssh ${SECOND_MACHINE} cat /tmp/foo.txt) == "A file hopping around!" ]] } - -@test "cleanup" { - rm foo.txt - machine rm $NAME -} diff --git a/test/integration/ssh-backends.bats b/test/integration/core/ssh-backends.bats similarity index 64% rename from test/integration/ssh-backends.bats rename to test/integration/core/ssh-backends.bats index 9bf0ad8ca4..b5fbd35896 100644 --- a/test/integration/ssh-backends.bats +++ b/test/integration/core/ssh-backends.bats @@ -1,10 +1,6 @@ #!/usr/bin/env bats -load helpers - -export DRIVER=virtualbox -export NAME="bats-$DRIVER-test" -export MACHINE_STORAGE_PATH=/tmp/machine-bats-test-$DRIVER +load ${BASE_TEST_DIR}/helpers.bash # Basic smoke test for SSH backends @@ -32,14 +28,3 @@ export MACHINE_STORAGE_PATH=/tmp/machine-bats-test-$DRIVER run machine --native-ssh ssh $NAME echo foo [[ "$output" == "foo" ]] } - -@test "$DRIVER: remove machine after ssh backend test" { - run machine rm -f $NAME -} - -# Cleanup of machine store should always be the last 'test' -@test "$DRIVER: cleanup" { - run rm -rf $MACHINE_STORAGE_PATH - [ "$status" -eq 0 ] -} - diff --git a/test/integration/core/supported-engine-options.bats b/test/integration/core/supported-engine-options.bats new file mode 100644 index 0000000000..243565827d --- /dev/null +++ b/test/integration/core/supported-engine-options.bats @@ -0,0 +1,33 @@ +#!/usr/bin/env bats + +load ${BASE_TEST_DIR}/helpers.bash + +@test "$DRIVER: create with supported engine options" { + run machine create -d $DRIVER \ + --engine-label spam=eggs \ + --engine-storage-driver devicemapper \ + --engine-insecure-registry registry.myco.com \ + $NAME + echo "$output" + [ $status -eq 0 ] +} + +@test "$DRIVER: check for engine label" { + spamlabel=$(docker $(machine config $NAME) info | grep spam) + [[ $spamlabel =~ "spam=eggs" ]] +} + +@test "$DRIVER: check for engine storage driver" { + storage_driver_info=$(docker $(machine config $NAME) info | grep "Storage Driver") + [[ $storage_driver_info =~ "devicemapper" ]] +} + +@test "$DRIVER: rm after supported engine option create" { + run machine rm $NAME + [ $status -eq 0 ] +} + +@test "$DRIVER: machine should not exist" { + run machine inspect $NAME + [ "$status" -eq 1 ] +} diff --git a/test/integration/swarm-options.bats b/test/integration/core/swarm-options.bats similarity index 69% rename from test/integration/swarm-options.bats rename to test/integration/core/swarm-options.bats index 36686f5362..a117a7ab3b 100644 --- a/test/integration/swarm-options.bats +++ b/test/integration/core/swarm-options.bats @@ -1,18 +1,16 @@ #!/usr/bin/env bats -load helpers - -export DRIVER=virtualbox -export MACHINE_STORAGE_PATH=/tmp/machine-bats-test-$DRIVER +load ${BASE_TEST_DIR}/helpers.bash export TOKEN=$(curl -sS -X POST "https://discovery-stage.hub.docker.com/v1/clusters") @test "create swarm master" { - run machine create -d virtualbox --swarm --swarm-master --swarm-discovery "token://$TOKEN" --swarm-strategy binpack --swarm-opt heartbeat=5 queenbee + run machine create -d $DRIVER --swarm --swarm-master --swarm-discovery "token://$TOKEN" --swarm-strategy binpack --swarm-opt heartbeat=5 queenbee + echo ${output} [[ "$status" -eq 0 ]] } @test "create swarm node" { - run machine create -d virtualbox --swarm --swarm-discovery "token://$TOKEN" workerbee + run machine create -d $DRIVER --swarm --swarm-discovery "token://$TOKEN" workerbee [[ "$status" -eq 0 ]] } diff --git a/test/integration/driver-amazonec2.bats b/test/integration/driver-amazonec2.bats deleted file mode 100644 index 74f2cc651d..0000000000 --- a/test/integration/driver-amazonec2.bats +++ /dev/null @@ -1,157 +0,0 @@ -#!/usr/bin/env bats - -load helpers - -export DRIVER=amazonec2 -export NAME="bats-$DRIVER-test" -export MACHINE_STORAGE_PATH=/tmp/machine-bats-test-$DRIVER - -@test "$DRIVER: machine should not exist" { - run machine inspect $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ls" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"$NAME"* ]] -} - -@test "$DRIVER: run busybox container" { - run docker $(machine config $NAME) run busybox echo hello world - [ "$status" -eq 0 ] -} - -@test "$DRIVER: url" { - run machine url $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ip" { - run machine ip $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ssh" { - run machine ssh $NAME -- ls -lah / - [ "$status" -eq 0 ] - [[ ${lines[0]} =~ "total" ]] -} - -@test "$DRIVER: docker commands with the socket should work" { - run machine ssh $NAME -- docker version -} - -@test "$DRIVER: stop" { - run machine stop $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show stopped after stop" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Stopped"* ]] -} - -@test "$DRIVER: start" { - run machine start $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after start" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: kill" { - run machine kill $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show stopped after kill" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Stopped"* ]] -} - -@test "$DRIVER: restart" { - run machine restart $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after restart" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: remove" { - run machine rm -f $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: create with arbitrary engine option" { - run machine create -d $DRIVER \ - --engine-opt log-driver=none \ - $NAME - [ $status -eq 0 ] -} - -@test "$DRIVER: check created engine option (log driver)" { - docker $(machine config $NAME) run --name nolog busybox echo this should not be logged - run docker $(machine config $NAME) logs nolog - [ $status -eq 1 ] -} - -@test "$DRIVER: rm after arbitrary engine option create" { - run machine rm $NAME - [ $status -eq 0 ] -} - -@test "$DRIVER: create with supported engine options" { - run machine create -d $DRIVER \ - --engine-label spam=eggs \ - --engine-storage-driver devicemapper \ - --engine-insecure-registry registry.myco.com \ - $NAME - echo "$output" - [ $status -eq 0 ] -} - -@test "$DRIVER: check for engine label" { - spamlabel=$(docker $(machine config $NAME) info | grep spam) - [[ $spamlabel =~ "spam=eggs" ]] -} - -@test "$DRIVER: check for engine storage driver" { - storage_driver_info=$(docker $(machine config $NAME) info | grep "Storage Driver") - [[ $storage_driver_info =~ "devicemapper" ]] -} - -@test "$DRIVER: check for insecure registry setting" { - ir_option=$(machine ssh $NAME -- cat /etc/default/docker | grep insecure-registry) - [[ $ir_option =~ "registry.myco.com" ]] -} - -@test "$DRIVER: rm after supported engine option create" { - run machine rm $NAME - [ $status -eq 0 ] -} - - -@test "$DRIVER: machine should not exist" { - run machine inspect $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: cleanup" { - run rm -rf $MACHINE_STORAGE_PATH - [ "$status" -eq 0 ] -} - diff --git a/test/integration/driver-azure.bats b/test/integration/driver-azure.bats deleted file mode 100644 index 1aa79ea5cb..0000000000 --- a/test/integration/driver-azure.bats +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env bats - -load helpers - -export DRIVER=azure -export NAME="bats-$DRIVER-test" -export MACHINE_STORAGE_PATH=/tmp/machine-bats-test-$DRIVER - -@test "$DRIVER: machine should not exist" { - run machine inspect $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ls" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"$NAME"* ]] -} - -@test "$DRIVER: run busybox container" { - run docker $(machine config $NAME) run busybox echo hello world - [ "$status" -eq 0 ] -} - -@test "$DRIVER: url" { - run machine url $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ip" { - run machine ip $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ssh" { - run machine ssh $NAME -- ls -lah / - [ "$status" -eq 0 ] - [[ ${lines[0]} =~ "total" ]] -} - -@test "$DRIVER: stop" { - run machine stop $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show stopped after stop" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Stopped"* ]] -} - -@test "$DRIVER: start" { - run machine start $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after start" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: kill" { - run machine kill $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show stopped after kill" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Stopped"* ]] -} - -@test "$DRIVER: restart" { - run machine restart $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after restart" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: remove" { - run machine rm -f $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should not exist" { - run machine inspect $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: cleanup" { - run rm -rf $MACHINE_STORAGE_PATH - [ "$status" -eq 0 ] -} - diff --git a/test/integration/driver-digitalocean.bats b/test/integration/driver-digitalocean.bats deleted file mode 100644 index a8a343a745..0000000000 --- a/test/integration/driver-digitalocean.bats +++ /dev/null @@ -1,164 +0,0 @@ -#!/usr/bin/env bats - -load helpers - -export DRIVER=digitalocean -export NAME="bats-$DRIVER-test" -export MACHINE_STORAGE_PATH=/tmp/machine-bats-test-$DRIVER - -@test "$DRIVER: machine should not exist" { - run machine inspect $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ls" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"$NAME"* ]] -} - -@test "$DRIVER: run busybox container" { - run docker $(machine config $NAME) run busybox echo hello world - [ "$status" -eq 0 ] -} - -@test "$DRIVER: url" { - run machine url $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ip" { - run machine ip $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ssh" { - run machine ssh $NAME -- ls -lah / - [ "$status" -eq 0 ] - [[ ${lines[0]} =~ "total" ]] -} - -@test "$DRIVER: docker commands with the socket should work" { - run machine ssh $NAME -- docker version -} - -# currently this only checks debian/ubuntu style using 127.0.0.1 -@test "$DRIVER: hostname should be set properly" { - run machine ssh $NAME -- "grep -Fxq '127.0.1.1 $NAME' /etc/hosts" - [ "$status" -eq 0 ] -} - -@test "$DRIVER: stop" { - run machine stop $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show stopped after stop" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Stopped"* ]] -} - -@test "$DRIVER: start" { - run machine start $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after start" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: kill" { - run machine kill $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show stopped after kill" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Stopped"* ]] -} - -@test "$DRIVER: restart" { - run machine restart $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after restart" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: remove" { - run sleep 20 - run machine rm -f $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: create with arbitrary engine option" { - run machine create -d $DRIVER \ - --engine-opt log-driver=none \ - $NAME - [ $status -eq 0 ] -} - -@test "$DRIVER: check created engine option (log driver)" { - docker $(machine config $NAME) run --name nolog busybox echo this should not be logged - run docker $(machine config $NAME) logs nolog - [ $status -eq 1 ] -} - -@test "$DRIVER: rm after arbitrary engine option create" { - run machine rm $NAME - [ $status -eq 0 ] -} - -@test "$DRIVER: create with supported engine options" { - run machine create -d $DRIVER \ - --engine-label spam=eggs \ - --engine-storage-driver devicemapper \ - --engine-insecure-registry registry.myco.com \ - $NAME - echo "$output" - [ $status -eq 0 ] -} - -@test "$DRIVER: check for engine labels" { - spamlabel=$(docker $(machine config $NAME) info | grep spam) - [[ $spamlabel =~ "spam=eggs" ]] -} - -@test "$DRIVER: check for engine storage driver" { - storage_driver_info=$(docker $(machine config $NAME) info | grep "Storage Driver") - [[ $storage_driver_info =~ "devicemapper" ]] -} - -@test "$DRIVER: check for insecure registry setting" { - ir_option=$(machine ssh $NAME -- cat /etc/default/docker | grep insecure-registry) - [[ $ir_option =~ "registry.myco.com" ]] -} - -@test "$DRIVER: rm after supported engine option create" { - run machine rm $NAME - [ $status -eq 0 ] -} - - -@test "$DRIVER: machine should not exist" { - run machine inspect $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: cleanup" { - run rm -rf $MACHINE_STORAGE_PATH - [ "$status" -eq 0 ] -} - diff --git a/test/integration/driver-exoscale.bats b/test/integration/driver-exoscale.bats deleted file mode 100644 index 378b93eb64..0000000000 --- a/test/integration/driver-exoscale.bats +++ /dev/null @@ -1,109 +0,0 @@ -#!/usr/bin/env bats - -load helpers - -export DRIVER=exoscale -export NAME="bats-$DRIVER-test" -export MACHINE_STORAGE_PATH=/tmp/machine-bats-test-$DRIVER - -@test "$DRIVER: machine should not exist" { - run machine inspect $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ls" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"$NAME"* ]] -} - -@test "$DRIVER: run busybox container" { - run docker $(machine config $NAME) run busybox echo hello world - [ "$status" -eq 0 ] -} - -@test "$DRIVER: url" { - run machine url $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ip" { - run machine ip $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ssh" { - run machine ssh $NAME -- ls -lah / - [ "$status" -eq 0 ] - [[ ${lines[0]} =~ "total" ]] -} - -@test "$DRIVER: docker commands with the socket should work" { - run machine ssh $NAME -- docker version -} - -@test "$DRIVER: stop" { - run machine stop $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show stopped after stop" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Stopped"* ]] -} - -@test "$DRIVER: start" { - run machine start $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after start" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: kill" { - run machine kill $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show stopped after kill" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Stopped"* ]] -} - -@test "$DRIVER: restart" { - run machine restart $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after restart" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: remove" { - run sleep 20 - run machine rm -f $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should not exist" { - run machine inspect $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: cleanup" { - run rm -rf $MACHINE_STORAGE_PATH - [ "$status" -eq 0 ] -} - diff --git a/test/integration/driver-google.bats b/test/integration/driver-google.bats deleted file mode 100644 index bbf2db278e..0000000000 --- a/test/integration/driver-google.bats +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env bats - -load helpers - -export DRIVER=google -export NAME="bats-$DRIVER-test" -export MACHINE_STORAGE_PATH=/tmp/machine-bats-test-$DRIVER - -@test "$DRIVER: machine should not exist" { - run machine inspect $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ls" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"$NAME"* ]] -} - -@test "$DRIVER: run busybox container" { - run docker $(machine config $NAME) run busybox echo hello world - [ "$status" -eq 0 ] -} - -@test "$DRIVER: url" { - run machine url $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ip" { - run machine ip $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ssh" { - run machine ssh $NAME -- ls -lah / - [ "$status" -eq 0 ] - [[ ${lines[0]} =~ "total" ]] -} - -@test "$DRIVER: stop" { - run machine stop $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show stopped after stop" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Stopped"* ]] -} - -@test "$DRIVER: start" { - run machine start $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after start" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: kill" { - run machine kill $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show stopped after kill" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Stopped"* ]] -} - -@test "$DRIVER: restart" { - run machine restart $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after restart" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: remove" { - run machine rm -f $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should not exist" { - run machine inspect $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: cleanup" { - run rm -rf $MACHINE_STORAGE_PATH - [ "$status" -eq 0 ] -} - diff --git a/test/integration/driver-hyperv.bats b/test/integration/driver-hyperv.bats deleted file mode 100644 index 763e9d30d1..0000000000 --- a/test/integration/driver-hyperv.bats +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env bats - -load helpers - -export DRIVER=hyperv -export NAME="bats-$DRIVER-test" -export MACHINE_STORAGE_PATH=/tmp/machine-bats-test-$DRIVER - -@test "$DRIVER: machine should not exist" { - run machine inspect $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ls" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"$NAME"* ]] -} - -@test "$DRIVER: run busybox container" { - run docker $(machine config $NAME) run busybox echo hello world - [ "$status" -eq 0 ] -} - -@test "$DRIVER: url" { - run machine url $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ip" { - run machine ip $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ssh" { - run machine ssh $NAME -- ls -lah / - [ "$status" -eq 0 ] - [[ ${lines[0]} =~ "total" ]] -} - -@test "$DRIVER: stop" { - run machine stop $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show stopped after stop" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Stopped"* ]] -} - -@test "$DRIVER: start" { - run machine start $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after start" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: kill" { - run machine kill $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show stopped after kill" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Stopped"* ]] -} - -@test "$DRIVER: restart" { - run machine restart $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after restart" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: remove" { - run machine rm -f $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should not exist" { - run machine inspect $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: cleanup" { - run rm -rf $MACHINE_STORAGE_PATH - [ "$status" -eq 0 ] -} - diff --git a/test/integration/driver-rackspace.bats b/test/integration/driver-rackspace.bats deleted file mode 100644 index b96f59dece..0000000000 --- a/test/integration/driver-rackspace.bats +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env bats - -load helpers - -export DRIVER=rackspace -export NAME="bats-$DRIVER-test" -export MACHINE_STORAGE_PATH=/tmp/machine-bats-test-$DRIVER - -@test "$DRIVER: machine should not exist" { - run machine inspect $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ls" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"$NAME"* ]] - [[ ${lines[1]} == *"*"* ]] -} - -@test "$DRIVER: run busybox container" { - run docker $(machine config $NAME) run busybox echo hello world - [ "$status" -eq 0 ] -} - -@test "$DRIVER: url" { - run machine url $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ip" { - run machine ip $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ssh" { - run machine ssh $NAME -- ls -lah / - [ "$status" -eq 0 ] - [[ ${lines[0]} =~ "total" ]] -} - -@test "$DRIVER: stop should fail (unsupported)" { - run machine stop $NAME - [[ ${lines[1]} == *"not currently support"* ]] -} - -@test "$DRIVER: start should fail (unsupported)" { - run machine start $NAME - [[ ${lines[1]} == *"not currently support"* ]] -} - -@test "$DRIVER: restart" { - run machine restart $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after restart" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: remove" { - run machine rm $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should not exist" { - run machine inspect $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: cleanup" { - run rm -rf $MACHINE_STORAGE_PATH - [ "$status" -eq 0 ] -} - diff --git a/test/integration/driver-softlayer.bats b/test/integration/driver-softlayer.bats deleted file mode 100644 index b4be9c908c..0000000000 --- a/test/integration/driver-softlayer.bats +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env bats - -load helpers - -export DRIVER=softlayer -export NAME="bats-$DRIVER-test" -export MACHINE_STORAGE_PATH=/tmp/machine-bats-test-$DRIVER - -@test "$DRIVER: machine should not exist" { - run machine inspect $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ls" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"$NAME"* ]] -} - -@test "$DRIVER: run busybox container" { - run docker $(machine config $NAME) run busybox echo hello world - [ "$status" -eq 0 ] -} - -@test "$DRIVER: url" { - run machine url $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ip" { - run machine ip $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ssh" { - run machine ssh $NAME -- ls -lah / - [ "$status" -eq 0 ] - [[ ${lines[0]} =~ "total" ]] -} - -@test "$DRIVER: stop" { - run machine stop $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show stopped after stop" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Stopped"* ]] -} - -@test "$DRIVER: start" { - run machine start $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after start" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: kill" { - run machine kill $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show stopped after kill" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Stopped"* ]] -} - -@test "$DRIVER: restart" { - run machine restart $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after restart" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: remove" { - run machine rm -f $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should not exist" { - run machine inspect $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: cleanup" { - run rm -rf $MACHINE_STORAGE_PATH - [ "$status" -eq 0 ] -} - diff --git a/test/integration/driver-virtualbox.bats b/test/integration/driver-virtualbox.bats deleted file mode 100644 index 234bf92b6b..0000000000 --- a/test/integration/driver-virtualbox.bats +++ /dev/null @@ -1,408 +0,0 @@ -#!/usr/bin/env bats - -load helpers - -export DRIVER=virtualbox -export NAME="bats-$DRIVER-test" -export MACHINE_STORAGE_PATH=/tmp/machine-bats-test-$DRIVER -# Default memsize is 1024MB and disksize is 20000MB -# These values are defined in drivers/virtualbox/virtualbox.go -export DEFAULT_MEMSIZE=1024 -export DEFAULT_DISKSIZE=20000 -export CUSTOM_MEMSIZE=1536 -export CUSTOM_DISKSIZE=10000 -export CUSTOM_CPUCOUNT=1 -export BAD_URL="http://dev.null:9111/bad.iso" - -function setup() { - # add sleep because vbox; ugh - sleep 1 -} - -findDiskSize() { - # SATA-0-0 is usually the boot2disk.iso image - # We assume that SATA 1-0 is root disk VMDK and grab this UUID - # e.g. "SATA-ImageUUID-1-0"="fb5f33a7-e4e3-4cb9-877c-f9415ae2adea" - # TODO(slashk): does this work on Windows ? - run bash -c "VBoxManage showvminfo --machinereadable $NAME | grep SATA-ImageUUID-1-0 | cut -d'=' -f2" - run bash -c "VBoxManage showhdinfo $output | grep "Capacity:" | awk -F' ' '{ print $2 }'" -} - -findMemorySize() { - run bash -c "VBoxManage showvminfo --machinereadable $NAME | grep memory= | cut -d'=' -f2" -} - -findCPUCount() { - run bash -c "VBoxManage showvminfo --machinereadable $NAME | grep cpus= | cut -d'=' -f2" -} - -buildMachineWithOldIsoCheckUpgrade() { - run wget https://github.com/boot2docker/boot2docker/releases/download/v1.4.1/boot2docker.iso -O $MACHINE_STORAGE_PATH/cache/boot2docker.iso - run machine create -d virtualbox $NAME - run machine upgrade $NAME -} - -@test "$DRIVER: machine should not exist" { - run machine inspect $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: VM should not exist" { - run VBoxManage showvminfo $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: quiet ls" { - run machine ls -q - [[ ${output} == "$NAME" ]] -} - -@test "$DRIVER: check default machine memory size" { - findMemorySize - [[ ${output} == "${DEFAULT_MEMSIZE}" ]] -} - -@test "$DRIVER: check default machine disksize" { - findDiskSize - [[ ${output} == *"$DEFAULT_DISKSIZE"* ]] -} - -@test "$DRIVER: upgrade" { - run machine upgrade $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ls" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"$NAME"* ]] -} - -@test "$DRIVER: run busybox container" { - run docker $(machine config $NAME) run busybox echo hello world - [ "$status" -eq 0 ] -} - -@test "$DRIVER: url" { - run machine url $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ip" { - run machine ip $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ssh" { - run machine ssh $NAME -- ls -lah / - [ "$status" -eq 0 ] - [[ ${lines[0]} =~ "total" ]] -} - -@test "$DRIVER: docker commands with the socket should work" { - run machine ssh $NAME -- docker version -} - -@test "$DRIVER: stop" { - run machine stop $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show stopped after stop" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Stopped"* ]] -} - -@test "$DRIVER: machine should not allow upgrade when stopped" { - run machine upgrade $NAME - [[ "$status" -eq 1 ]] -} - -@test "$DRIVER: url should show an error when machine is stopped" { - run machine url $NAME - [ "$status" -eq 1 ] - [[ ${output} == "host is not running" ]] -} - -@test "$DRIVER: env should show an error when machine is stopped" { - run machine env $NAME - [ "$status" -eq 1 ] - [[ ${output} == *"not running. Please start this with"* ]] -} - -@test "$DRIVER: start" { - run machine start $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after start" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: kill" { - run machine kill $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show stopped after kill" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Stopped"* ]] -} - -@test "$DRIVER: restart" { - run machine restart $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after restart" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: VBoxManage pause" { - run VBoxManage controlvm $NAME pause - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show paused after VBoxManage pause" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Paused"* ]] -} - -@test "$DRIVER: start after paused" { - run machine start $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after start" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: VBoxManage savestate" { - run VBoxManage controlvm $NAME savestate - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show saved after VBoxManage savestate" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"$NAME"* ]] - [[ ${lines[1]} == *"Saved"* ]] -} - -@test "$DRIVER: start after saved" { - run machine start $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after start" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: remove after paused" { - run machine rm -f $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should not exist after remove" { - run machine inspect $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: VM should not exist after remove" { - run VBoxManage showvminfo $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: create with arbitrary engine option" { - run machine create -d $DRIVER \ - --engine-opt log-driver=none \ - $NAME - [ $status -eq 0 ] -} - -@test "$DRIVER: check created engine option (log driver)" { - docker $(machine config $NAME) run --name nolog busybox echo this should not be logged - run docker $(machine config $NAME) logs nolog - [ $status -eq 1 ] -} - -@test "$DRIVER: rm after arbitrary engine option create" { - run machine rm $NAME - [ $status -eq 0 ] -} - -@test "$DRIVER: create with supported engine options" { - run machine create -d $DRIVER \ - --engine-label spam=eggs \ - --engine-storage-driver devicemapper \ - --engine-insecure-registry registry.myco.com \ - $NAME - echo "$output" - [ $status -eq 0 ] -} - -@test "$DRIVER: check for engine labels" { - spamlabel=$(docker $(machine config $NAME) info | grep spam) - [[ $spamlabel =~ "spam=eggs" ]] -} - -@test "$DRIVER: check for engine storage driver" { - storage_driver_info=$(docker $(machine config $NAME) info | grep "Storage Driver") - [[ $storage_driver_info =~ "devicemapper" ]] -} - -@test "$DRIVER: check for insecure registry setting" { - ir_option=$(machine ssh $NAME -- cat /var/lib/boot2docker/profile | grep insecure-registry) - [[ $ir_option =~ "registry.myco.com" ]] -} - -@test "$DRIVER: rm after supported engine option create" { - run machine rm $NAME - [ $status -eq 0 ] -} - -@test "$DRIVER: create too small disk size" { - run machine create -d $DRIVER --virtualbox-disk-size 0 $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: remove after too small create" { - run machine rm -f $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: create too large disk size" { - skip "this will take too long to run effectively" - run machine create -d $DRIVER --virtualbox-disk-size 1000000 $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: remove after too large create" { - skip "no need to remove if large test not run" - run machine rm -f $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: should not create with incorrect value type for disk size" { - run machine create -d $DRIVER --virtualbox-disk-size ffsfwf $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: create too small memory size" { - run machine create -d $DRIVER --virtualbox-memory 0 $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: remove after too small memory" { - run machine rm -f $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: create with bad boot2docker url" { - run machine create -d $DRIVER --virtualbox-boot2docker-url $BAD_URL $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: remove after bad boot2docker url" { - run machine rm -f $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: create with no storage driver" { - run machine create -d $DRIVER --engine-storage-driver "" $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: create with custom disk, cpu count and memory size flags" { - run machine create -d $DRIVER --virtualbox-cpu-count $CUSTOM_CPUCOUNT --virtualbox-disk-size $CUSTOM_DISKSIZE --virtualbox-memory $CUSTOM_MEMSIZE $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: check custom machine memory size" { - findMemorySize - [[ ${output} == "$CUSTOM_MEMSIZE" ]] -} - -@test "$DRIVER: check custom machine disksize" { - findDiskSize - [[ ${output} == *"$CUSTOM_DISKSIZE"* ]] -} - -@test "$DRIVER: check custom machine cpucount" { - findCPUCount - [[ ${output} == "$CUSTOM_CPUCOUNT" ]] -} - -@test "$DRIVER: machine should show running after create" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: remove after custom flag create" { - run machine rm -f $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: can create custom machine using disk size, cpu count and memory size via env vars" { - VIRTUALBOX_DISK_SIZE=$CUSTOM_DISKSIZE VIRTUALBOX_CPU_COUNT=$CUSTOM_CPUCOUNT VIRTUALBOX_MEMORY_SIZE=$CUSTOM_MEMSIZE run machine create -d $DRIVER $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: check machine's memory size was set correctly by env var" { - findMemorySize - [[ ${output} == "$CUSTOM_MEMSIZE" ]] -} - -@test "$DRIVER: check machine's disk size was set correctly by env var" { - findDiskSize - [[ ${output} == *"$CUSTOM_DISKSIZE"* ]] -} - -@test "$DRIVER: check custom machine cpucount" { - findCPUCount - [[ ${output} == "$CUSTOM_CPUCOUNT" ]] -} - -@test "$DRIVER: machine should show running after create with env" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: remove after custom env create" { - run machine rm -f $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: upgrade should work" { - buildMachineWithOldIsoCheckUpgrade - [ "$status" -eq 0 ] -} - -@test "$DRIVER: remove machine after upgrade test" { - run machine rm -f $NAME -} - -# Cleanup of machine store should always be the last 'test' -@test "$DRIVER: cleanup" { - run rm -rf $MACHINE_STORAGE_PATH - [ "$status" -eq 0 ] -} - diff --git a/test/integration/driver-vmwarevcloudair.bats b/test/integration/driver-vmwarevcloudair.bats deleted file mode 100644 index 07883969ad..0000000000 --- a/test/integration/driver-vmwarevcloudair.bats +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env bats - -load helpers - -export DRIVER=vmwarevcloudair -export NAME="bats-$DRIVER-test" -export MACHINE_STORAGE_PATH=/tmp/machine-bats-test-$DRIVER - -@test "$DRIVER: machine should not exist" { - run machine inspect $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: create" { - run machine create -d $DRIVER $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ls" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"$NAME"* ]] -} - -@test "$DRIVER: run busybox container" { - run docker $(machine config $NAME) run busybox echo hello world - [ "$status" -eq 0 ] -} - -@test "$DRIVER: url" { - run machine url $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ip" { - run machine ip $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: ssh" { - run machine ssh $NAME -- ls -lah / - [ "$status" -eq 0 ] - [[ ${lines[0]} =~ "total" ]] -} - -@test "$DRIVER: stop" { - run machine stop $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show stopped after stop" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Stopped"* ]] -} - -@test "$DRIVER: start" { - run machine start $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after start" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: kill" { - run machine kill $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show stopped after kill" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Stopped"* ]] -} - -@test "$DRIVER: restart" { - run machine restart $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should show running after restart" { - run machine ls - [ "$status" -eq 0 ] - [[ ${lines[1]} == *"Running"* ]] -} - -@test "$DRIVER: remove" { - run machine rm -f $NAME - [ "$status" -eq 0 ] -} - -@test "$DRIVER: machine should not exist" { - run machine inspect $NAME - [ "$status" -eq 1 ] -} - -@test "$DRIVER: cleanup" { - run rm -rf $MACHINE_STORAGE_PATH - [ "$status" -eq 0 ] -} - diff --git a/test/integration/drivers/virtualbox/bad-create-iso.bats b/test/integration/drivers/virtualbox/bad-create-iso.bats new file mode 100644 index 0000000000..93d337ad85 --- /dev/null +++ b/test/integration/drivers/virtualbox/bad-create-iso.bats @@ -0,0 +1,10 @@ +#!/usr/bin/env bats + +load ${BASE_TEST_DIR}/helpers.bash + +export BAD_URL="http://dev.null:9111/bad.iso" + +@test "$DRIVER: Should not allow machine creation with bad ISO" { + run machine create -d virtualbox --virtualbox-boot2docker-url $BAD_URL $NAME + [[ ${status} -eq 1 ]] +} diff --git a/test/integration/drivers/virtualbox/custom-mem-disk.bats b/test/integration/drivers/virtualbox/custom-mem-disk.bats new file mode 100644 index 0000000000..377944f914 --- /dev/null +++ b/test/integration/drivers/virtualbox/custom-mem-disk.bats @@ -0,0 +1,54 @@ +#!/usr/bin/env bats + +load ${BASE_TEST_DIR}/helpers.bash + +# Default memsize is 1024MB and disksize is 20000MB +# These values are defined in drivers/virtualbox/virtualbox.go +export DEFAULT_MEMSIZE=1024 +export DEFAULT_DISKSIZE=20000 +export CUSTOM_MEMSIZE=1536 +export CUSTOM_DISKSIZE=10000 +export CUSTOM_CPUCOUNT=1 + +function findDiskSize() { + # SATA-0-0 is usually the boot2disk.iso image + # We assume that SATA 1-0 is root disk VMDK and grab this UUID + # e.g. "SATA-ImageUUID-1-0"="fb5f33a7-e4e3-4cb9-877c-f9415ae2adea" + # TODO(slashk): does this work on Windows ? + run bash -c "VBoxManage showvminfo --machinereadable $NAME | grep SATA-ImageUUID-1-0 | cut -d'=' -f2" + run bash -c "VBoxManage showhdinfo $output | grep "Capacity:" | awk -F' ' '{ print $2 }'" +} + +function findMemorySize() { + run bash -c "VBoxManage showvminfo --machinereadable $NAME | grep memory= | cut -d'=' -f2" +} + +function findCPUCount() { + run bash -c "VBoxManage showvminfo --machinereadable $NAME | grep cpus= | cut -d'=' -f2" +} + +@test "$DRIVER: create with custom disk, cpu count and memory size flags" { + run machine create -d $DRIVER --virtualbox-cpu-count $CUSTOM_CPUCOUNT --virtualbox-disk-size $CUSTOM_DISKSIZE --virtualbox-memory $CUSTOM_MEMSIZE $NAME + [ "$status" -eq 0 ] +} + +@test "$DRIVER: check custom machine memory size" { + findMemorySize + [[ ${output} == "$CUSTOM_MEMSIZE" ]] +} + +@test "$DRIVER: check custom machine disksize" { + findDiskSize + [[ ${output} == *"$CUSTOM_DISKSIZE"* ]] +} + +@test "$DRIVER: check custom machine cpucount" { + findCPUCount + [[ ${output} == "$CUSTOM_CPUCOUNT" ]] +} + +@test "$DRIVER: machine should show running after create" { + run machine ls + [ "$status" -eq 0 ] + [[ ${lines[1]} == *"Running"* ]] +} diff --git a/test/integration/drivers/virtualbox/pause-save-start.bats b/test/integration/drivers/virtualbox/pause-save-start.bats new file mode 100644 index 0000000000..6e75401858 --- /dev/null +++ b/test/integration/drivers/virtualbox/pause-save-start.bats @@ -0,0 +1,53 @@ +#!/usr/bin/env bats + +load ${BASE_TEST_DIR}/helpers.bash + +@test "$DRIVER: create" { + run machine create -d $DRIVER $NAME + [ "$status" -eq 0 ] +} + +@test "$DRIVER: VBoxManage pause" { + run VBoxManage controlvm $NAME pause + [ "$status" -eq 0 ] +} + +@test "$DRIVER: machine should show paused after VBoxManage pause" { + run machine ls + [ "$status" -eq 0 ] + [[ ${lines[1]} == *"Paused"* ]] +} + +@test "$DRIVER: start after paused" { + run machine start $NAME + [ "$status" -eq 0 ] +} + +@test "$DRIVER: machine should show running after start" { + run machine ls + [ "$status" -eq 0 ] + [[ ${lines[1]} == *"Running"* ]] +} + +@test "$DRIVER: VBoxManage savestate" { + run VBoxManage controlvm $NAME savestate + [ "$status" -eq 0 ] +} + +@test "$DRIVER: machine should show saved after VBoxManage savestate" { + run machine ls + [ "$status" -eq 0 ] + [[ ${lines[1]} == *"$NAME"* ]] + [[ ${lines[1]} == *"Saved"* ]] +} + +@test "$DRIVER: start after saved" { + run machine start $NAME + [ "$status" -eq 0 ] +} + +@test "$DRIVER: machine should show running after start" { + run machine ls + [ "$status" -eq 0 ] + [[ ${lines[1]} == *"Running"* ]] +} diff --git a/test/integration/drivers/virtualbox/upgrade.bats b/test/integration/drivers/virtualbox/upgrade.bats new file mode 100644 index 0000000000..267500e4df --- /dev/null +++ b/test/integration/drivers/virtualbox/upgrade.bats @@ -0,0 +1,26 @@ +#!/usr/bin/env bats + +load ${BASE_TEST_DIR}/helpers.bash + +export OLD_ISO_URL="https://github.com/boot2docker/boot2docker/releases/download/v1.4.1/boot2docker.iso" + +@test "$DRIVER: create for upgrade" { + run machine create -d virtualbox --virtualbox-boot2docker-url $OLD_ISO_URL $NAME +} + +@test "$DRIVER: verify that docker version is old" { + # Have to run this over SSH due to client/server mismatch restriction + SERVER_VERSION=$(machine ssh $NAME docker version | grep 'Server version' | awk '{ print $3; }') + [[ "$SERVER_VERSION" == "1.4.1" ]] +} + +@test "$DRIVER: upgrade" { + run machine upgrade $NAME + echo ${output} + [ "$status" -eq 0 ] +} + +@test "$DRIVER: upgrade is correct version" { + SERVER_VERSION=$(docker $(machine config $NAME) version | grep 'Server version' | awk '{ print $3; }') + [[ "$SERVER_VERSION" != "1.4.1" ]] +} diff --git a/test/integration/helpers.bash b/test/integration/helpers.bash index efd36a2393..e54c391889 100644 --- a/test/integration/helpers.bash +++ b/test/integration/helpers.bash @@ -1,29 +1,5 @@ #!/bin/bash -# Root directory of the repository. -MACHINE_ROOT=${BATS_TEST_DIRNAME}/../.. - -PLATFORM=`uname -s | tr '[:upper:]' '[:lower:]'` -case "$(uname -m)" in - arm*) - ARCH="arm" - ;; - x86_64) - ARCH="amd64" - ;; - i*86) - ARCH="386" - ;; - *) - ARCH="$(uname -m)" -esac - -MACHINE_BIN_NAME=docker-machine_$PLATFORM-$ARCH -BATS_LOG=${MACHINE_ROOT}/bats.log - -touch ${BATS_LOG} -rm ${BATS_LOG} - teardown() { echo "$BATS_TEST_NAME ---------- @@ -32,18 +8,3 @@ $output " >> ${BATS_LOG} } - -build_machine() { - pushd $MACHINE_ROOT >/dev/null - godep go build -o $MACHINE_BIN_NAME - popd >/dev/null -} - -# build machine binary if needed -if [ ! -e $MACHINE_ROOT/$MACHINE_BIN_NAME ]; then - build_machine -fi - -function machine() { - ${MACHINE_ROOT}/$MACHINE_BIN_NAME "$@" -} diff --git a/test/integration/run-bats.sh b/test/integration/run-bats.sh new file mode 100755 index 0000000000..406e02cfc2 --- /dev/null +++ b/test/integration/run-bats.sh @@ -0,0 +1,108 @@ +#!/bin/bash + +set -e + +# Wrapper script to run bats tests for various drivers. +# Usage: DRIVER=[driver] ./run-bats.sh [subtest] + +function build_machine() { + cd ${MACHINE_ROOT} + ./script/build + cd - +} + +function quiet_run () { + if [[ "$VERBOSE" == "1" ]]; then + "$@" + else + "$@" &>/dev/null + fi +} + +function cleanup_machines() { + if [[ $(docker-machine ls -q | wc -l) -ne 0 ]]; then + quiet_run machine stop $(machine ls -q) + quiet_run machine rm $(machine ls -q) + fi +} + +function machine() { + "$MACHINE_ROOT"/"$MACHINE_BIN_NAME" "$@" +} + +function run_bats() { + for bats_file in $(find "$1" -name \*.bats); do + # 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. + set +e + bats "$bats_file" + if [[ $? -ne 0 ]]; then + EXIT_STATUS=1 + fi + set -e + cleanup_machines + done +} + +# Platform and architecture information is used to correctly identify the +# binary we want to test. +PLATFORM=`uname -s | tr '[:upper:]' '[:lower:]'` +case "$(uname -m)" in + arm*) + ARCH="arm" + ;; + x86_64) + ARCH="amd64" + ;; + i*86) + ARCH="386" + ;; + *) + ARCH="$(uname -m)" +esac + +# Set this ourselves in case bats call fails +EXIT_STATUS=0 +export BATS_FILE="$1" + +# build machine binary if needed +if [ ! -e "$MACHINE_ROOT"/"$MACHINE_BIN_NAME" ]; then + build_machine +fi + +if [[ -z "$DRIVER" ]]; then + echo "The DRIVER environment variable must be set." + exit 1 +fi + +if [[ -z "$BATS_FILE" ]]; then + echo "You must specify a bats test to run." + exit 1 +fi + +if [[ ! -e "$BATS_FILE" ]]; then + echo "Requested bats file or directory not found: $BATS_FILE" + exit 1 +fi + +# TODO: Should the script bail out if these are set already? +export BASE_TEST_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +export MACHINE_ROOT="$BASE_TEST_DIR/../.." +export NAME="bats-$DRIVER-test" +export MACHINE_STORAGE_PATH="/tmp/machine-bats-test-$DRIVER" +export MACHINE_BIN_NAME=docker-machine_$PLATFORM-$ARCH +export BATS_LOG="$MACHINE_ROOT/bats.log" + +# This function gets used in the integration tests, so export it. +export -f machine + +touch "$BATS_LOG" +rm "$BATS_LOG" + +run_bats "$BATS_FILE" + +if [[ -d "$MACHINE_STORAGE_PATH" ]]; then + rm -r "$MACHINE_STORAGE_PATH" +fi + +exit ${EXIT_STATUS}