瀏覽代碼

Move TestContainerApiCreate to integration-cli

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Brian Goff 10 年之前
父節點
當前提交
23fa7d41d5
共有 2 個文件被更改,包括 27 次插入40 次删除
  1. 27 0
      integration-cli/docker_api_containers_test.go
  2. 0 40
      integration/api_test.go

+ 27 - 0
integration-cli/docker_api_containers_test.go

@@ -694,3 +694,30 @@ func TestContainerApiCommit(t *testing.T) {
 
 	logDone("containers REST API - POST /commit")
 }
+
+func TestContainerApiCreate(t *testing.T) {
+	defer deleteAllContainers()
+	config := map[string]interface{}{
+		"Image": "busybox",
+		"Cmd":   []string{"/bin/sh", "-c", "touch /test && ls /test"},
+	}
+
+	_, b, err := sockRequest("POST", "/containers/create", config)
+	if err != nil && !strings.Contains(err.Error(), "200 OK: 201") {
+		t.Fatal(err)
+	}
+	type createResp struct {
+		Id string
+	}
+	var container createResp
+	if err := json.Unmarshal(b, &container); err != nil {
+		t.Fatal(err)
+	}
+
+	out, _, _ := dockerCmd(t, "start", "-a", container.Id)
+	if strings.TrimSpace(out) != "/test" {
+		t.Fatalf("expected output `/test`, got %q", out)
+	}
+
+	logDone("containers REST API - POST /containers/create")
+}

+ 0 - 40
integration/api_test.go

@@ -22,46 +22,6 @@ import (
 	"github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
 )
 
-func TestPostContainersCreate(t *testing.T) {
-	eng := NewTestEngine(t)
-	defer mkDaemonFromEngine(eng, t).Nuke()
-
-	configJSON, err := json.Marshal(&runconfig.Config{
-		Image: unitTestImageID,
-		Cmd:   runconfig.NewCommand("touch", "/test"),
-	})
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	req, err := http.NewRequest("POST", "/containers/create", bytes.NewReader(configJSON))
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	req.Header.Set("Content-Type", "application/json")
-
-	r := httptest.NewRecorder()
-	server.ServeRequest(eng, api.APIVERSION, r, req)
-	assertHttpNotError(r, t)
-	if r.Code != http.StatusCreated {
-		t.Fatalf("%d Created expected, received %d\n", http.StatusCreated, r.Code)
-	}
-
-	var apiRun engine.Env
-	if err := apiRun.Decode(r.Body); err != nil {
-		t.Fatal(err)
-	}
-	containerID := apiRun.Get("Id")
-
-	containerAssertExists(eng, containerID, t)
-	containerRun(eng, containerID, t)
-
-	if !containerFileExists(eng, containerID, "test", t) {
-		t.Fatal("Test file was not created")
-	}
-}
-
 func TestPostJsonVerify(t *testing.T) {
 	eng := NewTestEngine(t)
 	defer mkDaemonFromEngine(eng, t).Nuke()