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