github.com/codemac/docker@v1.2.1-0.20150518222241-6a18412d5b9c/integration-cli/docker_cli_diff_test.go (about) 1 package main 2 3 import ( 4 "os/exec" 5 "strings" 6 7 "github.com/go-check/check" 8 ) 9 10 // ensure that an added file shows up in docker diff 11 func (s *DockerSuite) TestDiffFilenameShownInOutput(c *check.C) { 12 containerCmd := `echo foo > /root/bar` 13 runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", containerCmd) 14 out, _, err := runCommandWithOutput(runCmd) 15 if err != nil { 16 c.Fatalf("failed to start the container: %s, %v", out, err) 17 } 18 19 cleanCID := strings.TrimSpace(out) 20 21 diffCmd := exec.Command(dockerBinary, "diff", cleanCID) 22 out, _, err = runCommandWithOutput(diffCmd) 23 if err != nil { 24 c.Fatalf("failed to run diff: %s %v", out, err) 25 } 26 27 found := false 28 for _, line := range strings.Split(out, "\n") { 29 if strings.Contains("A /root/bar", line) { 30 found = true 31 break 32 } 33 } 34 if !found { 35 c.Errorf("couldn't find the new file in docker diff's output: %v", out) 36 } 37 } 38 39 // test to ensure GH #3840 doesn't occur any more 40 func (s *DockerSuite) TestDiffEnsureDockerinitFilesAreIgnored(c *check.C) { 41 // this is a list of files which shouldn't show up in `docker diff` 42 dockerinitFiles := []string{"/etc/resolv.conf", "/etc/hostname", "/etc/hosts", "/.dockerinit", "/.dockerenv"} 43 containerCount := 5 44 45 // we might not run into this problem from the first run, so start a few containers 46 for i := 0; i < containerCount; i++ { 47 containerCmd := `echo foo > /root/bar` 48 runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", containerCmd) 49 out, _, err := runCommandWithOutput(runCmd) 50 51 if err != nil { 52 c.Fatal(out, err) 53 } 54 55 cleanCID := strings.TrimSpace(out) 56 57 diffCmd := exec.Command(dockerBinary, "diff", cleanCID) 58 out, _, err = runCommandWithOutput(diffCmd) 59 if err != nil { 60 c.Fatalf("failed to run diff: %s, %v", out, err) 61 } 62 63 for _, filename := range dockerinitFiles { 64 if strings.Contains(out, filename) { 65 c.Errorf("found file which should've been ignored %v in diff output", filename) 66 } 67 } 68 } 69 } 70 71 func (s *DockerSuite) TestDiffEnsureOnlyKmsgAndPtmx(c *check.C) { 72 runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sleep", "0") 73 out, _, err := runCommandWithOutput(runCmd) 74 if err != nil { 75 c.Fatal(out, err) 76 } 77 78 cleanCID := strings.TrimSpace(out) 79 80 diffCmd := exec.Command(dockerBinary, "diff", cleanCID) 81 out, _, err = runCommandWithOutput(diffCmd) 82 if err != nil { 83 c.Fatalf("failed to run diff: %s, %v", out, err) 84 } 85 86 expected := map[string]bool{ 87 "C /dev": true, 88 "A /dev/full": true, // busybox 89 "C /dev/ptmx": true, // libcontainer 90 "A /dev/kmsg": true, // lxc 91 "A /dev/fd": true, 92 "A /dev/fuse": true, 93 "A /dev/ptmx": true, 94 "A /dev/null": true, 95 "A /dev/random": true, 96 "A /dev/stdout": true, 97 "A /dev/stderr": true, 98 "A /dev/tty1": true, 99 "A /dev/stdin": true, 100 "A /dev/tty": true, 101 "A /dev/urandom": true, 102 "A /dev/zero": true, 103 } 104 105 for _, line := range strings.Split(out, "\n") { 106 if line != "" && !expected[line] { 107 c.Errorf("%q is shown in the diff but shouldn't", line) 108 } 109 } 110 }