integration-cli/docker_cli_diff_test.go
6db32fde
 package main
 
 import (
 	"strings"
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
 		}
 	}
 	if !found {
dc944ea7
 		c.Errorf("couldn't find the new file in docker diff's output: %v", out)
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 {
 			if strings.Contains(out, filename) {
dc944ea7
 				c.Errorf("found file which should've been ignored %v in diff output", 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
fbe20aa3
 		"A /dev/mqueue":  true, // lxc
29ac29a4
 		"A /dev/kmsg":    true, // lxc
 		"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") {
 		if line != "" && !expected[line] {
dc944ea7
 			c.Errorf("%q is shown in the diff but shouldn't", line)
dcf2b72f
 		}
 	}
 }
9d84d4c2
 
 // https://github.com/docker/docker/pull/14381#discussion_r33859347
 func (s *DockerSuite) TestDiffEmptyArgClientError(c *check.C) {
693ba98c
 	out, _, err := dockerCmdWithError("diff", "")
9d84d4c2
 	c.Assert(err, check.NotNil)
 	c.Assert(strings.TrimSpace(out), check.Equals, "Container name cannot be empty")
 }