From 9e5592d6a10ce02fb77244c7de3fff38958e0b89 Mon Sep 17 00:00:00 2001 From: unclejack Date: Fri, 12 Sep 2014 20:10:42 +0300 Subject: [PATCH] integ-cli: fix TestImportDisplay & add FileServer Docker-DCO-1.1-Signed-off-by: Cristian Staretu (github: unclejack) --- Dockerfile | 3 +++ integration-cli/docker_cli_import_test.go | 11 +++++++++- integration-cli/utils.go | 26 +++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8f47b0de75..7114d4e00e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -89,6 +89,9 @@ RUN mkdir -p /go/src/github.com/cpuguy83 \ # Get the "busybox" image source so we can build locally instead of pulling RUN git clone -b buildroot-2014.02 https://github.com/jpetazzo/docker-busybox.git /docker-busybox +# Get the "cirros" image source so we can import it instead of fetching it during tests +RUN curl -sSL -o /cirros.tar.gz https://github.com/ewindisch/docker-cirros/raw/1cded459668e8b9dbf4ef976c94c05add9bbd8e9/cirros-0.3.0-x86_64-lxc.tar.gz + # Setup s3cmd config RUN /bin/echo -e '[default]\naccess_key=$AWS_ACCESS_KEY\nsecret_key=$AWS_SECRET_KEY' > /.s3cfg diff --git a/integration-cli/docker_cli_import_test.go b/integration-cli/docker_cli_import_test.go index 6833cd5d76..9a73bd75e1 100644 --- a/integration-cli/docker_cli_import_test.go +++ b/integration-cli/docker_cli_import_test.go @@ -1,13 +1,22 @@ package main import ( + "fmt" "os/exec" "strings" "testing" ) func TestImportDisplay(t *testing.T) { - importCmd := exec.Command(dockerBinary, "import", "https://github.com/ewindisch/docker-cirros/raw/master/cirros-0.3.0-x86_64-lxc.tar.gz") + server, err := fileServer(map[string]string{ + "/cirros.tar.gz": "/cirros.tar.gz", + }) + if err != nil { + t.Fatal(err) + } + defer server.Close() + fileUrl := fmt.Sprintf("%s/cirros.tar.gz", server.URL) + importCmd := exec.Command(dockerBinary, "import", fileUrl) out, _, err := runCommandWithOutput(importCmd) if err != nil { t.Errorf("import failed with errors: %v, output: %q", err, out) diff --git a/integration-cli/utils.go b/integration-cli/utils.go index 9d0aceb156..57b7671ecd 100644 --- a/integration-cli/utils.go +++ b/integration-cli/utils.go @@ -5,6 +5,8 @@ import ( "encoding/json" "fmt" "io" + "net/http" + "net/http/httptest" "os" "os/exec" "reflect" @@ -212,3 +214,27 @@ func ListTar(f io.Reader) ([]string, error) { entries = append(entries, th.Name) } } + +type FileServer struct { + *httptest.Server +} + +func fileServer(files map[string]string) (*FileServer, error) { + var handler http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) { + if filePath, found := files[r.URL.Path]; found { + http.ServeFile(w, r, filePath) + } else { + http.Error(w, http.StatusText(404), 404) + } + } + + for _, file := range files { + if _, err := os.Stat(file); err != nil { + return nil, err + } + } + server := httptest.NewServer(handler) + return &FileServer{ + Server: server, + }, nil +}