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