зеркало из https://github.com/microsoft/docker.git
Clean integration-cli/utils.go from most of its content
Most of the code is now on pkg/integration. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Родитель
1dece339c3
Коммит
def13fa23c
|
@ -19,6 +19,7 @@ import (
|
|||
|
||||
"github.com/docker/docker/builder/dockerfile/command"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/docker/docker/pkg/integration"
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
icmd "github.com/docker/docker/pkg/integration/cmd"
|
||||
"github.com/docker/docker/pkg/stringutils"
|
||||
|
@ -2085,7 +2086,7 @@ func (s *DockerSuite) TestBuildContextCleanup(c *check.C) {
|
|||
if err != nil {
|
||||
c.Fatalf("failed to list contents of tmp dir: %s", err)
|
||||
}
|
||||
if err = compareDirectoryEntries(entries, entriesFinal); err != nil {
|
||||
if err = integration.CompareDirectoryEntries(entries, entriesFinal); err != nil {
|
||||
c.Fatalf("context should have been deleted, but wasn't")
|
||||
}
|
||||
|
||||
|
@ -2110,7 +2111,7 @@ func (s *DockerSuite) TestBuildContextCleanupFailedBuild(c *check.C) {
|
|||
if err != nil {
|
||||
c.Fatalf("failed to list contents of tmp dir: %s", err)
|
||||
}
|
||||
if err = compareDirectoryEntries(entries, entriesFinal); err != nil {
|
||||
if err = integration.CompareDirectoryEntries(entries, entriesFinal); err != nil {
|
||||
c.Fatalf("context should have been deleted, but wasn't")
|
||||
}
|
||||
|
||||
|
@ -5341,7 +5342,7 @@ func (s *DockerSuite) TestBuildContainerWithCgroupParent(c *check.C) {
|
|||
if err != nil {
|
||||
c.Fatalf("failed to read '/proc/self/cgroup - %v", err)
|
||||
}
|
||||
selfCgroupPaths := parseCgroupPaths(string(data))
|
||||
selfCgroupPaths := integration.ParseCgroupPaths(string(data))
|
||||
_, found := selfCgroupPaths["memory"]
|
||||
if !found {
|
||||
c.Fatalf("unable to find self memory cgroup path. CgroupsPath: %v", selfCgroupPaths)
|
||||
|
@ -6242,11 +6243,10 @@ func (s *DockerSuite) TestBuildMultipleTags(c *check.C) {
|
|||
FROM busybox
|
||||
MAINTAINER test-15780
|
||||
`
|
||||
cmd := exec.Command(dockerBinary, "build", "-t", "tag1", "-t", "tag2:v2",
|
||||
"-t", "tag1:latest", "-t", "tag1", "--no-cache", "-")
|
||||
cmd.Stdin = strings.NewReader(dockerfile)
|
||||
_, err := runCommand(cmd)
|
||||
c.Assert(err, check.IsNil)
|
||||
icmd.RunCmd(icmd.Cmd{
|
||||
Command: []string{dockerBinary, "build", "-t", "tag1", "-t", "tag2:v2", "-t", "tag1:latest", "-t", "tag1", "--no-cache", "-"},
|
||||
Stdin: strings.NewReader(dockerfile),
|
||||
}).Assert(c, icmd.Success)
|
||||
|
||||
id1, err := getIDByName("tag1")
|
||||
c.Assert(err, check.IsNil)
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/pkg/integration"
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
icmd "github.com/docker/docker/pkg/integration/cmd"
|
||||
"github.com/go-check/check"
|
||||
|
@ -545,7 +546,7 @@ func (s *DockerSuite) TestCpToStdout(c *check.C) {
|
|||
// failed to set up container
|
||||
c.Assert(strings.TrimSpace(out), checker.Equals, "0")
|
||||
|
||||
out, _, err := runCommandPipelineWithOutput(
|
||||
out, _, err := integration.RunCommandPipelineWithOutput(
|
||||
exec.Command(dockerBinary, "cp", containerID+":/test", "-"),
|
||||
exec.Command("tar", "-vtf", "-"))
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/docker/docker/pkg/integration"
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/docker/go-connections/nat"
|
||||
|
@ -355,7 +356,7 @@ func (s *DockerTrustSuite) TestCreateWhenCertExpired(c *check.C) {
|
|||
// Certificates have 10 years of expiration
|
||||
elevenYearsFromNow := time.Now().Add(time.Hour * 24 * 365 * 11)
|
||||
|
||||
runAtDifferentDate(elevenYearsFromNow, func() {
|
||||
integration.RunAtDifferentDate(elevenYearsFromNow, func() {
|
||||
// Try create
|
||||
createCmd := exec.Command(dockerBinary, "create", repoName)
|
||||
s.trustedCmd(createCmd)
|
||||
|
@ -364,7 +365,7 @@ func (s *DockerTrustSuite) TestCreateWhenCertExpired(c *check.C) {
|
|||
c.Assert(string(out), checker.Contains, "could not validate the path to a trusted root", check.Commentf("Missing expected output on trusted create in the distant future:\n%s", out))
|
||||
})
|
||||
|
||||
runAtDifferentDate(elevenYearsFromNow, func() {
|
||||
integration.RunAtDifferentDate(elevenYearsFromNow, func() {
|
||||
// Try create
|
||||
createCmd := exec.Command(dockerBinary, "create", "--disable-content-trust", repoName)
|
||||
s.trustedCmd(createCmd)
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/docker/docker/integration-cli/daemon"
|
||||
"github.com/docker/docker/pkg/integration"
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
icmd "github.com/docker/docker/pkg/integration/cmd"
|
||||
"github.com/docker/docker/pkg/mount"
|
||||
|
@ -235,11 +236,7 @@ func (s *DockerDaemonSuite) TestDaemonStartBridgeWithoutIPAssociation(c *check.C
|
|||
s.d.Stop(c)
|
||||
|
||||
// now we will remove the ip from docker0 and then try starting the daemon
|
||||
ipCmd := exec.Command("ip", "addr", "flush", "dev", "docker0")
|
||||
stdout, stderr, _, err := runCommandWithStdoutStderr(ipCmd)
|
||||
if err != nil {
|
||||
c.Fatalf("failed to remove docker0 IP association: %v, stdout: %q, stderr: %q", err, stdout, stderr)
|
||||
}
|
||||
icmd.RunCommand("ip", "addr", "flush", "dev", "docker0").Assert(c, icmd.Success)
|
||||
|
||||
if err := s.d.StartWithError(); err != nil {
|
||||
warning := "**WARNING: Docker bridge network in bad state--delete docker0 bridge interface to fix"
|
||||
|
@ -668,24 +665,16 @@ func (s *DockerDaemonSuite) TestDaemonBridgeIP(c *check.C) {
|
|||
defer d.Restart(c)
|
||||
|
||||
ifconfigSearchString := ip.String()
|
||||
ifconfigCmd := exec.Command("ifconfig", defaultNetworkBridge)
|
||||
out, _, _, err := runCommandWithStdoutStderr(ifconfigCmd)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
c.Assert(strings.Contains(out, ifconfigSearchString), check.Equals, true,
|
||||
check.Commentf("ifconfig output should have contained %q, but was %q",
|
||||
ifconfigSearchString, out))
|
||||
icmd.RunCommand("ifconfig", defaultNetworkBridge).Assert(c, icmd.Expected{
|
||||
Out: ifconfigSearchString,
|
||||
})
|
||||
|
||||
ipTablesSearchString := bridgeIPNet.String()
|
||||
ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL")
|
||||
out, _, err = runCommandWithOutput(ipTablesCmd)
|
||||
c.Assert(err, check.IsNil)
|
||||
icmd.RunCommand("iptables", "-t", "nat", "-nvL").Assert(c, icmd.Expected{
|
||||
Out: ipTablesSearchString,
|
||||
})
|
||||
|
||||
c.Assert(strings.Contains(out, ipTablesSearchString), check.Equals, true,
|
||||
check.Commentf("iptables output should have contained %q, but was %q",
|
||||
ipTablesSearchString, out))
|
||||
|
||||
out, err = d.Cmd("run", "-d", "--name", "test", "busybox", "top")
|
||||
_, err := d.Cmd("run", "-d", "--name", "test", "busybox", "top")
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
containerIP, err := d.FindContainerIP("test")
|
||||
|
@ -706,24 +695,15 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithBridgeIPChange(c *check.C) {
|
|||
bridgeIP := "192.169.100.1/24"
|
||||
_, bridgeIPNet, _ := net.ParseCIDR(bridgeIP)
|
||||
|
||||
ipCmd := exec.Command("ifconfig", "docker0", bridgeIP)
|
||||
stdout, stderr, _, err := runCommandWithStdoutStderr(ipCmd)
|
||||
if err != nil {
|
||||
c.Fatalf("failed to change docker0's IP association: %v, stdout: %q, stderr: %q", err, stdout, stderr)
|
||||
}
|
||||
icmd.RunCommand("ifconfig", "docker0", bridgeIP).Assert(c, icmd.Success)
|
||||
|
||||
s.d.Start(c, "--bip", bridgeIP)
|
||||
|
||||
//check if the iptables contains new bridgeIP MASQUERADE rule
|
||||
ipTablesSearchString := bridgeIPNet.String()
|
||||
ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL")
|
||||
out, _, err := runCommandWithOutput(ipTablesCmd)
|
||||
if err != nil {
|
||||
c.Fatalf("Could not run iptables -nvL: %s, %v", out, err)
|
||||
}
|
||||
if !strings.Contains(out, ipTablesSearchString) {
|
||||
c.Fatalf("iptables output should have contained new MASQUERADE rule with IP %q, but was %q", ipTablesSearchString, out)
|
||||
}
|
||||
icmd.RunCommand("iptables", "-t", "nat", "-nvL").Assert(c, icmd.Expected{
|
||||
Out: ipTablesSearchString,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *DockerDaemonSuite) TestDaemonBridgeFixedCidr(c *check.C) {
|
||||
|
@ -1908,7 +1888,7 @@ func (s *DockerDaemonSuite) TestDaemonCgroupParent(c *check.C) {
|
|||
|
||||
out, err := s.d.Cmd("run", "--name", name, "busybox", "cat", "/proc/self/cgroup")
|
||||
c.Assert(err, checker.IsNil)
|
||||
cgroupPaths := parseCgroupPaths(string(out))
|
||||
cgroupPaths := integration.ParseCgroupPaths(string(out))
|
||||
c.Assert(len(cgroupPaths), checker.Not(checker.Equals), 0, check.Commentf("unexpected output - %q", string(out)))
|
||||
out, err = s.d.Cmd("inspect", "-f", "{{.Id}}", name)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
|
||||
eventtypes "github.com/docker/docker/api/types/events"
|
||||
eventstestutils "github.com/docker/docker/daemon/events/testutils"
|
||||
"github.com/docker/docker/pkg/integration"
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
icmd "github.com/docker/docker/pkg/integration/cmd"
|
||||
"github.com/go-check/check"
|
||||
|
@ -221,7 +222,7 @@ func (s *DockerSuite) TestEventsImageImport(c *check.C) {
|
|||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
||||
since := daemonUnixTime(c)
|
||||
out, _, err := runCommandPipelineWithOutput(
|
||||
out, _, err := integration.RunCommandPipelineWithOutput(
|
||||
exec.Command(dockerBinary, "export", cleanedContainerID),
|
||||
exec.Command(dockerBinary, "import", "-"),
|
||||
)
|
||||
|
|
|
@ -206,6 +206,7 @@ func (s *DockerSuite) TestExecTTYWithoutStdin(c *check.C) {
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME(vdemeester) this should be a unit tests on cli/command/container package
|
||||
func (s *DockerSuite) TestExecParseError(c *check.C) {
|
||||
// TODO Windows CI: Requires some extra work. Consider copying the
|
||||
// runSleepingContainer helper to have an exec version.
|
||||
|
@ -213,10 +214,11 @@ func (s *DockerSuite) TestExecParseError(c *check.C) {
|
|||
dockerCmd(c, "run", "-d", "--name", "top", "busybox", "top")
|
||||
|
||||
// Test normal (non-detached) case first
|
||||
cmd := exec.Command(dockerBinary, "exec", "top")
|
||||
_, stderr, _, err := runCommandWithStdoutStderr(cmd)
|
||||
c.Assert(err, checker.NotNil)
|
||||
c.Assert(stderr, checker.Contains, "See 'docker exec --help'")
|
||||
icmd.RunCommand(dockerBinary, "exec", "top").Assert(c, icmd.Expected{
|
||||
ExitCode: 1,
|
||||
Error: "exit status 1",
|
||||
Err: "See 'docker exec --help'",
|
||||
})
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestExecStopNotHanging(c *check.C) {
|
||||
|
|
|
@ -147,56 +147,56 @@ func (s *DockerSuite) TestHelpExitCodesHelpOutput(c *check.C) {
|
|||
// various good and bad cases are what we expect
|
||||
|
||||
// docker : stdout=all, stderr=empty, rc=0
|
||||
out, _, err := dockerCmdWithError()
|
||||
c.Assert(err, checker.IsNil, check.Commentf(out))
|
||||
out, _ := dockerCmd(c)
|
||||
// Be really pick
|
||||
c.Assert(out, checker.Not(checker.HasSuffix), "\n\n", check.Commentf("Should not have a blank line at the end of 'docker'\n"))
|
||||
|
||||
// docker help: stdout=all, stderr=empty, rc=0
|
||||
out, _, err = dockerCmdWithError("help")
|
||||
c.Assert(err, checker.IsNil, check.Commentf(out))
|
||||
out, _ = dockerCmd(c, "help")
|
||||
// Be really pick
|
||||
c.Assert(out, checker.Not(checker.HasSuffix), "\n\n", check.Commentf("Should not have a blank line at the end of 'docker help'\n"))
|
||||
|
||||
// docker --help: stdout=all, stderr=empty, rc=0
|
||||
out, _, err = dockerCmdWithError("--help")
|
||||
c.Assert(err, checker.IsNil, check.Commentf(out))
|
||||
out, _ = dockerCmd(c, "--help")
|
||||
// Be really pick
|
||||
c.Assert(out, checker.Not(checker.HasSuffix), "\n\n", check.Commentf("Should not have a blank line at the end of 'docker --help'\n"))
|
||||
|
||||
// docker inspect busybox: stdout=all, stderr=empty, rc=0
|
||||
// Just making sure stderr is empty on valid cmd
|
||||
out, _, err = dockerCmdWithError("inspect", "busybox")
|
||||
c.Assert(err, checker.IsNil, check.Commentf(out))
|
||||
out, _ = dockerCmd(c, "inspect", "busybox")
|
||||
// Be really pick
|
||||
c.Assert(out, checker.Not(checker.HasSuffix), "\n\n", check.Commentf("Should not have a blank line at the end of 'docker inspect busyBox'\n"))
|
||||
|
||||
// docker rm: stdout=empty, stderr=all, rc!=0
|
||||
// testing the min arg error msg
|
||||
cmd := exec.Command(dockerBinary, "rm")
|
||||
stdout, stderr, _, err := runCommandWithStdoutStderr(cmd)
|
||||
c.Assert(err, checker.NotNil)
|
||||
c.Assert(stdout, checker.Equals, "")
|
||||
// Should not contain full help text but should contain info about
|
||||
// # of args and Usage line
|
||||
c.Assert(stderr, checker.Contains, "requires at least 1 argument", check.Commentf("Missing # of args text from 'docker rm'\n"))
|
||||
icmd.RunCommand(dockerBinary, "rm").Assert(c, icmd.Expected{
|
||||
ExitCode: 1,
|
||||
Error: "exit status 1",
|
||||
Out: "",
|
||||
// Should not contain full help text but should contain info about
|
||||
// # of args and Usage line
|
||||
Err: "requires at least 1 argument",
|
||||
})
|
||||
|
||||
// docker rm NoSuchContainer: stdout=empty, stderr=all, rc=0
|
||||
// testing to make sure no blank line on error
|
||||
cmd = exec.Command(dockerBinary, "rm", "NoSuchContainer")
|
||||
stdout, stderr, _, err = runCommandWithStdoutStderr(cmd)
|
||||
c.Assert(err, checker.NotNil)
|
||||
c.Assert(len(stderr), checker.Not(checker.Equals), 0)
|
||||
c.Assert(stdout, checker.Equals, "")
|
||||
result := icmd.RunCommand(dockerBinary, "rm", "NoSuchContainer")
|
||||
result.Assert(c, icmd.Expected{
|
||||
ExitCode: 1,
|
||||
Error: "exit status 1",
|
||||
Out: "",
|
||||
})
|
||||
// Be really picky
|
||||
c.Assert(stderr, checker.Not(checker.HasSuffix), "\n\n", check.Commentf("Should not have a blank line at the end of 'docker rm'\n"))
|
||||
c.Assert(len(result.Stderr()), checker.Not(checker.Equals), 0)
|
||||
c.Assert(result.Stderr(), checker.Not(checker.HasSuffix), "\n\n", check.Commentf("Should not have a blank line at the end of 'docker rm'\n"))
|
||||
|
||||
// docker BadCmd: stdout=empty, stderr=all, rc=0
|
||||
cmd = exec.Command(dockerBinary, "BadCmd")
|
||||
stdout, stderr, _, err = runCommandWithStdoutStderr(cmd)
|
||||
c.Assert(err, checker.NotNil)
|
||||
c.Assert(stdout, checker.Equals, "")
|
||||
c.Assert(stderr, checker.Equals, "docker: 'BadCmd' is not a docker command.\nSee 'docker --help'\n", check.Commentf("Unexcepted output for 'docker badCmd'\n"))
|
||||
icmd.RunCommand(dockerBinary, "BadCmd").Assert(c, icmd.Expected{
|
||||
ExitCode: 1,
|
||||
Error: "exit status 1",
|
||||
Out: "",
|
||||
Err: "docker: 'BadCmd' is not a docker command.\nSee 'docker --help'\n",
|
||||
})
|
||||
}
|
||||
|
||||
func testCommand(cmd string, newEnvs []string, scanForHome bool, home string) error {
|
||||
|
@ -204,9 +204,13 @@ func testCommand(cmd string, newEnvs []string, scanForHome bool, home string) er
|
|||
args := strings.Split(cmd+" --help", " ")
|
||||
|
||||
// Check the full usage text
|
||||
helpCmd := exec.Command(dockerBinary, args...)
|
||||
helpCmd.Env = newEnvs
|
||||
out, stderr, _, err := runCommandWithStdoutStderr(helpCmd)
|
||||
result := icmd.RunCmd(icmd.Cmd{
|
||||
Command: append([]string{dockerBinary}, args...),
|
||||
Env: newEnvs,
|
||||
})
|
||||
err := result.Error
|
||||
out := result.Stdout()
|
||||
stderr := result.Stderr()
|
||||
if len(stderr) != 0 {
|
||||
return fmt.Errorf("Error on %q help. non-empty stderr:%q\n", cmd, stderr)
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/pkg/integration"
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
icmd "github.com/docker/docker/pkg/integration/cmd"
|
||||
"github.com/go-check/check"
|
||||
|
@ -19,7 +20,7 @@ func (s *DockerSuite) TestImportDisplay(c *check.C) {
|
|||
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
||||
out, _, err := runCommandPipelineWithOutput(
|
||||
out, _, err := integration.RunCommandPipelineWithOutput(
|
||||
exec.Command(dockerBinary, "export", cleanedContainerID),
|
||||
exec.Command(dockerBinary, "import", "-"),
|
||||
)
|
||||
|
@ -51,11 +52,10 @@ func (s *DockerSuite) TestImportFile(c *check.C) {
|
|||
c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file"))
|
||||
defer os.Remove(temporaryFile.Name())
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "export", "test-import")
|
||||
runCmd.Stdout = bufio.NewWriter(temporaryFile)
|
||||
|
||||
_, err = runCommand(runCmd)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to export a container"))
|
||||
icmd.RunCmd(icmd.Cmd{
|
||||
Command: []string{dockerBinary, "export", "test-import"},
|
||||
Stdout: bufio.NewWriter(temporaryFile),
|
||||
}).Assert(c, icmd.Success)
|
||||
|
||||
out, _ := dockerCmd(c, "import", temporaryFile.Name())
|
||||
c.Assert(out, checker.Count, "\n", 1, check.Commentf("display is expected 1 '\\n' but didn't"))
|
||||
|
@ -73,14 +73,12 @@ func (s *DockerSuite) TestImportGzipped(c *check.C) {
|
|||
c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file"))
|
||||
defer os.Remove(temporaryFile.Name())
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "export", "test-import")
|
||||
w := gzip.NewWriter(temporaryFile)
|
||||
runCmd.Stdout = w
|
||||
|
||||
_, err = runCommand(runCmd)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to export a container"))
|
||||
err = w.Close()
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to close gzip writer"))
|
||||
icmd.RunCmd(icmd.Cmd{
|
||||
Command: []string{dockerBinary, "export", "test-import"},
|
||||
Stdout: w,
|
||||
}).Assert(c, icmd.Success)
|
||||
c.Assert(w.Close(), checker.IsNil, check.Commentf("failed to close gzip writer"))
|
||||
temporaryFile.Close()
|
||||
out, _ := dockerCmd(c, "import", temporaryFile.Name())
|
||||
c.Assert(out, checker.Count, "\n", 1, check.Commentf("display is expected 1 '\\n' but didn't"))
|
||||
|
@ -98,11 +96,10 @@ func (s *DockerSuite) TestImportFileWithMessage(c *check.C) {
|
|||
c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file"))
|
||||
defer os.Remove(temporaryFile.Name())
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "export", "test-import")
|
||||
runCmd.Stdout = bufio.NewWriter(temporaryFile)
|
||||
|
||||
_, err = runCommand(runCmd)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to export a container"))
|
||||
icmd.RunCmd(icmd.Cmd{
|
||||
Command: []string{dockerBinary, "export", "test-import"},
|
||||
Stdout: bufio.NewWriter(temporaryFile),
|
||||
}).Assert(c, icmd.Success)
|
||||
|
||||
message := "Testing commit message"
|
||||
out, _ := dockerCmd(c, "import", "-m", message, temporaryFile.Name())
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -12,6 +11,7 @@ import (
|
|||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
icmd "github.com/docker/docker/pkg/integration/cmd"
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
|
@ -142,11 +142,12 @@ func (s *DockerSuite) TestInspectImageFilterInt(c *check.C) {
|
|||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectContainerFilterInt(c *check.C) {
|
||||
runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "cat")
|
||||
runCmd.Stdin = strings.NewReader("blahblah")
|
||||
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to run container: %v, output: %q", err, out))
|
||||
|
||||
result := icmd.RunCmd(icmd.Cmd{
|
||||
Command: []string{dockerBinary, "run", "-i", "-a", "stdin", "busybox", "cat"},
|
||||
Stdin: strings.NewReader("blahblah"),
|
||||
})
|
||||
result.Assert(c, icmd.Success)
|
||||
out := result.Stdout()
|
||||
id := strings.TrimSpace(out)
|
||||
|
||||
out = inspectField(c, id, "State.ExitCode")
|
||||
|
@ -157,9 +158,9 @@ func (s *DockerSuite) TestInspectContainerFilterInt(c *check.C) {
|
|||
//now get the exit code to verify
|
||||
formatStr := fmt.Sprintf("--format={{eq .State.ExitCode %d}}", exitCode)
|
||||
out, _ = dockerCmd(c, "inspect", formatStr, id)
|
||||
result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n"))
|
||||
inspectResult, err := strconv.ParseBool(strings.TrimSuffix(out, "\n"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(result, checker.Equals, true)
|
||||
c.Assert(inspectResult, checker.Equals, true)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectImageGraphDriver(c *check.C) {
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/pkg/integration"
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
"github.com/docker/docker/runconfig"
|
||||
"github.com/go-check/check"
|
||||
|
@ -101,7 +102,7 @@ func (s *DockerSuite) TestLinksInspectLinksStarted(c *check.C) {
|
|||
err := json.Unmarshal([]byte(links), &result)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
output := convertSliceOfStringsToMap(result)
|
||||
output := integration.ConvertSliceOfStringsToMap(result)
|
||||
|
||||
c.Assert(output, checker.DeepEquals, expected)
|
||||
}
|
||||
|
@ -120,7 +121,7 @@ func (s *DockerSuite) TestLinksInspectLinksStopped(c *check.C) {
|
|||
err := json.Unmarshal([]byte(links), &result)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
output := convertSliceOfStringsToMap(result)
|
||||
output := integration.ConvertSliceOfStringsToMap(result)
|
||||
|
||||
c.Assert(output, checker.DeepEquals, expected)
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/pkg/integration"
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
"github.com/docker/docker/pkg/jsonlog"
|
||||
"github.com/go-check/check"
|
||||
|
@ -253,11 +254,11 @@ func (s *DockerSuite) TestLogsFollowSlowStdoutConsumer(c *check.C) {
|
|||
c.Assert(logCmd.Start(), checker.IsNil)
|
||||
|
||||
// First read slowly
|
||||
bytes1, err := consumeWithSpeed(stdout, 10, 50*time.Millisecond, stopSlowRead)
|
||||
bytes1, err := integration.ConsumeWithSpeed(stdout, 10, 50*time.Millisecond, stopSlowRead)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
// After the container has finished we can continue reading fast
|
||||
bytes2, err := consumeWithSpeed(stdout, 32*1024, 0, nil)
|
||||
bytes2, err := integration.ConsumeWithSpeed(stdout, 32*1024, 0, nil)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
actual := bytes1 + bytes2
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/pkg/integration"
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
@ -69,7 +70,7 @@ func (s *DockerTrustSuite) TestPullWhenCertExpired(c *check.C) {
|
|||
// Certificates have 10 years of expiration
|
||||
elevenYearsFromNow := time.Now().Add(time.Hour * 24 * 365 * 11)
|
||||
|
||||
runAtDifferentDate(elevenYearsFromNow, func() {
|
||||
integration.RunAtDifferentDate(elevenYearsFromNow, func() {
|
||||
// Try pull
|
||||
pullCmd := exec.Command(dockerBinary, "pull", repoName)
|
||||
s.trustedCmd(pullCmd)
|
||||
|
@ -79,7 +80,7 @@ func (s *DockerTrustSuite) TestPullWhenCertExpired(c *check.C) {
|
|||
c.Assert(string(out), checker.Contains, "could not validate the path to a trusted root", check.Commentf(out))
|
||||
})
|
||||
|
||||
runAtDifferentDate(elevenYearsFromNow, func() {
|
||||
integration.RunAtDifferentDate(elevenYearsFromNow, func() {
|
||||
// Try pull
|
||||
pullCmd := exec.Command(dockerBinary, "pull", "--disable-content-trust", repoName)
|
||||
s.trustedCmd(pullCmd)
|
||||
|
@ -166,7 +167,7 @@ func (s *DockerTrustSuite) TestTrustedPullWithExpiredSnapshot(c *check.C) {
|
|||
// Snapshots last for three years. This should be expired
|
||||
fourYearsLater := time.Now().Add(time.Hour * 24 * 365 * 4)
|
||||
|
||||
runAtDifferentDate(fourYearsLater, func() {
|
||||
integration.RunAtDifferentDate(fourYearsLater, func() {
|
||||
// Try pull
|
||||
pullCmd := exec.Command(dockerBinary, "pull", repoName)
|
||||
s.trustedCmd(pullCmd)
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
|
||||
"github.com/docker/distribution/reference"
|
||||
cliconfig "github.com/docker/docker/cli/config"
|
||||
"github.com/docker/docker/pkg/integration"
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
@ -437,7 +438,7 @@ func (s *DockerTrustSuite) TestTrustedPushWithExpiredSnapshot(c *check.C) {
|
|||
// Snapshots last for three years. This should be expired
|
||||
fourYearsLater := time.Now().Add(time.Hour * 24 * 365 * 4)
|
||||
|
||||
runAtDifferentDate(fourYearsLater, func() {
|
||||
integration.RunAtDifferentDate(fourYearsLater, func() {
|
||||
// Push with wrong passphrases
|
||||
pushCmd = exec.Command(dockerBinary, "push", repoName)
|
||||
s.trustedCmd(pushCmd)
|
||||
|
@ -464,7 +465,7 @@ func (s *DockerTrustSuite) TestTrustedPushWithExpiredTimestamp(c *check.C) {
|
|||
threeWeeksLater := time.Now().Add(time.Hour * 24 * 21)
|
||||
|
||||
// Should succeed because the server transparently re-signs one
|
||||
runAtDifferentDate(threeWeeksLater, func() {
|
||||
integration.RunAtDifferentDate(threeWeeksLater, func() {
|
||||
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
||||
s.trustedCmd(pushCmd)
|
||||
out, _, err := runCommandWithOutput(pushCmd)
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/pkg/integration"
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
icmd "github.com/docker/docker/pkg/integration/cmd"
|
||||
"github.com/docker/docker/pkg/mount"
|
||||
|
@ -92,12 +93,12 @@ func (s *DockerSuite) TestRunExitCodeOne(c *check.C) {
|
|||
func (s *DockerSuite) TestRunStdinPipe(c *check.C) {
|
||||
// TODO Windows: This needs some work to make compatible.
|
||||
testRequires(c, DaemonIsLinux)
|
||||
runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "cat")
|
||||
runCmd.Stdin = strings.NewReader("blahblah")
|
||||
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
||||
if err != nil {
|
||||
c.Fatalf("failed to run container: %v, output: %q", err, out)
|
||||
}
|
||||
result := icmd.RunCmd(icmd.Cmd{
|
||||
Command: []string{dockerBinary, "run", "-i", "-a", "stdin", "busybox", "cat"},
|
||||
Stdin: strings.NewReader("blahblah"),
|
||||
})
|
||||
result.Assert(c, icmd.Success)
|
||||
out := result.Stdout()
|
||||
|
||||
out = strings.TrimSpace(out)
|
||||
dockerCmd(c, "wait", out)
|
||||
|
@ -497,7 +498,7 @@ func (s *DockerSuite) TestRunVolumesFromInReadWriteMode(c *check.C) {
|
|||
func (s *DockerSuite) TestVolumesFromGetsProperMode(c *check.C) {
|
||||
testRequires(c, SameHostDaemon)
|
||||
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
||||
hostpath := randomTmpDirPath("test", daemonPlatform)
|
||||
hostpath := integration.RandomTmpDirPath("test", daemonPlatform)
|
||||
if err := os.MkdirAll(hostpath, 0755); err != nil {
|
||||
c.Fatalf("Failed to create %s: %q", hostpath, err)
|
||||
}
|
||||
|
@ -520,8 +521,8 @@ func (s *DockerSuite) TestVolumesFromGetsProperMode(c *check.C) {
|
|||
|
||||
// Test for GH#10618
|
||||
func (s *DockerSuite) TestRunNoDupVolumes(c *check.C) {
|
||||
path1 := randomTmpDirPath("test1", daemonPlatform)
|
||||
path2 := randomTmpDirPath("test2", daemonPlatform)
|
||||
path1 := integration.RandomTmpDirPath("test1", daemonPlatform)
|
||||
path2 := integration.RandomTmpDirPath("test2", daemonPlatform)
|
||||
|
||||
someplace := ":/someplace"
|
||||
if daemonPlatform == "windows" {
|
||||
|
@ -1453,10 +1454,7 @@ func (s *DockerSuite) TestRunResolvconfUpdate(c *check.C) {
|
|||
c.Fatal(err)
|
||||
}
|
||||
if mounted {
|
||||
cmd := exec.Command("umount", "/etc/resolv.conf")
|
||||
if _, err = runCommand(cmd); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
icmd.RunCommand("umount", "/etc/resolv.conf").Assert(c, icmd.Success)
|
||||
}
|
||||
|
||||
//cleanup
|
||||
|
@ -1656,13 +1654,11 @@ func (s *DockerSuite) TestRunAttachStdOutAndErrTTYMode(c *check.C) {
|
|||
// Test for #10388 - this will run the same test as TestRunAttachStdOutAndErrTTYMode
|
||||
// but using --attach instead of -a to make sure we read the flag correctly
|
||||
func (s *DockerSuite) TestRunAttachWithDetach(c *check.C) {
|
||||
cmd := exec.Command(dockerBinary, "run", "-d", "--attach", "stdout", "busybox", "true")
|
||||
_, stderr, _, err := runCommandWithStdoutStderr(cmd)
|
||||
if err == nil {
|
||||
c.Fatal("Container should have exited with error code different than 0")
|
||||
} else if !strings.Contains(stderr, "Conflicting options: -a and -d") {
|
||||
c.Fatal("Should have been returned an error with conflicting options -a and -d")
|
||||
}
|
||||
icmd.RunCommand(dockerBinary, "run", "-d", "--attach", "stdout", "busybox", "true").Assert(c, icmd.Expected{
|
||||
ExitCode: 1,
|
||||
Error: "exit status 1",
|
||||
Err: "Conflicting options: -a and -d",
|
||||
})
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunState(c *check.C) {
|
||||
|
@ -2279,7 +2275,7 @@ func (s *DockerSuite) TestVolumesNoCopyData(c *check.C) {
|
|||
c.Fatalf("Data was copied on volumes-from but shouldn't be:\n%q", out)
|
||||
}
|
||||
|
||||
tmpDir := randomTmpDirPath("docker_test_bind_mount_copy_data", daemonPlatform)
|
||||
tmpDir := integration.RandomTmpDirPath("docker_test_bind_mount_copy_data", daemonPlatform)
|
||||
if out, _, err := dockerCmdWithError("run", "-v", tmpDir+":/foo", "dataimage", "ls", "-lh", "/foo/bar"); err == nil || !strings.Contains(out, "No such file or directory") {
|
||||
c.Fatalf("Data was copied on bind-mount but shouldn't be:\n%q", out)
|
||||
}
|
||||
|
@ -2348,7 +2344,7 @@ func (s *DockerSuite) TestRunSlowStdoutConsumer(c *check.C) {
|
|||
if err := cont.Start(); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
n, err := consumeWithSpeed(stdout, 10000, 5*time.Millisecond, nil)
|
||||
n, err := integration.ConsumeWithSpeed(stdout, 10000, 5*time.Millisecond, nil)
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
@ -3330,7 +3326,7 @@ func (s *DockerTrustSuite) TestRunWhenCertExpired(c *check.C) {
|
|||
// Certificates have 10 years of expiration
|
||||
elevenYearsFromNow := time.Now().Add(time.Hour * 24 * 365 * 11)
|
||||
|
||||
runAtDifferentDate(elevenYearsFromNow, func() {
|
||||
integration.RunAtDifferentDate(elevenYearsFromNow, func() {
|
||||
// Try run
|
||||
runCmd := exec.Command(dockerBinary, "run", repoName)
|
||||
s.trustedCmd(runCmd)
|
||||
|
@ -3344,7 +3340,7 @@ func (s *DockerTrustSuite) TestRunWhenCertExpired(c *check.C) {
|
|||
}
|
||||
})
|
||||
|
||||
runAtDifferentDate(elevenYearsFromNow, func() {
|
||||
integration.RunAtDifferentDate(elevenYearsFromNow, func() {
|
||||
// Try run
|
||||
runCmd := exec.Command(dockerBinary, "run", "--disable-content-trust", repoName)
|
||||
s.trustedCmd(runCmd)
|
||||
|
@ -3536,7 +3532,7 @@ func (s *DockerSuite) TestRunContainerWithCgroupParent(c *check.C) {
|
|||
if err != nil {
|
||||
c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", string(out), err)
|
||||
}
|
||||
cgroupPaths := parseCgroupPaths(string(out))
|
||||
cgroupPaths := integration.ParseCgroupPaths(string(out))
|
||||
if len(cgroupPaths) == 0 {
|
||||
c.Fatalf("unexpected output - %q", string(out))
|
||||
}
|
||||
|
@ -3565,7 +3561,7 @@ func (s *DockerSuite) TestRunContainerWithCgroupParentAbsPath(c *check.C) {
|
|||
if err != nil {
|
||||
c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", string(out), err)
|
||||
}
|
||||
cgroupPaths := parseCgroupPaths(string(out))
|
||||
cgroupPaths := integration.ParseCgroupPaths(string(out))
|
||||
if len(cgroupPaths) == 0 {
|
||||
c.Fatalf("unexpected output - %q", string(out))
|
||||
}
|
||||
|
@ -3604,7 +3600,7 @@ func (s *DockerSuite) TestRunInvalidCgroupParent(c *check.C) {
|
|||
c.Fatalf("SECURITY: --cgroup-parent with ../../ relative paths cause files to be created in the host (this is bad) !!")
|
||||
}
|
||||
|
||||
cgroupPaths := parseCgroupPaths(string(out))
|
||||
cgroupPaths := integration.ParseCgroupPaths(string(out))
|
||||
if len(cgroupPaths) == 0 {
|
||||
c.Fatalf("unexpected output - %q", string(out))
|
||||
}
|
||||
|
@ -3643,7 +3639,7 @@ func (s *DockerSuite) TestRunAbsoluteInvalidCgroupParent(c *check.C) {
|
|||
c.Fatalf("SECURITY: --cgroup-parent with /../../ garbage paths cause files to be created in the host (this is bad) !!")
|
||||
}
|
||||
|
||||
cgroupPaths := parseCgroupPaths(string(out))
|
||||
cgroupPaths := integration.ParseCgroupPaths(string(out))
|
||||
if len(cgroupPaths) == 0 {
|
||||
c.Fatalf("unexpected output - %q", string(out))
|
||||
}
|
||||
|
@ -4151,15 +4147,8 @@ func (s *DockerSuite) TestRunVolumesMountedAsShared(c *check.C) {
|
|||
|
||||
// Convert this directory into a shared mount point so that we do
|
||||
// not rely on propagation properties of parent mount.
|
||||
cmd := exec.Command("mount", "--bind", tmpDir, tmpDir)
|
||||
if _, err = runCommand(cmd); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
cmd = exec.Command("mount", "--make-private", "--make-shared", tmpDir)
|
||||
if _, err = runCommand(cmd); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
icmd.RunCommand("mount", "--bind", tmpDir, tmpDir).Assert(c, icmd.Success)
|
||||
icmd.RunCommand("mount", "--make-private", "--make-shared", tmpDir).Assert(c, icmd.Success)
|
||||
|
||||
dockerCmd(c, "run", "--privileged", "-v", fmt.Sprintf("%s:/volume-dest:shared", tmpDir), "busybox", "mount", "--bind", "/volume-dest/mnt1", "/volume-dest/mnt1")
|
||||
|
||||
|
@ -4201,25 +4190,15 @@ func (s *DockerSuite) TestRunVolumesMountedAsSlave(c *check.C) {
|
|||
|
||||
// Convert this directory into a shared mount point so that we do
|
||||
// not rely on propagation properties of parent mount.
|
||||
cmd := exec.Command("mount", "--bind", tmpDir, tmpDir)
|
||||
if _, err = runCommand(cmd); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
cmd = exec.Command("mount", "--make-private", "--make-shared", tmpDir)
|
||||
if _, err = runCommand(cmd); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
icmd.RunCommand("mount", "--bind", tmpDir, tmpDir).Assert(c, icmd.Success)
|
||||
icmd.RunCommand("mount", "--make-private", "--make-shared", tmpDir).Assert(c, icmd.Success)
|
||||
|
||||
dockerCmd(c, "run", "-i", "-d", "--name", "parent", "-v", fmt.Sprintf("%s:/volume-dest:slave", tmpDir), "busybox", "top")
|
||||
|
||||
// Bind mount tmpDir2/ onto tmpDir/mnt1. If mount propagates inside
|
||||
// container then contents of tmpDir2/slave-testfile should become
|
||||
// visible at "/volume-dest/mnt1/slave-testfile"
|
||||
cmd = exec.Command("mount", "--bind", tmpDir2, path.Join(tmpDir, "mnt1"))
|
||||
if _, err = runCommand(cmd); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
icmd.RunCommand("mount", "--bind", tmpDir2, path.Join(tmpDir, "mnt1")).Assert(c, icmd.Success)
|
||||
|
||||
out, _ := dockerCmd(c, "exec", "parent", "cat", "/volume-dest/mnt1/slave-testfile")
|
||||
|
||||
|
@ -4628,11 +4607,13 @@ func (s *DockerSuite) TestSlowStdinClosing(c *check.C) {
|
|||
name := "testslowstdinclosing"
|
||||
repeat := 3 // regression happened 50% of the time
|
||||
for i := 0; i < repeat; i++ {
|
||||
cmd := exec.Command(dockerBinary, "run", "--rm", "--name", name, "-i", "busybox", "cat")
|
||||
cmd.Stdin = &delayedReader{}
|
||||
cmd := icmd.Cmd{
|
||||
Command: []string{dockerBinary, "run", "--rm", "--name", name, "-i", "busybox", "cat"},
|
||||
Stdin: &delayedReader{},
|
||||
}
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
_, err := runCommand(cmd)
|
||||
err := icmd.RunCmd(cmd).Error
|
||||
done <- err
|
||||
}()
|
||||
|
||||
|
|
|
@ -71,9 +71,7 @@ func (s *DockerSuite) TestRunWithVolumesIsRecursive(c *check.C) {
|
|||
c.Assert(err, checker.IsNil)
|
||||
defer f.Close()
|
||||
|
||||
runCmd := exec.Command(dockerBinary, "run", "--name", "test-data", "--volume", fmt.Sprintf("%s:/tmp:ro", tmpDir), "busybox:latest", "ls", "/tmp/tmpfs")
|
||||
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
||||
c.Assert(err, checker.IsNil)
|
||||
out, _ := dockerCmd(c, "run", "--name", "test-data", "--volume", fmt.Sprintf("%s:/tmp:ro", tmpDir), "busybox:latest", "ls", "/tmp/tmpfs")
|
||||
c.Assert(out, checker.Contains, filepath.Base(f.Name()), check.Commentf("Recursive bind mount test failed. Expected file not found"))
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/docker/distribution/digest"
|
||||
"github.com/docker/docker/pkg/integration"
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
@ -29,7 +30,7 @@ func (s *DockerSuite) TestSaveXzAndLoadRepoStdout(c *check.C) {
|
|||
|
||||
dockerCmd(c, "inspect", repoName)
|
||||
|
||||
repoTarball, _, err := runCommandPipelineWithOutput(
|
||||
repoTarball, _, err := integration.RunCommandPipelineWithOutput(
|
||||
exec.Command(dockerBinary, "save", repoName),
|
||||
exec.Command("xz", "-c"),
|
||||
exec.Command("gzip", "-c"))
|
||||
|
@ -56,7 +57,7 @@ func (s *DockerSuite) TestSaveXzGzAndLoadRepoStdout(c *check.C) {
|
|||
|
||||
dockerCmd(c, "inspect", repoName)
|
||||
|
||||
out, _, err := runCommandPipelineWithOutput(
|
||||
out, _, err := integration.RunCommandPipelineWithOutput(
|
||||
exec.Command(dockerBinary, "save", repoName),
|
||||
exec.Command("xz", "-c"),
|
||||
exec.Command("gzip", "-c"))
|
||||
|
@ -81,7 +82,7 @@ func (s *DockerSuite) TestSaveSingleTag(c *check.C) {
|
|||
out, _ := dockerCmd(c, "images", "-q", "--no-trunc", repoName)
|
||||
cleanedImageID := strings.TrimSpace(out)
|
||||
|
||||
out, _, err := runCommandPipelineWithOutput(
|
||||
out, _, err := integration.RunCommandPipelineWithOutput(
|
||||
exec.Command(dockerBinary, "save", fmt.Sprintf("%v:latest", repoName)),
|
||||
exec.Command("tar", "t"),
|
||||
exec.Command("grep", "-E", fmt.Sprintf("(^repositories$|%v)", cleanedImageID)))
|
||||
|
@ -100,7 +101,7 @@ func (s *DockerSuite) TestSaveCheckTimes(c *check.C) {
|
|||
c.Assert(err, checker.IsNil, check.Commentf("failed to marshal from %q: err %v", repoName, err))
|
||||
c.Assert(len(data), checker.Not(checker.Equals), 0, check.Commentf("failed to marshal the data from %q", repoName))
|
||||
tarTvTimeFormat := "2006-01-02 15:04"
|
||||
out, _, err = runCommandPipelineWithOutput(
|
||||
out, _, err = integration.RunCommandPipelineWithOutput(
|
||||
exec.Command(dockerBinary, "save", repoName),
|
||||
exec.Command("tar", "tv"),
|
||||
exec.Command("grep", "-E", fmt.Sprintf("%s %s", data[0].Created.Format(tarTvTimeFormat), digest.Digest(data[0].ID).Hex())))
|
||||
|
@ -158,7 +159,7 @@ func (s *DockerSuite) TestSaveAndLoadRepoFlags(c *check.C) {
|
|||
|
||||
before, _ := dockerCmd(c, "inspect", repoName)
|
||||
|
||||
out, _, err := runCommandPipelineWithOutput(
|
||||
out, _, err := integration.RunCommandPipelineWithOutput(
|
||||
exec.Command(dockerBinary, "save", repoName),
|
||||
exec.Command(dockerBinary, "load"))
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to save and load repo: %s, %v", out, err))
|
||||
|
@ -187,7 +188,7 @@ func (s *DockerSuite) TestSaveMultipleNames(c *check.C) {
|
|||
// Make two images
|
||||
dockerCmd(c, "tag", "emptyfs:latest", fmt.Sprintf("%v-two:latest", repoName))
|
||||
|
||||
out, _, err := runCommandPipelineWithOutput(
|
||||
out, _, err := integration.RunCommandPipelineWithOutput(
|
||||
exec.Command(dockerBinary, "save", fmt.Sprintf("%v-one", repoName), fmt.Sprintf("%v-two:latest", repoName)),
|
||||
exec.Command("tar", "xO", "repositories"),
|
||||
exec.Command("grep", "-q", "-E", "(-one|-two)"),
|
||||
|
@ -219,7 +220,7 @@ func (s *DockerSuite) TestSaveRepoWithMultipleImages(c *check.C) {
|
|||
deleteImages(repoName)
|
||||
|
||||
// create the archive
|
||||
out, _, err := runCommandPipelineWithOutput(
|
||||
out, _, err := integration.RunCommandPipelineWithOutput(
|
||||
exec.Command(dockerBinary, "save", repoName, "busybox:latest"),
|
||||
exec.Command("tar", "t"))
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to save multiple images: %s, %v", out, err))
|
||||
|
@ -266,7 +267,7 @@ func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) {
|
|||
true)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("%v", err))
|
||||
|
||||
out, _, err := runCommandPipelineWithOutput(
|
||||
out, _, err := integration.RunCommandPipelineWithOutput(
|
||||
exec.Command(dockerBinary, "save", name),
|
||||
exec.Command("tar", "-xf", "-", "-C", extractionDirectory),
|
||||
)
|
||||
|
@ -285,7 +286,7 @@ func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) {
|
|||
c.Assert(err, checker.IsNil, check.Commentf("failed to open %s: %s", layerPath, err))
|
||||
defer f.Close()
|
||||
|
||||
entries, err := listTar(f)
|
||||
entries, err := integration.ListTar(f)
|
||||
for _, e := range entries {
|
||||
if !strings.Contains(e, "dev/") {
|
||||
entriesSansDev = append(entriesSansDev, e)
|
||||
|
@ -363,7 +364,7 @@ func (s *DockerSuite) TestSaveLoadNoTag(c *check.C) {
|
|||
id := inspectField(c, name, "Id")
|
||||
|
||||
// Test to make sure that save w/o name just shows imageID during load
|
||||
out, _, err := runCommandPipelineWithOutput(
|
||||
out, _, err := integration.RunCommandPipelineWithOutput(
|
||||
exec.Command(dockerBinary, "save", id),
|
||||
exec.Command(dockerBinary, "load"))
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to save and load repo: %s, %v", out, err))
|
||||
|
@ -374,7 +375,7 @@ func (s *DockerSuite) TestSaveLoadNoTag(c *check.C) {
|
|||
c.Assert(out, checker.Contains, id)
|
||||
|
||||
// Test to make sure that save by name shows that name during load
|
||||
out, _, err = runCommandPipelineWithOutput(
|
||||
out, _, err = integration.RunCommandPipelineWithOutput(
|
||||
exec.Command(dockerBinary, "save", name),
|
||||
exec.Command(dockerBinary, "load"))
|
||||
c.Assert(err, checker.IsNil, check.Commentf("failed to save and load repo: %s, %v", out, err))
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
icmd "github.com/docker/docker/pkg/integration/cmd"
|
||||
"github.com/go-check/check"
|
||||
"github.com/kr/pty"
|
||||
)
|
||||
|
@ -29,11 +30,10 @@ func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *check.C) {
|
|||
c.Assert(err, check.IsNil)
|
||||
defer os.Remove(tmpFile.Name())
|
||||
|
||||
saveCmd := exec.Command(dockerBinary, "save", repoName)
|
||||
saveCmd.Stdout = tmpFile
|
||||
|
||||
_, err = runCommand(saveCmd)
|
||||
c.Assert(err, check.IsNil)
|
||||
icmd.RunCmd(icmd.Cmd{
|
||||
Command: []string{dockerBinary, "save", repoName},
|
||||
Stdout: tmpFile,
|
||||
}).Assert(c, icmd.Success)
|
||||
|
||||
tmpFile, err = os.Open(tmpFile.Name())
|
||||
c.Assert(err, check.IsNil)
|
||||
|
|
|
@ -2,11 +2,11 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
icmd "github.com/docker/docker/pkg/integration/cmd"
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
|
@ -182,8 +182,13 @@ func (s *DockerSuite) TestStartAttachWithRename(c *check.C) {
|
|||
dockerCmd(c, "rename", "before", "after")
|
||||
dockerCmd(c, "stop", "--time=2", "after")
|
||||
}()
|
||||
_, stderr, _, _ := runCommandWithStdoutStderr(exec.Command(dockerBinary, "start", "-a", "before"))
|
||||
c.Assert(stderr, checker.Not(checker.Contains), "No such container")
|
||||
// FIXME(vdemeester) the intent is not clear and potentially racey
|
||||
result := icmd.RunCommand(dockerBinary, "start", "-a", "before")
|
||||
result.Assert(c, icmd.Expected{
|
||||
ExitCode: 137,
|
||||
Error: "exit status 137",
|
||||
})
|
||||
c.Assert(result.Stderr(), checker.Not(checker.Contains), "No such container")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestStartReturnCorrectExitCode(c *check.C) {
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/pkg/integration"
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/docker/docker/pkg/system"
|
||||
|
@ -61,12 +62,12 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *check.C) {
|
|||
c.Assert(err, checker.IsNil, check.Commentf("Could not inspect running container: out: %q", pid))
|
||||
// check the uid and gid maps for the PID to ensure root is remapped
|
||||
// (cmd = cat /proc/<pid>/uid_map | grep -E '0\s+9999\s+1')
|
||||
out, rc1, err := runCommandPipelineWithOutput(
|
||||
out, rc1, err := integration.RunCommandPipelineWithOutput(
|
||||
exec.Command("cat", "/proc/"+strings.TrimSpace(pid)+"/uid_map"),
|
||||
exec.Command("grep", "-E", fmt.Sprintf("0[[:space:]]+%d[[:space:]]+", uid)))
|
||||
c.Assert(rc1, checker.Equals, 0, check.Commentf("Didn't match uid_map: output: %s", out))
|
||||
|
||||
out, rc2, err := runCommandPipelineWithOutput(
|
||||
out, rc2, err := integration.RunCommandPipelineWithOutput(
|
||||
exec.Command("cat", "/proc/"+strings.TrimSpace(pid)+"/gid_map"),
|
||||
exec.Command("grep", "-E", fmt.Sprintf("0[[:space:]]+%d[[:space:]]+", gid)))
|
||||
c.Assert(rc2, checker.Equals, 0, check.Commentf("Didn't match gid_map: output: %s", out))
|
||||
|
|
|
@ -16,8 +16,8 @@ import (
|
|||
func (s *DockerSuite) TestVolumeCLICreate(c *check.C) {
|
||||
dockerCmd(c, "volume", "create")
|
||||
|
||||
_, err := runCommand(exec.Command(dockerBinary, "volume", "create", "-d", "nosuchdriver"))
|
||||
c.Assert(err, check.Not(check.IsNil))
|
||||
_, _, err := dockerCmdWithError("volume", "create", "-d", "nosuchdriver")
|
||||
c.Assert(err, check.NotNil)
|
||||
|
||||
// test using hidden --name option
|
||||
out, _ := dockerCmd(c, "volume", "create", "--name=test")
|
||||
|
@ -250,6 +250,7 @@ func (s *DockerSuite) TestVolumeCLIRm(c *check.C) {
|
|||
)
|
||||
}
|
||||
|
||||
// FIXME(vdemeester) should be a unit test in cli/command/volume package
|
||||
func (s *DockerSuite) TestVolumeCLINoArgs(c *check.C) {
|
||||
out, _ := dockerCmd(c, "volume")
|
||||
// no args should produce the cmd usage output
|
||||
|
@ -257,15 +258,20 @@ func (s *DockerSuite) TestVolumeCLINoArgs(c *check.C) {
|
|||
c.Assert(out, checker.Contains, usage)
|
||||
|
||||
// invalid arg should error and show the command usage on stderr
|
||||
_, stderr, _, err := runCommandWithStdoutStderr(exec.Command(dockerBinary, "volume", "somearg"))
|
||||
c.Assert(err, check.NotNil, check.Commentf(stderr))
|
||||
c.Assert(stderr, checker.Contains, usage)
|
||||
icmd.RunCommand(dockerBinary, "volume", "somearg").Assert(c, icmd.Expected{
|
||||
ExitCode: 1,
|
||||
Error: "exit status 1",
|
||||
Err: usage,
|
||||
})
|
||||
|
||||
// invalid flag should error and show the flag error and cmd usage
|
||||
_, stderr, _, err = runCommandWithStdoutStderr(exec.Command(dockerBinary, "volume", "--no-such-flag"))
|
||||
c.Assert(err, check.NotNil, check.Commentf(stderr))
|
||||
c.Assert(stderr, checker.Contains, usage)
|
||||
c.Assert(stderr, checker.Contains, "unknown flag: --no-such-flag")
|
||||
result := icmd.RunCommand(dockerBinary, "volume", "--no-such-flag")
|
||||
result.Assert(c, icmd.Expected{
|
||||
ExitCode: 125,
|
||||
Error: "exit status 125",
|
||||
Err: usage,
|
||||
})
|
||||
c.Assert(result.Stderr(), checker.Contains, "unknown flag: --no-such-flag")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestVolumeCLIInspectTmplError(c *check.C) {
|
||||
|
|
|
@ -45,7 +45,7 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartVolumeBinds(c *check.C) {
|
|||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusCreated)
|
||||
|
||||
bindPath := randomTmpDirPath("test", daemonPlatform)
|
||||
bindPath := integration.RandomTmpDirPath("test", daemonPlatform)
|
||||
config = map[string]interface{}{
|
||||
"Binds": []string{bindPath + ":" + path},
|
||||
}
|
||||
|
@ -72,8 +72,8 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartDupVolumeBinds(c *check.C)
|
|||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusCreated)
|
||||
|
||||
bindPath1 := randomTmpDirPath("test1", daemonPlatform)
|
||||
bindPath2 := randomTmpDirPath("test2", daemonPlatform)
|
||||
bindPath1 := integration.RandomTmpDirPath("test1", daemonPlatform)
|
||||
bindPath2 := integration.RandomTmpDirPath("test2", daemonPlatform)
|
||||
|
||||
config = map[string]interface{}{
|
||||
"Binds": []string{bindPath1 + ":/tmp", bindPath2 + ":/tmp"},
|
||||
|
|
|
@ -902,15 +902,17 @@ func buildImageWithOut(name, dockerfile string, useCache bool, buildFlags ...str
|
|||
|
||||
func buildImageWithStdoutStderr(name, dockerfile string, useCache bool, buildFlags ...string) (string, string, string, error) {
|
||||
buildCmd := buildImageCmd(name, dockerfile, useCache, buildFlags...)
|
||||
stdout, stderr, exitCode, err := runCommandWithStdoutStderr(buildCmd)
|
||||
result := icmd.RunCmd(transformCmd(buildCmd))
|
||||
err := result.Error
|
||||
exitCode := result.ExitCode
|
||||
if err != nil || exitCode != 0 {
|
||||
return "", stdout, stderr, fmt.Errorf("failed to build the image: %s", stdout)
|
||||
return "", result.Stdout(), result.Stderr(), fmt.Errorf("failed to build the image: %s", result.Combined())
|
||||
}
|
||||
id, err := getIDByName(name)
|
||||
if err != nil {
|
||||
return "", stdout, stderr, err
|
||||
return "", result.Stdout(), result.Stderr(), err
|
||||
}
|
||||
return id, stdout, stderr, nil
|
||||
return id, result.Stdout(), result.Stderr(), nil
|
||||
}
|
||||
|
||||
func buildImage(name, dockerfile string, useCache bool, buildFlags ...string) (string, error) {
|
||||
|
@ -953,18 +955,21 @@ func buildImageFromContextWithStdoutStderr(name string, ctx *FakeContext, useCac
|
|||
}
|
||||
args = append(args, buildFlags...)
|
||||
args = append(args, ".")
|
||||
buildCmd := exec.Command(dockerBinary, args...)
|
||||
buildCmd.Dir = ctx.Dir
|
||||
|
||||
stdout, stderr, exitCode, err := runCommandWithStdoutStderr(buildCmd)
|
||||
result := icmd.RunCmd(icmd.Cmd{
|
||||
Command: append([]string{dockerBinary}, args...),
|
||||
Dir: ctx.Dir,
|
||||
})
|
||||
exitCode := result.ExitCode
|
||||
err := result.Error
|
||||
if err != nil || exitCode != 0 {
|
||||
return "", stdout, stderr, fmt.Errorf("failed to build the image: %s", stdout)
|
||||
return "", result.Stdout(), result.Stderr(), fmt.Errorf("failed to build the image: %s", result.Combined())
|
||||
}
|
||||
id, err := getIDByName(name)
|
||||
if err != nil {
|
||||
return "", stdout, stderr, err
|
||||
return "", result.Stdout(), result.Stderr(), err
|
||||
}
|
||||
return id, stdout, stderr, nil
|
||||
return id, result.Stdout(), result.Stderr(), nil
|
||||
}
|
||||
|
||||
func buildImageFromGitWithStdoutStderr(name string, ctx *fakeGit, useCache bool, buildFlags ...string) (string, string, string, error) {
|
||||
|
@ -974,17 +979,19 @@ func buildImageFromGitWithStdoutStderr(name string, ctx *fakeGit, useCache bool,
|
|||
}
|
||||
args = append(args, buildFlags...)
|
||||
args = append(args, ctx.RepoURL)
|
||||
buildCmd := exec.Command(dockerBinary, args...)
|
||||
|
||||
stdout, stderr, exitCode, err := runCommandWithStdoutStderr(buildCmd)
|
||||
result := icmd.RunCmd(icmd.Cmd{
|
||||
Command: append([]string{dockerBinary}, args...),
|
||||
})
|
||||
exitCode := result.ExitCode
|
||||
err := result.Error
|
||||
if err != nil || exitCode != 0 {
|
||||
return "", stdout, stderr, fmt.Errorf("failed to build the image: %s", stdout)
|
||||
return "", result.Stdout(), result.Stderr(), fmt.Errorf("failed to build the image: %s", result.Combined())
|
||||
}
|
||||
id, err := getIDByName(name)
|
||||
if err != nil {
|
||||
return "", stdout, stderr, err
|
||||
return "", result.Stdout(), result.Stderr(), err
|
||||
}
|
||||
return id, stdout, stderr, nil
|
||||
return id, result.Stdout(), result.Stderr(), nil
|
||||
}
|
||||
|
||||
func buildImageFromPath(name, path string, useCache bool, buildFlags ...string) (string, error) {
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/pkg/integration"
|
||||
"github.com/docker/docker/pkg/integration/cmd"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func getPrefixAndSlashFromDaemonPlatform() (prefix, slash string) {
|
||||
|
@ -23,18 +18,6 @@ func runCommandWithOutput(execCmd *exec.Cmd) (string, int, error) {
|
|||
return result.Combined(), result.ExitCode, result.Error
|
||||
}
|
||||
|
||||
// TODO: update code to call cmd.RunCmd directly, and remove this function
|
||||
func runCommandWithStdoutStderr(execCmd *exec.Cmd) (string, string, int, error) {
|
||||
result := cmd.RunCmd(transformCmd(execCmd))
|
||||
return result.Stdout(), result.Stderr(), result.ExitCode, result.Error
|
||||
}
|
||||
|
||||
// TODO: update code to call cmd.RunCmd directly, and remove this function
|
||||
func runCommand(execCmd *exec.Cmd) (exitCode int, err error) {
|
||||
result := cmd.RunCmd(transformCmd(execCmd))
|
||||
return result.ExitCode, result.Error
|
||||
}
|
||||
|
||||
// Temporary shim for migrating commands to the new function
|
||||
func transformCmd(execCmd *exec.Cmd) cmd.Cmd {
|
||||
return cmd.Cmd{
|
||||
|
@ -45,35 +28,3 @@ func transformCmd(execCmd *exec.Cmd) cmd.Cmd {
|
|||
Stdout: execCmd.Stdout,
|
||||
}
|
||||
}
|
||||
|
||||
func runCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, exitCode int, err error) {
|
||||
return integration.RunCommandPipelineWithOutput(cmds...)
|
||||
}
|
||||
|
||||
func convertSliceOfStringsToMap(input []string) map[string]struct{} {
|
||||
return integration.ConvertSliceOfStringsToMap(input)
|
||||
}
|
||||
|
||||
func compareDirectoryEntries(e1 []os.FileInfo, e2 []os.FileInfo) error {
|
||||
return integration.CompareDirectoryEntries(e1, e2)
|
||||
}
|
||||
|
||||
func listTar(f io.Reader) ([]string, error) {
|
||||
return integration.ListTar(f)
|
||||
}
|
||||
|
||||
func randomTmpDirPath(s string, platform string) string {
|
||||
return integration.RandomTmpDirPath(s, platform)
|
||||
}
|
||||
|
||||
func consumeWithSpeed(reader io.Reader, chunkSize int, interval time.Duration, stop chan bool) (n int, err error) {
|
||||
return integration.ConsumeWithSpeed(reader, chunkSize, interval, stop)
|
||||
}
|
||||
|
||||
func parseCgroupPaths(procCgroupData string) map[string]string {
|
||||
return integration.ParseCgroupPaths(procCgroupData)
|
||||
}
|
||||
|
||||
func runAtDifferentDate(date time.Time, block func()) {
|
||||
integration.RunAtDifferentDate(date, block)
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче