mirror of https://github.com/docker/docs.git
started on integration tests
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
parent
a5e55ff007
commit
882f98dcc0
|
|
@ -0,0 +1,147 @@
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
MachineDriver struct {
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
machineBinary = "machine"
|
||||||
|
machineTestDrivers []MachineDriver
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
machineTestDrivers = []MachineDriver{
|
||||||
|
MachineDriver{
|
||||||
|
name: "virtualbox",
|
||||||
|
},
|
||||||
|
MachineDriver{
|
||||||
|
name: "digitalocean",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if machineBin := os.Getenv("MACHINE_BINARY"); machineBin != "" {
|
||||||
|
machineBinary = machineBin
|
||||||
|
} else {
|
||||||
|
whichCmd := exec.Command("which", "machine")
|
||||||
|
out, _, err := runCommandWithOutput(whichCmd)
|
||||||
|
if err == nil {
|
||||||
|
machineBinary = stripTrailingCharacters(out)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
fmt.Printf("ERROR: couldn't resolve full path to the Machine binary")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getExitCode(err error) (int, error) {
|
||||||
|
exitCode := 0
|
||||||
|
if exiterr, ok := err.(*exec.ExitError); ok {
|
||||||
|
if procExit := exiterr.Sys().(syscall.WaitStatus); ok {
|
||||||
|
return procExit.ExitStatus(), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return exitCode, fmt.Errorf("failed to get exit code")
|
||||||
|
}
|
||||||
|
|
||||||
|
func processExitCode(err error) (exitCode int) {
|
||||||
|
if err != nil {
|
||||||
|
var exiterr error
|
||||||
|
if exitCode, exiterr = getExitCode(err); exiterr != nil {
|
||||||
|
// TODO: Fix this so we check the error's text.
|
||||||
|
// we've failed to retrieve exit code, so we set it to 127
|
||||||
|
exitCode = 127
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func runCommandWithOutput(cmd *exec.Cmd) (output string, exitCode int, err error) {
|
||||||
|
exitCode = 0
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
exitCode = processExitCode(err)
|
||||||
|
output = string(out)
|
||||||
|
return
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func stripTrailingCharacters(target string) string {
|
||||||
|
target = strings.Trim(target, "\n")
|
||||||
|
target = strings.Trim(target, " ")
|
||||||
|
return target
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
docker build -t docker-machine .
|
docker build -t docker-machine .
|
||||||
exec docker run --rm docker-machine go test -v ./...
|
exec docker run --rm docker-machine go test -v -short ./...
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
docker build -t docker-machine .
|
||||||
|
exec docker run --rm docker-machine go test -v $* ./...
|
||||||
Loading…
Reference in New Issue