Upgrade go-dockerclient dependency to support CgroupParent

This commit is contained in:
Tobi Knaup
2015-04-23 20:46:45 +00:00
parent f7831dcd93
commit 522d4c3b85
14 changed files with 329 additions and 123 deletions

View File

@@ -25,6 +25,8 @@ import (
"github.com/gorilla/mux"
)
var nameRegexp = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_.-]+$`)
// DockerServer represents a programmable, concurrent (not much), HTTP server
// implementing a fake version of the Docker remote API.
//
@@ -339,6 +341,11 @@ func (s *DockerServer) createContainer(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
name := r.URL.Query().Get("name")
if name != "" && !nameRegexp.MatchString(name) {
http.Error(w, "Invalid container name", http.StatusInternalServerError)
return
}
if _, err := s.findImage(config.Image); err != nil {
http.Error(w, err.Error(), http.StatusNotFound)
return
@@ -363,7 +370,7 @@ func (s *DockerServer) createContainer(w http.ResponseWriter, r *http.Request) {
}
container := docker.Container{
Name: r.URL.Query().Get("name"),
Name: name,
ID: s.generateID(),
Created: time.Now(),
Path: path,

View File

@@ -241,6 +241,24 @@ func TestCreateContainerInvalidBody(t *testing.T) {
}
}
func TestCreateContainerInvalidName(t *testing.T) {
server := DockerServer{}
server.buildMuxer()
recorder := httptest.NewRecorder()
body := `{"Hostname":"", "User":"", "Memory":0, "MemorySwap":0, "AttachStdin":false, "AttachStdout":true, "AttachStderr":true,
"PortSpecs":null, "Tty":false, "OpenStdin":false, "StdinOnce":false, "Env":null, "Cmd":["date"],
"Image":"base", "Volumes":{}, "VolumesFrom":""}`
request, _ := http.NewRequest("POST", "/containers/create?name=myapp/container1", strings.NewReader(body))
server.ServeHTTP(recorder, request)
if recorder.Code != http.StatusInternalServerError {
t.Errorf("CreateContainer: wrong status. Want %d. Got %d.", http.StatusInternalServerError, recorder.Code)
}
expectedBody := "Invalid container name\n"
if got := recorder.Body.String(); got != expectedBody {
t.Errorf("CreateContainer: wrong body. Want %q. Got %q.", expectedBody, got)
}
}
func TestCreateContainerImageNotFound(t *testing.T) {
server := DockerServer{}
server.buildMuxer()