integcli: add & use dockerCmdWithTimeout & InDir

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
Upstream-commit: c6965e3e45cc1c46afc885c57e0e6b9a7769722c
Component: engine
This commit is contained in:
unclejack
2014-08-13 19:02:04 +03:00
parent cf1e3ce7c5
commit 3afe5f7408
3 changed files with 54 additions and 43 deletions

View File

@ -345,12 +345,34 @@ func dockerCmd(t *testing.T, args ...string) (string, int, error) {
return out, status, err
}
// execute a docker ocmmand with a timeout
func dockerCmdWithTimeout(timeout time.Duration, args ...string) (string, int, error) {
out, status, err := runCommandWithOutputAndTimeout(exec.Command(dockerBinary, args...), timeout)
if err != nil {
return out, status, fmt.Errorf("'%s' failed with errors: %v : %q)", strings.Join(args, " "), err, out)
}
return out, status, err
}
// execute a docker command in a directory
func dockerCmdInDir(t *testing.T, path string, args ...string) (string, int, error) {
dockerCommand := exec.Command(dockerBinary, args...)
dockerCommand.Dir = path
out, status, err := runCommandWithOutput(dockerCommand)
errorOut(err, t, fmt.Sprintf("'%s' failed with errors: %v (%v)", strings.Join(args, " "), err, out))
if err != nil {
return out, status, fmt.Errorf("'%s' failed with errors: %v : %q)", strings.Join(args, " "), err, out)
}
return out, status, err
}
// execute a docker command in a directory with a timeout
func dockerCmdInDirWithTimeout(timeout time.Duration, path string, args ...string) (string, int, error) {
dockerCommand := exec.Command(dockerBinary, args...)
dockerCommand.Dir = path
out, status, err := runCommandWithOutputAndTimeout(dockerCommand, timeout)
if err != nil {
return out, status, fmt.Errorf("'%s' failed with errors: %v : %q)", strings.Join(args, " "), err, out)
}
return out, status, err
}