github.com/noxiouz/docker@v0.7.3-0.20160629055221-3d231c78e8c5/integration-cli/docker_cli_diff_test.go (about) 1 package main 2 3 import ( 4 "strings" 5 6 "github.com/docker/docker/pkg/integration/checker" 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 testRequires(c, DaemonIsLinux) 13 containerCmd := `echo foo > /root/bar` 14 out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", containerCmd) 15 16 cleanCID := strings.TrimSpace(out) 17 out, _ = dockerCmd(c, "diff", cleanCID) 18 19 found := false 20 for _, line := range strings.Split(out, "\n") { 21 if strings.Contains("A /root/bar", line) { 22 found = true 23 break 24 } 25 } 26 c.Assert(found, checker.True) 27 } 28 29 // test to ensure GH #3840 doesn't occur any more 30 func (s *DockerSuite) TestDiffEnsureInitLayerFilesAreIgnored(c *check.C) { 31 testRequires(c, DaemonIsLinux) 32 // this is a list of files which shouldn't show up in `docker diff` 33 initLayerFiles := []string{"/etc/resolv.conf", "/etc/hostname", "/etc/hosts", "/.dockerenv"} 34 containerCount := 5 35 36 // we might not run into this problem from the first run, so start a few containers 37 for i := 0; i < containerCount; i++ { 38 containerCmd := `echo foo > /root/bar` 39 out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", containerCmd) 40 41 cleanCID := strings.TrimSpace(out) 42 out, _ = dockerCmd(c, "diff", cleanCID) 43 44 for _, filename := range initLayerFiles { 45 c.Assert(out, checker.Not(checker.Contains), filename) 46 } 47 } 48 } 49 50 func (s *DockerSuite) TestDiffEnsureDefaultDevs(c *check.C) { 51 testRequires(c, DaemonIsLinux) 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/mqueue": true, 62 "A /dev/kmsg": true, 63 "A /dev/fd": true, 64 "A /dev/fuse": true, 65 "A /dev/ptmx": true, 66 "A /dev/null": true, 67 "A /dev/random": true, 68 "A /dev/stdout": true, 69 "A /dev/stderr": true, 70 "A /dev/tty1": true, 71 "A /dev/stdin": true, 72 "A /dev/tty": true, 73 "A /dev/urandom": true, 74 "A /dev/zero": true, 75 } 76 77 for _, line := range strings.Split(out, "\n") { 78 c.Assert(line == "" || expected[line], checker.True, check.Commentf(line)) 79 } 80 } 81 82 // https://github.com/docker/docker/pull/14381#discussion_r33859347 83 func (s *DockerSuite) TestDiffEmptyArgClientError(c *check.C) { 84 out, _, err := dockerCmdWithError("diff", "") 85 c.Assert(err, checker.NotNil) 86 c.Assert(strings.TrimSpace(out), checker.Contains, "Container name cannot be empty") 87 }