mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-03 04:01:31 +00:00
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:
@@ -0,0 +1,66 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// ensure that an added file shows up in docker diff
|
||||
func TestDiffFilenameShownInOutput(t *testing.T) {
|
||||
containerCmd := `echo foo > /root/bar`
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", containerCmd)
|
||||
cid, _, err := runCommandWithOutput(runCmd)
|
||||
errorOut(err, t, fmt.Sprintf("failed to start the container: %v", err))
|
||||
|
||||
cleanCID := stripTrailingCharacters(cid)
|
||||
|
||||
diffCmd := exec.Command(dockerBinary, "diff", cleanCID)
|
||||
out, _, err := runCommandWithOutput(diffCmd)
|
||||
errorOut(err, t, fmt.Sprintf("failed to run diff: %v %v", out, err))
|
||||
|
||||
found := false
|
||||
for _, line := range strings.Split(out, "\n") {
|
||||
if strings.Contains("A /root/bar", line) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Errorf("couldn't find the new file in docker diff's output: %v", out)
|
||||
}
|
||||
go deleteContainer(cleanCID)
|
||||
|
||||
logDone("diff - check if created file shows up")
|
||||
}
|
||||
|
||||
// test to ensure GH #3840 doesn't occur any more
|
||||
func TestDiffEnsureDockerinitFilesAreIgnored(t *testing.T) {
|
||||
// this is a list of files which shouldn't show up in `docker diff`
|
||||
dockerinitFiles := []string{"/etc/resolv.conf", "/etc/hostname", "/etc/hosts", "/.dockerinit", "/.dockerenv"}
|
||||
|
||||
// we might not run into this problem from the first run, so start a few containers
|
||||
for i := 0; i < 20; i++ {
|
||||
containerCmd := `echo foo > /root/bar`
|
||||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", containerCmd)
|
||||
cid, _, err := runCommandWithOutput(runCmd)
|
||||
errorOut(err, t, fmt.Sprintf("%s", err))
|
||||
|
||||
cleanCID := stripTrailingCharacters(cid)
|
||||
|
||||
diffCmd := exec.Command(dockerBinary, "diff", cleanCID)
|
||||
out, _, err := runCommandWithOutput(diffCmd)
|
||||
errorOut(err, t, fmt.Sprintf("failed to run diff: %v %v", out, err))
|
||||
|
||||
go deleteContainer(cleanCID)
|
||||
|
||||
for _, filename := range dockerinitFiles {
|
||||
if strings.Contains(out, filename) {
|
||||
t.Errorf("found file which should've been ignored %v in diff output", filename)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logDone("diff - check if ignored files show up in diff")
|
||||
}
|
||||
Reference in New Issue
Block a user