Checkers on integration-cli/docker_cli_commit_test

Applying #16756 to integration-cli/docker_cli_commit_test.go

Signed-off-by: Aditi Rajagopal <arajagopal@us.ibm.com>
This commit is contained in:
Aditi Rajagopal 2015-10-16 16:48:51 -05:00
parent 1795eb9545
commit 483abbb313
1 changed files with 23 additions and 49 deletions

View File

@ -3,6 +3,7 @@ package main
import ( import (
"strings" "strings"
"github.com/docker/docker/pkg/integration/checker"
"github.com/go-check/check" "github.com/go-check/check"
) )
@ -49,10 +50,9 @@ func (s *DockerSuite) TestCommitPausedContainer(c *check.C) {
out, _ = dockerCmd(c, "commit", cleanedContainerID) out, _ = dockerCmd(c, "commit", cleanedContainerID)
out, err := inspectField(cleanedContainerID, "State.Paused") out, err := inspectField(cleanedContainerID, "State.Paused")
c.Assert(err, check.IsNil) c.Assert(err, checker.IsNil, check.Commentf("%s", out))
if !strings.Contains(out, "true") { // commit should not unpause a paused container
c.Fatalf("commit should not unpause a paused container") c.Assert(out, checker.Contains, "true")
}
} }
func (s *DockerSuite) TestCommitNewFile(c *check.C) { func (s *DockerSuite) TestCommitNewFile(c *check.C) {
@ -60,14 +60,11 @@ func (s *DockerSuite) TestCommitNewFile(c *check.C) {
dockerCmd(c, "run", "--name", "commiter", "busybox", "/bin/sh", "-c", "echo koye > /foo") dockerCmd(c, "run", "--name", "commiter", "busybox", "/bin/sh", "-c", "echo koye > /foo")
imageID, _ := dockerCmd(c, "commit", "commiter") imageID, _ := dockerCmd(c, "commit", "commiter")
imageID = strings.Trim(imageID, "\r\n") imageID = strings.TrimSpace(imageID)
out, _ := dockerCmd(c, "run", imageID, "cat", "/foo") out, _ := dockerCmd(c, "run", imageID, "cat", "/foo")
actual := strings.TrimSpace(out)
if actual := strings.Trim(out, "\r\n"); actual != "koye" { c.Assert(actual, checker.Equals, "koye")
c.Fatalf("expected output koye received %q", actual)
}
} }
func (s *DockerSuite) TestCommitHardlink(c *check.C) { func (s *DockerSuite) TestCommitHardlink(c *check.C) {
@ -76,35 +73,18 @@ func (s *DockerSuite) TestCommitHardlink(c *check.C) {
chunks := strings.Split(strings.TrimSpace(firstOutput), " ") chunks := strings.Split(strings.TrimSpace(firstOutput), " ")
inode := chunks[0] inode := chunks[0]
found := false chunks = strings.SplitAfterN(strings.TrimSpace(firstOutput), " ", 2)
for _, chunk := range chunks[1:] { c.Assert(chunks[1], checker.Contains, chunks[0], check.Commentf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:]))
if chunk == inode {
found = true
break
}
}
if !found {
c.Fatalf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:])
}
imageID, _ := dockerCmd(c, "commit", "hardlinks", "hardlinks") imageID, _ := dockerCmd(c, "commit", "hardlinks", "hardlinks")
imageID = strings.Trim(imageID, "\r\n") imageID = strings.TrimSpace(imageID)
secondOutput, _ := dockerCmd(c, "run", "-t", "hardlinks", "ls", "-di", "file1", "file2") secondOutput, _ := dockerCmd(c, "run", "-t", "hardlinks", "ls", "-di", "file1", "file2")
chunks = strings.Split(strings.TrimSpace(secondOutput), " ") chunks = strings.Split(strings.TrimSpace(secondOutput), " ")
inode = chunks[0] inode = chunks[0]
found = false chunks = strings.SplitAfterN(strings.TrimSpace(secondOutput), " ", 2)
for _, chunk := range chunks[1:] { c.Assert(chunks[1], checker.Contains, chunks[0], check.Commentf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:]))
if chunk == inode {
found = true
break
}
}
if !found {
c.Fatalf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:])
}
} }
func (s *DockerSuite) TestCommitTTY(c *check.C) { func (s *DockerSuite) TestCommitTTY(c *check.C) {
@ -112,10 +92,9 @@ func (s *DockerSuite) TestCommitTTY(c *check.C) {
dockerCmd(c, "run", "-t", "--name", "tty", "busybox", "/bin/ls") dockerCmd(c, "run", "-t", "--name", "tty", "busybox", "/bin/ls")
imageID, _ := dockerCmd(c, "commit", "tty", "ttytest") imageID, _ := dockerCmd(c, "commit", "tty", "ttytest")
imageID = strings.Trim(imageID, "\r\n") imageID = strings.TrimSpace(imageID)
dockerCmd(c, "run", "ttytest", "/bin/ls") dockerCmd(c, "run", "ttytest", "/bin/ls")
} }
func (s *DockerSuite) TestCommitWithHostBindMount(c *check.C) { func (s *DockerSuite) TestCommitWithHostBindMount(c *check.C) {
@ -123,10 +102,9 @@ func (s *DockerSuite) TestCommitWithHostBindMount(c *check.C) {
dockerCmd(c, "run", "--name", "bind-commit", "-v", "/dev/null:/winning", "busybox", "true") dockerCmd(c, "run", "--name", "bind-commit", "-v", "/dev/null:/winning", "busybox", "true")
imageID, _ := dockerCmd(c, "commit", "bind-commit", "bindtest") imageID, _ := dockerCmd(c, "commit", "bind-commit", "bindtest")
imageID = strings.Trim(imageID, "\r\n") imageID = strings.TrimSpace(imageID)
dockerCmd(c, "run", "bindtest", "true") dockerCmd(c, "run", "bindtest", "true")
} }
func (s *DockerSuite) TestCommitChange(c *check.C) { func (s *DockerSuite) TestCommitChange(c *check.C) {
@ -146,7 +124,7 @@ func (s *DockerSuite) TestCommitChange(c *check.C) {
"--change", "VOLUME /var/lib/docker", "--change", "VOLUME /var/lib/docker",
"--change", "ONBUILD /usr/local/bin/python-build --dir /app/src", "--change", "ONBUILD /usr/local/bin/python-build --dir /app/src",
"test", "test-commit") "test", "test-commit")
imageID = strings.Trim(imageID, "\r\n") imageID = strings.TrimSpace(imageID)
expected := map[string]string{ expected := map[string]string{
"Config.ExposedPorts": "map[8080/tcp:{}]", "Config.ExposedPorts": "map[8080/tcp:{}]",
@ -162,12 +140,11 @@ func (s *DockerSuite) TestCommitChange(c *check.C) {
for conf, value := range expected { for conf, value := range expected {
res, err := inspectField(imageID, conf) res, err := inspectField(imageID, conf)
c.Assert(err, check.IsNil) c.Assert(err, checker.IsNil, check.Commentf("%s('%s')", conf, res))
if res != value { if res != value {
c.Errorf("%s('%s'), expected %s", conf, res, value) c.Errorf("%s('%s'), expected %s", conf, res, value)
} }
} }
} }
// TODO: commit --run is deprecated, remove this once --run is removed // TODO: commit --run is deprecated, remove this once --run is removed
@ -180,22 +157,20 @@ func (s *DockerSuite) TestCommitMergeConfigRun(c *check.C) {
dockerCmd(c, "commit", `--run={"Cmd": ["cat", "/tmp/foo"]}`, id, "commit-test") dockerCmd(c, "commit", `--run={"Cmd": ["cat", "/tmp/foo"]}`, id, "commit-test")
out, _ = dockerCmd(c, "run", "--name", name, "commit-test") out, _ = dockerCmd(c, "run", "--name", name, "commit-test")
if strings.TrimSpace(out) != "testing" { //run config in committed container was not merged
c.Fatal("run config in committed container was not merged") c.Assert(strings.TrimSpace(out), checker.Equals, "testing")
}
type cfg struct { type cfg struct {
Env []string Env []string
Cmd []string Cmd []string
} }
config1 := cfg{} config1 := cfg{}
if err := inspectFieldAndMarshall(id, "Config", &config1); err != nil { err := inspectFieldAndMarshall(id, "Config", &config1)
c.Fatal(err) c.Assert(err, checker.IsNil)
}
config2 := cfg{} config2 := cfg{}
if err := inspectFieldAndMarshall(name, "Config", &config2); err != nil { err = inspectFieldAndMarshall(name, "Config", &config2)
c.Fatal(err) c.Assert(err, checker.IsNil)
}
// Env has at least PATH loaded as well here, so let's just grab the FOO one // Env has at least PATH loaded as well here, so let's just grab the FOO one
var env1, env2 string var env1, env2 string
@ -215,5 +190,4 @@ func (s *DockerSuite) TestCommitMergeConfigRun(c *check.C) {
if len(config1.Env) != len(config2.Env) || env1 != env2 && env2 != "" { if len(config1.Env) != len(config2.Env) || env1 != env2 && env2 != "" {
c.Fatalf("expected envs to match: %v - %v", config1.Env, config2.Env) c.Fatalf("expected envs to match: %v - %v", config1.Env, config2.Env)
} }
} }