initial version of cli integration tests

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
This commit is contained in:
unclejack
2014-03-29 23:09:40 +02:00
parent c705e4a80b
commit 6db32fdefd
22 changed files with 1117 additions and 2 deletions
+56
View File
@@ -0,0 +1,56 @@
package main
import (
"fmt"
"os/exec"
"strings"
)
func deleteContainer(container string) error {
container = strings.Replace(container, "\n", " ", -1)
container = strings.Trim(container, " ")
rmArgs := fmt.Sprintf("rm %v", container)
rmSplitArgs := strings.Split(rmArgs, " ")
rmCmd := exec.Command(dockerBinary, rmSplitArgs...)
exitCode, err := runCommand(rmCmd)
// set error manually if not set
if exitCode != 0 && err == nil {
err = fmt.Errorf("failed to remove container: `docker rm` exit is non-zero")
}
return err
}
func getAllContainers() (string, error) {
getContainersCmd := exec.Command(dockerBinary, "ps", "-q", "-a")
out, exitCode, err := runCommandWithOutput(getContainersCmd)
if exitCode != 0 && err == nil {
err = fmt.Errorf("failed to get a list of containers: %v\n", out)
}
return out, err
}
func deleteAllContainers() error {
containers, err := getAllContainers()
if err != nil {
fmt.Println(containers)
return err
}
if err = deleteContainer(containers); err != nil {
return err
}
return nil
}
func deleteImages(images string) error {
rmiCmd := exec.Command(dockerBinary, "rmi", images)
exitCode, err := runCommand(rmiCmd)
// set error manually if not set
if exitCode != 0 && err == nil {
err = fmt.Errorf("failed to remove image: `docker rmi` exit is non-zero")
}
return err
}