Browse Source

Update commit test in cli
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)

Michael Crosby 11 years ago
parent
commit
6beb858fb0
2 changed files with 30 additions and 196 deletions
  1. 30 0
      integration-cli/docker_cli_commit_test.go
  2. 0 196
      integration/container_test.go

+ 30 - 0
integration-cli/docker_cli_commit_test.go

@@ -3,6 +3,7 @@ package main
 import (
 	"fmt"
 	"os/exec"
+	"strings"
 	"testing"
 )
 
@@ -32,3 +33,32 @@ func TestCommitAfterContainerIsDone(t *testing.T) {
 
 	logDone("commit - echo foo and commit the image")
 }
+
+func TestCommitNewFile(t *testing.T) {
+	cmd := exec.Command(dockerBinary, "run", "--name", "commiter", "busybox", "/bin/sh", "-c", "echo koye > /foo")
+	if _, err := runCommand(cmd); err != nil {
+		t.Fatal(err)
+	}
+
+	cmd = exec.Command(dockerBinary, "commit", "commiter")
+	imageId, _, err := runCommandWithOutput(cmd)
+	if err != nil {
+		t.Fatal(err)
+	}
+	imageId = strings.Trim(imageId, "\r\n")
+
+	cmd = exec.Command(dockerBinary, "run", imageId, "cat", "/foo")
+
+	out, _, err := runCommandWithOutput(cmd)
+	if err != nil {
+		t.Fatal(err, out)
+	}
+	if actual := strings.Trim(out, "\r\n"); actual != "koye" {
+		t.Fatalf("expected output koye received %s", actual)
+	}
+
+	deleteAllContainers()
+	deleteImages(imageId)
+
+	logDone("commit - commit file and read")
+}

+ 0 - 196
integration/container_test.go

@@ -16,202 +16,6 @@ import (
 	"time"
 )
 
-func TestDiff(t *testing.T) {
-	eng := NewTestEngine(t)
-	daemon := mkDaemonFromEngine(eng, t)
-	defer nuke(daemon)
-	// Create a container and remove a file
-	container1, _, _ := mkContainer(daemon, []string{"_", "/bin/rm", "/etc/passwd"}, t)
-	defer daemon.Destroy(container1)
-
-	// The changelog should be empty and not fail before run. See #1705
-	c, err := container1.Changes()
-	if err != nil {
-		t.Fatal(err)
-	}
-	if len(c) != 0 {
-		t.Fatalf("Changelog should be empty before run")
-	}
-
-	if err := container1.Run(); err != nil {
-		t.Fatal(err)
-	}
-
-	// Check the changelog
-	c, err = container1.Changes()
-	if err != nil {
-		t.Fatal(err)
-	}
-	success := false
-	for _, elem := range c {
-		if elem.Path == "/etc/passwd" && elem.Kind == 2 {
-			success = true
-		}
-	}
-	if !success {
-		t.Fatalf("/etc/passwd as been removed but is not present in the diff")
-	}
-
-	// Commit the container
-	img, err := daemon.Commit(container1, "", "", "unit test commited image - diff", "", nil)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	// Create a new container from the commited image
-	container2, _, _ := mkContainer(daemon, []string{img.ID, "cat", "/etc/passwd"}, t)
-	defer daemon.Destroy(container2)
-
-	if err := container2.Run(); err != nil {
-		t.Fatal(err)
-	}
-
-	// Check the changelog
-	c, err = container2.Changes()
-	if err != nil {
-		t.Fatal(err)
-	}
-	for _, elem := range c {
-		if elem.Path == "/etc/passwd" {
-			t.Fatalf("/etc/passwd should not be present in the diff after commit.")
-		}
-	}
-
-	// Create a new container
-	container3, _, _ := mkContainer(daemon, []string{"_", "rm", "/bin/httpd"}, t)
-	defer daemon.Destroy(container3)
-
-	if err := container3.Run(); err != nil {
-		t.Fatal(err)
-	}
-
-	// Check the changelog
-	c, err = container3.Changes()
-	if err != nil {
-		t.Fatal(err)
-	}
-	success = false
-	for _, elem := range c {
-		if elem.Path == "/bin/httpd" && elem.Kind == 2 {
-			success = true
-		}
-	}
-	if !success {
-		t.Fatalf("/bin/httpd should be present in the diff after commit.")
-	}
-}
-
-func TestCommitAutoRun(t *testing.T) {
-	daemon := mkDaemon(t)
-	defer nuke(daemon)
-	container1, _, _ := mkContainer(daemon, []string{"_", "/bin/sh", "-c", "echo hello > /world"}, t)
-	defer daemon.Destroy(container1)
-
-	if container1.State.IsRunning() {
-		t.Errorf("Container shouldn't be running")
-	}
-	if err := container1.Run(); err != nil {
-		t.Fatal(err)
-	}
-	if container1.State.IsRunning() {
-		t.Errorf("Container shouldn't be running")
-	}
-
-	img, err := daemon.Commit(container1, "", "", "unit test commited image", "", &runconfig.Config{Cmd: []string{"cat", "/world"}})
-	if err != nil {
-		t.Error(err)
-	}
-
-	// FIXME: Make a TestCommit that stops here and check docker.root/layers/img.id/world
-	container2, _, _ := mkContainer(daemon, []string{img.ID}, t)
-	defer daemon.Destroy(container2)
-	stdout, err := container2.StdoutPipe()
-	if err != nil {
-		t.Fatal(err)
-	}
-	stderr, err := container2.StderrPipe()
-	if err != nil {
-		t.Fatal(err)
-	}
-	if err := container2.Start(); err != nil {
-		t.Fatal(err)
-	}
-	container2.Wait()
-	output, err := ioutil.ReadAll(stdout)
-	if err != nil {
-		t.Fatal(err)
-	}
-	output2, err := ioutil.ReadAll(stderr)
-	if err != nil {
-		t.Fatal(err)
-	}
-	if err := stdout.Close(); err != nil {
-		t.Fatal(err)
-	}
-	if err := stderr.Close(); err != nil {
-		t.Fatal(err)
-	}
-	if string(output) != "hello\n" {
-		t.Fatalf("Unexpected output. Expected %s, received: %s (err: %s)", "hello\n", output, output2)
-	}
-}
-
-func TestCommitRun(t *testing.T) {
-	daemon := mkDaemon(t)
-	defer nuke(daemon)
-
-	container1, _, _ := mkContainer(daemon, []string{"_", "/bin/sh", "-c", "echo hello > /world"}, t)
-	defer daemon.Destroy(container1)
-
-	if container1.State.IsRunning() {
-		t.Errorf("Container shouldn't be running")
-	}
-	if err := container1.Run(); err != nil {
-		t.Fatal(err)
-	}
-	if container1.State.IsRunning() {
-		t.Errorf("Container shouldn't be running")
-	}
-
-	img, err := daemon.Commit(container1, "", "", "unit test commited image", "", nil)
-	if err != nil {
-		t.Error(err)
-	}
-
-	// FIXME: Make a TestCommit that stops here and check docker.root/layers/img.id/world
-	container2, _, _ := mkContainer(daemon, []string{img.ID, "cat", "/world"}, t)
-	defer daemon.Destroy(container2)
-	stdout, err := container2.StdoutPipe()
-	if err != nil {
-		t.Fatal(err)
-	}
-	stderr, err := container2.StderrPipe()
-	if err != nil {
-		t.Fatal(err)
-	}
-	if err := container2.Start(); err != nil {
-		t.Fatal(err)
-	}
-	container2.Wait()
-	output, err := ioutil.ReadAll(stdout)
-	if err != nil {
-		t.Fatal(err)
-	}
-	output2, err := ioutil.ReadAll(stderr)
-	if err != nil {
-		t.Fatal(err)
-	}
-	if err := stdout.Close(); err != nil {
-		t.Fatal(err)
-	}
-	if err := stderr.Close(); err != nil {
-		t.Fatal(err)
-	}
-	if string(output) != "hello\n" {
-		t.Fatalf("Unexpected output. Expected %s, received: %s (err: %s)", "hello\n", output, output2)
-	}
-}
-
 func TestStart(t *testing.T) {
 	daemon := mkDaemon(t)
 	defer nuke(daemon)