moby/integration-cli/fixtures.go
Brian Goff ff91276d1f Move some test fixtures to go
moves ensure-frozen-images to go
moves ensure-syscall-test to go
moves ensure-nnp-test to go
moves ensure-httpserver to go

Also makes some of the fixtures load only for the required tests.
This makes sure that fixtures that won't be needed for a test run such as
`make TESTFLAGS='-check.f Swarm' test-integration-cli` (for example)
aren't loaded... like the syscall tests.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2016-09-07 17:30:35 -04:00

69 lines
1.6 KiB
Go

package main
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"sync"
)
var ensureHTTPServerOnce sync.Once
func ensureHTTPServerImage() error {
var doIt bool
ensureHTTPServerOnce.Do(func() {
doIt = true
})
if !doIt {
return nil
}
protectedImages["httpserver:latest"] = struct{}{}
tmp, err := ioutil.TempDir("", "docker-http-server-test")
if err != nil {
return fmt.Errorf("could not build http server: %v", err)
}
defer os.RemoveAll(tmp)
goos := daemonPlatform
if goos == "" {
goos = "linux"
}
goarch := os.Getenv("DOCKER_ENGINE_GOARCH")
if goarch == "" {
goarch = "amd64"
}
goCmd, lookErr := exec.LookPath("go")
if lookErr != nil {
return fmt.Errorf("could not build http server: %v", lookErr)
}
cmd := exec.Command(goCmd, "build", "-o", filepath.Join(tmp, "httpserver"), "github.com/docker/docker/contrib/httpserver")
cmd.Env = append(os.Environ(), []string{
"CGO_ENABLED=0",
"GOOS=" + goos,
"GOARCH=" + goarch,
}...)
var out []byte
if out, err = cmd.CombinedOutput(); err != nil {
return fmt.Errorf("could not build http server: %s", string(out))
}
cpCmd, lookErr := exec.LookPath("cp")
if lookErr != nil {
return fmt.Errorf("could not build http server: %v", lookErr)
}
if out, err = exec.Command(cpCmd, "../contrib/httpserver/Dockerfile", filepath.Join(tmp, "Dockerfile")).CombinedOutput(); err != nil {
return fmt.Errorf("could not build http server: %v", string(out))
}
if out, err = exec.Command(dockerBinary, "build", "-q", "-t", "httpserver", tmp).CombinedOutput(); err != nil {
return fmt.Errorf("could not build http server: %v", string(out))
}
return nil
}