integration-cli/docker_cli_diff_test.go
6db32fde
 package main
 
 import (
 	"strings"
dc944ea7
 
7be79767
 	"github.com/docker/docker/pkg/integration/checker"
dc944ea7
 	"github.com/go-check/check"
6db32fde
 )
 
 // ensure that an added file shows up in docker diff
dc944ea7
 func (s *DockerSuite) TestDiffFilenameShownInOutput(c *check.C) {
f9a3558a
 	testRequires(c, DaemonIsLinux)
6db32fde
 	containerCmd := `echo foo > /root/bar`
668e2369
 	out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", containerCmd)
6db32fde
 
475c6531
 	cleanCID := strings.TrimSpace(out)
668e2369
 	out, _ = dockerCmd(c, "diff", cleanCID)
6db32fde
 
 	found := false
 	for _, line := range strings.Split(out, "\n") {
 		if strings.Contains("A /root/bar", line) {
 			found = true
 			break
 		}
 	}
7be79767
 	c.Assert(found, checker.True)
6db32fde
 }
 
 // test to ensure GH #3840 doesn't occur any more
dc944ea7
 func (s *DockerSuite) TestDiffEnsureDockerinitFilesAreIgnored(c *check.C) {
f9a3558a
 	testRequires(c, DaemonIsLinux)
6db32fde
 	// 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"}
50868b2c
 	containerCount := 5
6db32fde
 
 	// we might not run into this problem from the first run, so start a few containers
50868b2c
 	for i := 0; i < containerCount; i++ {
6db32fde
 		containerCmd := `echo foo > /root/bar`
668e2369
 		out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", containerCmd)
6db32fde
 
475c6531
 		cleanCID := strings.TrimSpace(out)
668e2369
 		out, _ = dockerCmd(c, "diff", cleanCID)
6db32fde
 
 		for _, filename := range dockerinitFiles {
7be79767
 			c.Assert(out, checker.Not(checker.Contains), filename)
6db32fde
 		}
 	}
 }
dcf2b72f
 
dc944ea7
 func (s *DockerSuite) TestDiffEnsureOnlyKmsgAndPtmx(c *check.C) {
f9a3558a
 	testRequires(c, DaemonIsLinux)
668e2369
 	out, _ := dockerCmd(c, "run", "-d", "busybox", "sleep", "0")
ac62c543
 
475c6531
 	cleanCID := strings.TrimSpace(out)
668e2369
 	out, _ = dockerCmd(c, "diff", cleanCID)
dcf2b72f
 
 	expected := map[string]bool{
29ac29a4
 		"C /dev":         true,
 		"A /dev/full":    true, // busybox
 		"C /dev/ptmx":    true, // libcontainer
3b5fac46
 		"A /dev/mqueue":  true,
 		"A /dev/kmsg":    true,
29ac29a4
 		"A /dev/fd":      true,
 		"A /dev/fuse":    true,
 		"A /dev/ptmx":    true,
 		"A /dev/null":    true,
 		"A /dev/random":  true,
 		"A /dev/stdout":  true,
 		"A /dev/stderr":  true,
 		"A /dev/tty1":    true,
 		"A /dev/stdin":   true,
 		"A /dev/tty":     true,
 		"A /dev/urandom": true,
 		"A /dev/zero":    true,
dcf2b72f
 	}
 
 	for _, line := range strings.Split(out, "\n") {
7be79767
 		c.Assert(line == "" || expected[line], checker.True)
dcf2b72f
 	}
 }
9d84d4c2
 
 // https://github.com/docker/docker/pull/14381#discussion_r33859347
 func (s *DockerSuite) TestDiffEmptyArgClientError(c *check.C) {
693ba98c
 	out, _, err := dockerCmdWithError("diff", "")
7be79767
 	c.Assert(err, checker.NotNil)
 	c.Assert(strings.TrimSpace(out), checker.Equals, "Container name cannot be empty")
9d84d4c2
 }