2014-02-25 16:17:48 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
2015-04-18 16:46:47 +00:00
|
|
|
|
2015-10-19 09:31:02 +00:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
2015-04-18 16:46:47 +00:00
|
|
|
"github.com/go-check/check"
|
2014-02-25 16:17:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ensure that an added file shows up in docker diff
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestDiffFilenameShownInOutput(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2014-02-25 16:17:48 +00:00
|
|
|
containerCmd := `echo foo > /root/bar`
|
2015-07-20 06:55:40 +00:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", containerCmd)
|
2014-02-25 16:17:48 +00:00
|
|
|
|
2015-04-06 13:21:18 +00:00
|
|
|
cleanCID := strings.TrimSpace(out)
|
2015-07-20 06:55:40 +00:00
|
|
|
out, _ = dockerCmd(c, "diff", cleanCID)
|
2014-02-25 16:17:48 +00:00
|
|
|
|
|
|
|
found := false
|
|
|
|
for _, line := range strings.Split(out, "\n") {
|
|
|
|
if strings.Contains("A /root/bar", line) {
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2015-10-19 09:31:02 +00:00
|
|
|
c.Assert(found, checker.True)
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// test to ensure GH #3840 doesn't occur any more
|
2016-01-20 11:53:54 +00:00
|
|
|
func (s *DockerSuite) TestDiffEnsureInitLayerFilesAreIgnored(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2014-02-25 16:17:48 +00:00
|
|
|
// this is a list of files which shouldn't show up in `docker diff`
|
2016-01-20 11:53:54 +00:00
|
|
|
initLayerFiles := []string{"/etc/resolv.conf", "/etc/hostname", "/etc/hosts", "/.dockerenv"}
|
2015-04-23 23:35:13 +00:00
|
|
|
containerCount := 5
|
2014-02-25 16:17:48 +00:00
|
|
|
|
|
|
|
// we might not run into this problem from the first run, so start a few containers
|
2015-04-23 23:35:13 +00:00
|
|
|
for i := 0; i < containerCount; i++ {
|
2014-02-25 16:17:48 +00:00
|
|
|
containerCmd := `echo foo > /root/bar`
|
2015-07-20 06:55:40 +00:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", containerCmd)
|
2014-02-25 16:17:48 +00:00
|
|
|
|
2015-04-06 13:21:18 +00:00
|
|
|
cleanCID := strings.TrimSpace(out)
|
2015-07-20 06:55:40 +00:00
|
|
|
out, _ = dockerCmd(c, "diff", cleanCID)
|
2014-02-25 16:17:48 +00:00
|
|
|
|
2016-01-20 11:53:54 +00:00
|
|
|
for _, filename := range initLayerFiles {
|
2015-10-19 09:31:02 +00:00
|
|
|
c.Assert(out, checker.Not(checker.Contains), filename)
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-01 21:07:40 +00:00
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestDiffEnsureOnlyKmsgAndPtmx(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-20 06:55:40 +00:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "sleep", "0")
|
2014-10-14 19:56:13 +00:00
|
|
|
|
2015-04-06 13:21:18 +00:00
|
|
|
cleanCID := strings.TrimSpace(out)
|
2015-07-20 06:55:40 +00:00
|
|
|
out, _ = dockerCmd(c, "diff", cleanCID)
|
2014-04-01 21:07:40 +00:00
|
|
|
|
|
|
|
expected := map[string]bool{
|
2015-01-23 12:17:05 +00:00
|
|
|
"C /dev": true,
|
|
|
|
"A /dev/full": true, // busybox
|
|
|
|
"C /dev/ptmx": true, // libcontainer
|
2015-11-04 19:39:12 +00:00
|
|
|
"A /dev/mqueue": true,
|
|
|
|
"A /dev/kmsg": true,
|
2015-01-23 12:17:05 +00:00
|
|
|
"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,
|
2014-04-01 21:07:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, line := range strings.Split(out, "\n") {
|
2015-10-19 09:31:02 +00:00
|
|
|
c.Assert(line == "" || expected[line], checker.True)
|
2014-04-01 21:07:40 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-08 08:44:48 +00:00
|
|
|
|
|
|
|
// https://github.com/docker/docker/pull/14381#discussion_r33859347
|
|
|
|
func (s *DockerSuite) TestDiffEmptyArgClientError(c *check.C) {
|
2015-07-27 18:13:25 +00:00
|
|
|
out, _, err := dockerCmdWithError("diff", "")
|
2015-10-19 09:31:02 +00:00
|
|
|
c.Assert(err, checker.NotNil)
|
|
|
|
c.Assert(strings.TrimSpace(out), checker.Equals, "Container name cannot be empty")
|
2015-07-08 08:44:48 +00:00
|
|
|
}
|