From 63bc3f64b22c35ced42f502c5fb161986b0795cb Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Sat, 21 Mar 2015 16:56:00 -0700 Subject: [PATCH] Newer github.com/fsouza/go-dockerclient --- Godeps/Godeps.json | 2 +- .../fsouza/go-dockerclient/container.go | 9 +++++ .../fsouza/go-dockerclient/testing/server.go | 20 +++++++++++ .../go-dockerclient/testing/server_test.go | 35 +++++++++++++++++++ 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index eaec7c41..76a2592c 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -180,7 +180,7 @@ }, { "ImportPath": "github.com/fsouza/go-dockerclient", - "Rev": "73a0e3760037ce30d63015a74af4ffe48329dbf8" + "Rev": "f7e250a5d56499f6591bc98fe58b3a6edaf479a8" }, { "ImportPath": "github.com/guelfey/go.dbus", diff --git a/Godeps/_workspace/src/github.com/fsouza/go-dockerclient/container.go b/Godeps/_workspace/src/github.com/fsouza/go-dockerclient/container.go index e6bf2422..8d0facc8 100644 --- a/Godeps/_workspace/src/github.com/fsouza/go-dockerclient/container.go +++ b/Godeps/_workspace/src/github.com/fsouza/go-dockerclient/container.go @@ -377,6 +377,14 @@ func NeverRestart() RestartPolicy { return RestartPolicy{Name: "no"} } +// Device represents a device mapping between the Docker host and the +// container. +type Device struct { + PathOnHost string `json:"PathOnHost,omitempty" yaml:"PathOnHost,omitempty"` + PathInContainer string `json:"PathInContainer,omitempty" yaml:"PathInContainer,omitempty"` + CgroupPermissions string `json:"CgroupPermissions,omitempty" yaml:"CgroupPermissions,omitempty"` +} + // HostConfig contains the container options related to starting a container on // a given host type HostConfig struct { @@ -397,6 +405,7 @@ type HostConfig struct { IpcMode string `json:"IpcMode,omitempty" yaml:"IpcMode,omitempty"` PidMode string `json:"PidMode,omitempty" yaml:"PidMode,omitempty"` RestartPolicy RestartPolicy `json:"RestartPolicy,omitempty" yaml:"RestartPolicy,omitempty"` + Devices []Device `json:"Devices,omitempty" yaml:"Devices,omitempty"` } // StartContainer starts a container, returning an error in case of failure. diff --git a/Godeps/_workspace/src/github.com/fsouza/go-dockerclient/testing/server.go b/Godeps/_workspace/src/github.com/fsouza/go-dockerclient/testing/server.go index 2c7661e2..54f22d7a 100644 --- a/Godeps/_workspace/src/github.com/fsouza/go-dockerclient/testing/server.go +++ b/Godeps/_workspace/src/github.com/fsouza/go-dockerclient/testing/server.go @@ -44,6 +44,7 @@ type DockerServer struct { mux *mux.Router hook func(*http.Request) failures map[string]string + multiFailures []map[string]string execCallbacks map[string]func() customHandlers map[string]http.Handler handlerMutex sync.RWMutex @@ -156,6 +157,12 @@ func (s *DockerServer) PrepareFailure(id string, urlRegexp string) { s.failures[id] = urlRegexp } +// PrepareMultiFailures enqueues a new expected failure based on a URL regexp +// it receives an id for the failure. +func (s *DockerServer) PrepareMultiFailures(id string, urlRegexp string) { + s.multiFailures = append(s.multiFailures, map[string]string{"error": id, "url": urlRegexp}) +} + // ResetFailure removes an expected failure identified by the given id. func (s *DockerServer) ResetFailure(id string) { delete(s.failures, id) @@ -237,6 +244,19 @@ func (s *DockerServer) handlerWrapper(f func(http.ResponseWriter, *http.Request) http.Error(w, errorID, http.StatusBadRequest) return } + for i, failure := range s.multiFailures { + matched, err := regexp.MatchString(failure["url"], r.URL.Path) + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + if !matched { + continue + } + http.Error(w, failure["error"], http.StatusBadRequest) + s.multiFailures = append(s.multiFailures[:i], s.multiFailures[i+1:]...) + return + } f(w, r) } } diff --git a/Godeps/_workspace/src/github.com/fsouza/go-dockerclient/testing/server_test.go b/Godeps/_workspace/src/github.com/fsouza/go-dockerclient/testing/server_test.go index 7bea37ed..2b1bccce 100644 --- a/Godeps/_workspace/src/github.com/fsouza/go-dockerclient/testing/server_test.go +++ b/Godeps/_workspace/src/github.com/fsouza/go-dockerclient/testing/server_test.go @@ -1110,6 +1110,41 @@ func TestPrepareFailure(t *testing.T) { } } +func TestPrepareMultiFailures(t *testing.T) { + server := DockerServer{multiFailures: []map[string]string{}} + server.buildMuxer() + errorID := "multi error" + server.PrepareMultiFailures(errorID, "containers/json") + server.PrepareMultiFailures(errorID, "containers/json") + recorder := httptest.NewRecorder() + request, _ := http.NewRequest("GET", "/containers/json?all=1", nil) + server.ServeHTTP(recorder, request) + if recorder.Code != http.StatusBadRequest { + t.Errorf("PrepareFailure: wrong status. Want %d. Got %d.", http.StatusBadRequest, recorder.Code) + } + if recorder.Body.String() != errorID+"\n" { + t.Errorf("PrepareFailure: wrong message. Want %s. Got %s.", errorID, recorder.Body.String()) + } + recorder = httptest.NewRecorder() + request, _ = http.NewRequest("GET", "/containers/json?all=1", nil) + server.ServeHTTP(recorder, request) + if recorder.Code != http.StatusBadRequest { + t.Errorf("PrepareFailure: wrong status. Want %d. Got %d.", http.StatusBadRequest, recorder.Code) + } + if recorder.Body.String() != errorID+"\n" { + t.Errorf("PrepareFailure: wrong message. Want %s. Got %s.", errorID, recorder.Body.String()) + } + recorder = httptest.NewRecorder() + request, _ = http.NewRequest("GET", "/containers/json?all=1", nil) + server.ServeHTTP(recorder, request) + if recorder.Code != http.StatusOK { + t.Errorf("PrepareFailure: wrong status. Want %d. Got %d.", http.StatusOK, recorder.Code) + } + if recorder.Body.String() == errorID+"\n" { + t.Errorf("PrepareFailure: wrong message. Want %s. Got %s.", errorID, recorder.Body.String()) + } +} + func TestRemoveFailure(t *testing.T) { server := DockerServer{failures: make(map[string]string)} server.buildMuxer()