Browse Source

Move TestPostCommit to integration-cli

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Brian Goff 10 years ago
parent
commit
f19061ccfd
2 changed files with 29 additions and 39 deletions
  1. 29 0
      integration-cli/docker_api_containers_test.go
  2. 0 39
      integration/api_test.go

+ 29 - 0
integration-cli/docker_api_containers_test.go

@@ -665,3 +665,32 @@ func TestContainerApiTop(t *testing.T) {
 
 
 	logDone("containers REST API -  GET /containers/<id>/top")
 	logDone("containers REST API -  GET /containers/<id>/top")
 }
 }
+
+func TestContainerApiCommit(t *testing.T) {
+	out, _, _ := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "touch /test")
+	id := strings.TrimSpace(out)
+
+	name := "testcommit"
+	_, b, err := sockRequest("POST", "/commit?repo="+name+"&testtag=tag&container="+id, nil)
+	if err != nil && !strings.Contains(err.Error(), "200 OK: 201") {
+		t.Fatal(err)
+	}
+
+	type resp struct {
+		Id string
+	}
+	var img resp
+	if err := json.Unmarshal(b, &img); err != nil {
+		t.Fatal(err)
+	}
+	defer deleteImages(img.Id)
+
+	out, err = inspectField(img.Id, "Config.Cmd")
+	if out != "[/bin/sh -c touch /test]" {
+		t.Fatalf("got wrong Cmd from commit: %q", out)
+	}
+	// sanity check, make sure the image is what we think it is
+	dockerCmd(t, "run", img.Id, "ls", "/test")
+
+	logDone("containers REST API - POST /commit")
+}

+ 0 - 39
integration/api_test.go

@@ -17,50 +17,11 @@ import (
 	"github.com/docker/docker/api"
 	"github.com/docker/docker/api"
 	"github.com/docker/docker/api/server"
 	"github.com/docker/docker/api/server"
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types"
-	"github.com/docker/docker/builder"
 	"github.com/docker/docker/engine"
 	"github.com/docker/docker/engine"
 	"github.com/docker/docker/runconfig"
 	"github.com/docker/docker/runconfig"
 	"github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
 	"github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
 )
 )
 
 
-func TestPostCommit(t *testing.T) {
-	eng := NewTestEngine(t)
-	b := &builder.BuilderJob{Engine: eng}
-	b.Install()
-	defer mkDaemonFromEngine(eng, t).Nuke()
-
-	// Create a container and remove a file
-	containerID := createTestContainer(eng,
-		&runconfig.Config{
-			Image: unitTestImageID,
-			Cmd:   runconfig.NewCommand("touch", "/test"),
-		},
-		t,
-	)
-
-	containerRun(eng, containerID, t)
-
-	req, err := http.NewRequest("POST", "/commit?repo=testrepo&testtag=tag&container="+containerID, bytes.NewReader([]byte{}))
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	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 env engine.Env
-	if err := env.Decode(r.Body); err != nil {
-		t.Fatal(err)
-	}
-	if err := eng.Job("image_inspect", env.Get("Id")).Run(); err != nil {
-		t.Fatalf("The image has not been committed")
-	}
-}
-
 func TestPostContainersCreate(t *testing.T) {
 func TestPostContainersCreate(t *testing.T) {
 	eng := NewTestEngine(t)
 	eng := NewTestEngine(t)
 	defer mkDaemonFromEngine(eng, t).Nuke()
 	defer mkDaemonFromEngine(eng, t).Nuke()