本文整理汇总了Golang中github.com/docker/docker/pkg/integration/cmd.RunCommand函数的典型用法代码示例。如果您正苦于以下问题:Golang RunCommand函数的具体用法?Golang RunCommand怎么用?Golang RunCommand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RunCommand函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: RunAtDifferentDate
// RunAtDifferentDate runs the specified function with the given time.
// It changes the date of the system, which can led to weird behaviors.
func RunAtDifferentDate(date time.Time, block func()) {
// Layout for date. MMDDhhmmYYYY
const timeLayout = "010203042006"
// Ensure we bring time back to now
now := time.Now().Format(timeLayout)
defer icmd.RunCommand("date", now)
icmd.RunCommand("date", date.Format(timeLayout))
block()
return
}
开发者ID:CWSpear,项目名称:docker,代码行数:13,代码来源:utils.go
示例2: waitInspectWithArgs
func waitInspectWithArgs(name, expr, expected string, timeout time.Duration, arg ...string) error {
after := time.After(timeout)
args := append(arg, "inspect", "-f", expr, name)
for {
result := icmd.RunCommand(dockerBinary, args...)
if result.Error != nil {
if !strings.Contains(result.Stderr(), "No such") {
return fmt.Errorf("error executing docker inspect: %v\n%s",
result.Stderr(), result.Stdout())
}
select {
case <-after:
return result.Error
default:
time.Sleep(10 * time.Millisecond)
continue
}
}
out := strings.TrimSpace(result.Stdout())
if out == expected {
break
}
select {
case <-after:
return fmt.Errorf("condition \"%q == %q\" not true in time", out, expected)
default:
}
time.Sleep(100 * time.Millisecond)
}
return nil
}
开发者ID:Mic92,项目名称:docker,代码行数:35,代码来源:docker_utils.go
示例3: dockerCmd
func dockerCmd(c *check.C, args ...string) (string, int) {
if err := validateArgs(args...); err != nil {
c.Fatalf(err.Error())
}
result := icmd.RunCommand(dockerBinary, args...)
c.Assert(result, icmd.Matches, icmd.Success)
return result.Combined(), result.ExitCode
}
开发者ID:Mic92,项目名称:docker,代码行数:8,代码来源:docker_utils.go
示例4: dockerCmdWithError
func dockerCmdWithError(args ...string) (string, int, error) {
if err := validateArgs(args...); err != nil {
return "", 0, err
}
result := icmd.RunCommand(dockerBinary, args...)
if result.Error != nil {
return result.Combined(), result.ExitCode, result.Compare(icmd.Success)
}
return result.Combined(), result.ExitCode, result.Error
}
开发者ID:Mic92,项目名称:docker,代码行数:10,代码来源:docker_utils.go
示例5: dockerCmdWithStdoutStderr
func dockerCmdWithStdoutStderr(c *check.C, args ...string) (string, string, int) {
if err := validateArgs(args...); err != nil {
c.Fatalf(err.Error())
}
result := icmd.RunCommand(dockerBinary, args...)
// TODO: why is c ever nil?
if c != nil {
c.Assert(result, icmd.Matches, icmd.Success)
}
return result.Stdout(), result.Stderr(), result.ExitCode
}
开发者ID:Mic92,项目名称:docker,代码行数:12,代码来源:docker_utils.go
示例6: TestEventsImageLoad
func (s *DockerSuite) TestEventsImageLoad(c *check.C) {
testRequires(c, DaemonIsLinux)
myImageName := "footest:v1"
dockerCmd(c, "tag", "busybox", myImageName)
since := daemonUnixTime(c)
out, _ := dockerCmd(c, "images", "-q", "--no-trunc", myImageName)
longImageID := strings.TrimSpace(out)
c.Assert(longImageID, checker.Not(check.Equals), "", check.Commentf("Id should not be empty"))
dockerCmd(c, "save", "-o", "saveimg.tar", myImageName)
dockerCmd(c, "rmi", myImageName)
out, _ = dockerCmd(c, "images", "-q", myImageName)
noImageID := strings.TrimSpace(out)
c.Assert(noImageID, checker.Equals, "", check.Commentf("Should not have any image"))
dockerCmd(c, "load", "-i", "saveimg.tar")
result := icmd.RunCommand("rm", "-rf", "saveimg.tar")
c.Assert(result, icmd.Matches, icmd.Success)
out, _ = dockerCmd(c, "images", "-q", "--no-trunc", myImageName)
imageID := strings.TrimSpace(out)
c.Assert(imageID, checker.Equals, longImageID, check.Commentf("Should have same image id as before"))
out, _ = dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=load")
events := strings.Split(strings.TrimSpace(out), "\n")
c.Assert(events, checker.HasLen, 1)
matches := eventstestutils.ScanMap(events[0])
c.Assert(matches["id"], checker.Equals, imageID, check.Commentf("matches: %v\nout:\n%s\n", matches, out))
c.Assert(matches["action"], checker.Equals, "load", check.Commentf("matches: %v\nout:\n%s\n", matches, out))
out, _ = dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=save")
events = strings.Split(strings.TrimSpace(out), "\n")
c.Assert(events, checker.HasLen, 1)
matches = eventstestutils.ScanMap(events[0])
c.Assert(matches["id"], checker.Equals, imageID, check.Commentf("matches: %v\nout:\n%s\n", matches, out))
c.Assert(matches["action"], checker.Equals, "save", check.Commentf("matches: %v\nout:\n%s\n", matches, out))
}
开发者ID:Mic92,项目名称:docker,代码行数:38,代码来源:docker_cli_events_test.go
示例7: TestCpUnprivilegedUser
// Check that cp with unprivileged user doesn't return any error
func (s *DockerSuite) TestCpUnprivilegedUser(c *check.C) {
testRequires(c, DaemonIsLinux)
testRequires(c, UnixCli) // uses chmod/su: not available on windows
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "touch "+cpTestName)
containerID := strings.TrimSpace(out)
out, _ = dockerCmd(c, "wait", containerID)
// failed to set up container
c.Assert(strings.TrimSpace(out), checker.Equals, "0")
tmpdir, err := ioutil.TempDir("", "docker-integration")
c.Assert(err, checker.IsNil)
defer os.RemoveAll(tmpdir)
c.Assert(os.Chmod(tmpdir, 0777), checker.IsNil)
result := icmd.RunCommand("su", "unprivilegeduser", "-c",
fmt.Sprintf("%s cp %s:%s %s", dockerBinary, containerID, cpTestName, tmpdir))
result.Assert(c, icmd.Expected{})
}
开发者ID:Ingensi,项目名称:dockerbeat,代码行数:24,代码来源:docker_cli_cp_test.go
示例8: TestExecExitStatus
func (s *DockerSuite) TestExecExitStatus(c *check.C) {
runSleepingContainer(c, "-d", "--name", "top")
result := icmd.RunCommand(dockerBinary, "exec", "top", "sh", "-c", "exit 23")
c.Assert(result, icmd.Matches, icmd.Expected{ExitCode: 23, Error: "exit status 23"})
}
开发者ID:msabansal,项目名称:docker,代码行数:6,代码来源:docker_cli_exec_test.go
示例9: dockerCmdWithResult
func dockerCmdWithResult(args ...string) *icmd.Result {
return icmd.RunCommand(dockerBinary, args...)
}
开发者ID:Mic92,项目名称:docker,代码行数:3,代码来源:docker_utils.go
示例10: imageExists
func imageExists(image string) error {
return icmd.RunCommand(dockerBinary, "inspect", image).Error
}
开发者ID:Mic92,项目名称:docker,代码行数:3,代码来源:docker_utils.go
示例11: unpauseContainer
func unpauseContainer(container string) error {
return icmd.RunCommand(dockerBinary, "unpause", container).Error
}
开发者ID:Mic92,项目名称:docker,代码行数:3,代码来源:docker_utils.go
示例12: deleteContainer
func deleteContainer(container ...string) error {
result := icmd.RunCommand(dockerBinary, append([]string{"rm", "-fv"}, container...)...)
return result.Compare(icmd.Success)
}
开发者ID:Mic92,项目名称:docker,代码行数:4,代码来源:docker_utils.go
注:本文中的github.com/docker/docker/pkg/integration/cmd.RunCommand函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论