1
0
mirror of https://github.com/docker/docs.git synced 2026-11-05 00:14:17 +03:00

Merge pull request #1158 from nathanleclaire/integration_cleanup

Refactor integration tests
This commit is contained in:
Evan Hazlett
2015-06-02 14:46:44 -04:00
27 changed files with 429 additions and 1594 deletions

View File

@@ -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:

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bats
load helpers
load ${BASE_TEST_DIR}/helpers.bash
@test "cli: show info" {
run machine

View File

@@ -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" {

View File

@@ -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 ]
}

View File

@@ -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

View File

@@ -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 ]
}

View File

@@ -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

View File

@@ -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
}

View File

@@ -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 ]
}

View File

@@ -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 ]
}

View File

@@ -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 ]]
}

View File

@@ -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 ]
}

View File

@@ -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 ]
}

View File

@@ -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 ]
}

View File

@@ -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 ]
}

View File

@@ -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 ]
}

View File

@@ -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 ]
}

View File

@@ -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 ]
}

View File

@@ -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 ]
}

View File

@@ -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 ]
}

View File

@@ -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 ]
}

View File

@@ -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 ]]
}

View File

@@ -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"* ]]
}

View File

@@ -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"* ]]
}

View File

@@ -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" ]]
}

View File

@@ -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 "$@"
}

108
test/integration/run-bats.sh Executable file
View File

@@ -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}