diff --git a/README.md b/README.md index ab773f56ee..08d1f18b9d 100644 --- a/README.md +++ b/README.md @@ -142,3 +142,15 @@ run: If you have any questions we're in #docker-machine on Freenode. +======= +## Integration Tests +There is a suite of integration tests that will run for the drivers. In order +to use these you must export the corresponding environment variables for each +driver as these perform the actual actions (start, stop, restart, kill, etc). + +By default, the suite will run tests against all drivers in master. You can +override this by setting the environment variable `MACHINE_TESTS`. For example, +`MACHINE_TESTS="virtualbox" ./script/run-integration-tests` will only run the +virtualbox driver integration tests. + +To run, use the helper script `./script/run-integration-tests`. diff --git a/_integration-test/machine_test.go b/_integration-test/machine_test.go new file mode 100644 index 0000000000..3c4f8c68ff --- /dev/null +++ b/_integration-test/machine_test.go @@ -0,0 +1,152 @@ +package main + +import ( + "fmt" + "os/exec" + "sync" + "testing" +) + +const ( + MACHINE_NAME = "machine-integration-test-%s" +) + +func machineCreate(name string, t *testing.T, wg *sync.WaitGroup) { + mName := fmt.Sprintf(MACHINE_NAME, name) + fmt.Printf(" - testing create for %s (%s)\n", name, mName) + runCmd := exec.Command(machineBinary, "create", "-d", name, mName) + out, exitCode, err := runCommandWithOutput(runCmd) + if err != nil { + t.Error(out, err) + } + if exitCode != 0 { + t.Errorf("error creating machine: driver: %s; exit code: %d; output: %s", name, exitCode, out) + } + wg.Done() +} + +func machineStop(name string, t *testing.T, wg *sync.WaitGroup) { + mName := fmt.Sprintf(MACHINE_NAME, name) + fmt.Printf(" - testing stop for %s (%s)\n", name, mName) + runCmd := exec.Command(machineBinary, "stop", mName) + out, exitCode, err := runCommandWithOutput(runCmd) + if err != nil { + t.Error(out, err) + } + if exitCode != 0 { + t.Errorf("error stopping machine: driver: %s; exit code: %d; output: %s", name, exitCode, out) + } + wg.Done() +} + +func machineStart(name string, t *testing.T, wg *sync.WaitGroup) { + mName := fmt.Sprintf(MACHINE_NAME, name) + fmt.Printf(" - testing start for %s (%s)\n", name, mName) + runCmd := exec.Command(machineBinary, "start", mName) + out, exitCode, err := runCommandWithOutput(runCmd) + if err != nil { + t.Error(out, err) + } + if exitCode != 0 { + t.Errorf("error starting machine: driver: %s; exit code: %d; output: %s", name, exitCode, out) + } + wg.Done() +} + +func machineKill(name string, t *testing.T, wg *sync.WaitGroup) { + mName := fmt.Sprintf(MACHINE_NAME, name) + fmt.Printf(" - testing kill for %s (%s)\n", name, mName) + runCmd := exec.Command(machineBinary, "kill", mName) + out, exitCode, err := runCommandWithOutput(runCmd) + if err != nil { + t.Error(out, err) + } + if exitCode != 0 { + t.Errorf("error killing machine: driver: %s; exit code: %d; output: %s", name, exitCode, out) + } + wg.Done() +} + +func machineRm(name string, t *testing.T, wg *sync.WaitGroup) { + mName := fmt.Sprintf(MACHINE_NAME, name) + fmt.Printf(" - testing rm for %s (%s)\n", name, mName) + runCmd := exec.Command(machineBinary, "rm", "-f", mName) + out, exitCode, err := runCommandWithOutput(runCmd) + if err != nil { + t.Error(out, err) + } + if exitCode != 0 { + t.Errorf("error removing machine: driver: %s; exit code: %d; output: %s", name, exitCode, out) + } + wg.Done() +} + +// TestMachineCreate will test that the driver creates the machine +func TestMachineCreate(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } + + var wg sync.WaitGroup + for _, d := range machineTestDrivers { + wg.Add(1) + go machineCreate(d.name, t, &wg) + } + wg.Wait() +} + +// TestMachineCreate will test that the driver stops the machine +func TestMachineStop(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } + + var wg sync.WaitGroup + for _, d := range machineTestDrivers { + wg.Add(1) + go machineStop(d.name, t, &wg) + } + wg.Wait() +} + +// TestMachineCreate will test that the driver starts the machine +func TestMachineStart(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } + + var wg sync.WaitGroup + for _, d := range machineTestDrivers { + wg.Add(1) + go machineStart(d.name, t, &wg) + } + wg.Wait() +} + +// TestMachineCreate will test that the driver kills the machine +func TestMachineKill(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } + + var wg sync.WaitGroup + for _, d := range machineTestDrivers { + wg.Add(1) + go machineKill(d.name, t, &wg) + } + wg.Wait() +} + +// TestMachineCreate will test that the driver removes the machine +func TestMachineRemove(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } + + var wg sync.WaitGroup + for _, d := range machineTestDrivers { + wg.Add(1) + go machineRm(d.name, t, &wg) + } + wg.Wait() +} diff --git a/script/run-integration-tests b/script/run-integration-tests index 4c9dc04310..d16f3053ac 100755 --- a/script/run-integration-tests +++ b/script/run-integration-tests @@ -1,7 +1,3 @@ #!/bin/sh -# HACK: until identity is merged -curl -sSL -o .docker-identity https://bfirsh.s3.amazonaws.com/docker/linux/docker-1.3.1-dev-identity-auth && chmod +x .docker-identity -./.docker-identity > /dev/null 2>&1 -godep go build go test -v ./_integration-test diff --git a/script/test-integration b/script/test-integration deleted file mode 100755 index 144d29f3d1..0000000000 --- a/script/test-integration +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -set -e -docker build -t docker-machine . -exec docker run --rm $* docker-machine ./script/run-integration-tests