1
0
mirror of https://github.com/rancher/os.git synced 2025-07-05 11:06:13 +00:00

Newer github.com/fsouza/go-dockerclient

This commit is contained in:
Darren Shepherd 2015-03-21 16:56:00 -07:00
parent 6a3240f865
commit 63bc3f64b2
4 changed files with 65 additions and 1 deletions

2
Godeps/Godeps.json generated
View File

@ -180,7 +180,7 @@
},
{
"ImportPath": "github.com/fsouza/go-dockerclient",
"Rev": "73a0e3760037ce30d63015a74af4ffe48329dbf8"
"Rev": "f7e250a5d56499f6591bc98fe58b3a6edaf479a8"
},
{
"ImportPath": "github.com/guelfey/go.dbus",

View File

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

View File

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

View File

@ -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()