MCPcopy Index your code
hub / github.com/fsouza/go-dockerclient / TestCreateMultipleContainersEmptyName

Function TestCreateMultipleContainersEmptyName

testing/server_test.go:402–439  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

400}
401
402func TestCreateMultipleContainersEmptyName(t *testing.T) {
403 t.Parallel()
404 server := baseDockerServer()
405 server.buildMuxer()
406 server.imgIDs = map[string]string{"base": "a1234"}
407 addContainers(&server, 1)
408 getContainer(&server).Name = ""
409 recorder := httptest.NewRecorder()
410 body := `{"Hostname":"", "User":"ubuntu", "Memory":0, "MemorySwap":0, "AttachStdin":false, "AttachStdout":true, "AttachStderr":true,
411"PortSpecs":null, "Tty":false, "OpenStdin":false, "StdinOnce":false, "Env":null, "Cmd":["date"], "Image":"base", "Volumes":{}, "VolumesFrom":"","HostConfig":{"Binds":["/var/run/docker.sock:/var/run/docker.sock:rw"]}}`
412 request, _ := http.NewRequest(http.MethodPost, "/containers/create", strings.NewReader(body))
413 server.ServeHTTP(recorder, request)
414 if recorder.Code != http.StatusCreated {
415 t.Errorf("CreateContainer: wrong status. Want %d. Got %d.", http.StatusCreated, recorder.Code)
416 }
417 var returned docker.Container
418 err := json.NewDecoder(recorder.Body).Decode(&returned)
419 if err != nil {
420 t.Fatal(err)
421 }
422 stored, err := server.findContainer(returned.ID)
423 if err != nil {
424 t.Fatal(err)
425 }
426 if returned.ID != stored.ID {
427 t.Errorf("CreateContainer: ID mismatch. Stored: %q. Returned: %q.", stored.ID, returned.ID)
428 }
429 if stored.State.Running {
430 t.Errorf("CreateContainer should not set container to running state.")
431 }
432 if stored.Config.User != "ubuntu" {
433 t.Errorf("CreateContainer: wrong config. Expected: %q. Returned: %q.", "ubuntu", stored.Config.User)
434 }
435 expectedBind := []string{"/var/run/docker.sock:/var/run/docker.sock:rw"}
436 if !reflect.DeepEqual(stored.HostConfig.Binds, expectedBind) {
437 t.Errorf("CreateContainer: wrong host config. Expected: %v. Returned %v.", expectedBind, stored.HostConfig.Binds)
438 }
439}
440
441func TestCreateContainerInvalidName(t *testing.T) {
442 t.Parallel()

Callers

nothing calls this directly

Calls 7

baseDockerServerFunction · 0.85
addContainersFunction · 0.85
getContainerFunction · 0.85
buildMuxerMethod · 0.80
ServeHTTPMethod · 0.80
DecodeMethod · 0.80
findContainerMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…