1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/integration-cli/utils.go
Daniel Nephin d7022f2b46 Create a unified RunCommand function with Assert()
Remove some run functions and replace them with the unified run command.
Remove DockerCmdWithStdoutStderr
Remove many duplicate runCommand functions.
Also add dockerCmdWithResult()
Allow Result.Assert() to ignore the error message if an exit status is expected.
Fix race in DockerSuite.TestDockerInspectMultipleNetwork
Fix flaky test DockerSuite.TestRunInteractiveWithRestartPolicy

Signed-off-by: Daniel Nephin <dnephin@docker.com>
2016-08-23 15:11:46 -04:00

79 lines
2.3 KiB
Go

package main
import (
"io"
"os"
"os/exec"
"time"
"github.com/docker/docker/pkg/integration"
"github.com/docker/docker/pkg/integration/cmd"
)
func getPrefixAndSlashFromDaemonPlatform() (prefix, slash string) {
if daemonPlatform == "windows" {
return "c:", `\`
}
return "", "/"
}
// TODO: update code to call cmd.RunCmd directly, and remove this function
func runCommandWithOutput(execCmd *exec.Cmd) (string, int, error) {
result := cmd.RunCmd(transformCmd(execCmd))
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{
Command: execCmd.Args,
Env: execCmd.Env,
Dir: execCmd.Dir,
Stdin: execCmd.Stdin,
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)
}