integ-cli: fix TestImportDisplay & add FileServer

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
Upstream-commit: 9e5592d6a10ce02fb77244c7de3fff38958e0b89
Component: engine
This commit is contained in:
unclejack
2014-09-12 20:10:42 +03:00
parent 3f5c1d5939
commit 86091bac44
3 changed files with 39 additions and 1 deletions

View File

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