2014-02-25 11:17:48 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
2015-04-18 12:46:47 -04:00
|
|
|
|
|
|
|
"github.com/go-check/check"
|
2014-02-25 11:17:48 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// ensure that an added file shows up in docker diff
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestDiffFilenameShownInOutput(c *check.C) {
|
2014-02-25 11:17:48 -05:00
|
|
|
containerCmd := `echo foo > /root/bar`
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", containerCmd)
|
2014-10-14 15:56:13 -04:00
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("failed to start the container: %s, %v", out, err)
|
2014-10-14 15:56:13 -04:00
|
|
|
}
|
2014-02-25 11:17:48 -05:00
|
|
|
|
2015-04-06 09:21:18 -04:00
|
|
|
cleanCID := strings.TrimSpace(out)
|
2014-02-25 11:17:48 -05:00
|
|
|
|
|
|
|
diffCmd := exec.Command(dockerBinary, "diff", cleanCID)
|
2014-10-14 15:56:13 -04:00
|
|
|
out, _, err = runCommandWithOutput(diffCmd)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("failed to run diff: %s %v", out, err)
|
2014-10-14 15:56:13 -04:00
|
|
|
}
|
2014-02-25 11:17:48 -05:00
|
|
|
|
|
|
|
found := false
|
|
|
|
for _, line := range strings.Split(out, "\n") {
|
|
|
|
if strings.Contains("A /root/bar", line) {
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !found {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Errorf("couldn't find the new file in docker diff's output: %v", out)
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// test to ensure GH #3840 doesn't occur any more
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestDiffEnsureDockerinitFilesAreIgnored(c *check.C) {
|
2014-02-25 11:17:48 -05:00
|
|
|
// 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"}
|
2015-04-23 19:35:13 -04:00
|
|
|
containerCount := 5
|
2014-02-25 11:17:48 -05:00
|
|
|
|
|
|
|
// we might not run into this problem from the first run, so start a few containers
|
2015-04-23 19:35:13 -04:00
|
|
|
for i := 0; i < containerCount; i++ {
|
2014-02-25 11:17:48 -05:00
|
|
|
containerCmd := `echo foo > /root/bar`
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", containerCmd)
|
2014-10-14 15:56:13 -04:00
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
2015-04-23 19:35:13 -04:00
|
|
|
|
2014-10-14 15:56:13 -04:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(out, err)
|
2014-10-14 15:56:13 -04:00
|
|
|
}
|
2014-02-25 11:17:48 -05:00
|
|
|
|
2015-04-06 09:21:18 -04:00
|
|
|
cleanCID := strings.TrimSpace(out)
|
2014-02-25 11:17:48 -05:00
|
|
|
|
|
|
|
diffCmd := exec.Command(dockerBinary, "diff", cleanCID)
|
2014-10-14 15:56:13 -04:00
|
|
|
out, _, err = runCommandWithOutput(diffCmd)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("failed to run diff: %s, %v", out, err)
|
2014-10-14 15:56:13 -04:00
|
|
|
}
|
2014-02-25 11:17:48 -05:00
|
|
|
|
|
|
|
for _, filename := range dockerinitFiles {
|
|
|
|
if strings.Contains(out, filename) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Errorf("found file which should've been ignored %v in diff output", filename)
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-01 17:07:40 -04:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestDiffEnsureOnlyKmsgAndPtmx(c *check.C) {
|
2014-06-26 20:09:41 -04:00
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sleep", "0")
|
2014-10-14 15:56:13 -04:00
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(out, err)
|
2014-10-14 15:56:13 -04:00
|
|
|
}
|
|
|
|
|
2015-04-06 09:21:18 -04:00
|
|
|
cleanCID := strings.TrimSpace(out)
|
2014-04-01 17:07:40 -04:00
|
|
|
|
|
|
|
diffCmd := exec.Command(dockerBinary, "diff", cleanCID)
|
2014-10-14 15:56:13 -04:00
|
|
|
out, _, err = runCommandWithOutput(diffCmd)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("failed to run diff: %s, %v", out, err)
|
2014-10-14 15:56:13 -04:00
|
|
|
}
|
2014-04-01 17:07:40 -04:00
|
|
|
|
|
|
|
expected := map[string]bool{
|
2015-01-23 07:17:05 -05:00
|
|
|
"C /dev": true,
|
|
|
|
"A /dev/full": true, // busybox
|
|
|
|
"C /dev/ptmx": true, // libcontainer
|
|
|
|
"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,
|
2014-04-01 17:07:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, line := range strings.Split(out, "\n") {
|
|
|
|
if line != "" && !expected[line] {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Errorf("%q is shown in the diff but shouldn't", line)
|
2014-04-01 17:07:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-08 04:44:48 -04:00
|
|
|
|
|
|
|
// https://github.com/docker/docker/pull/14381#discussion_r33859347
|
|
|
|
func (s *DockerSuite) TestDiffEmptyArgClientError(c *check.C) {
|
|
|
|
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "diff", ""))
|
|
|
|
c.Assert(err, check.NotNil)
|
|
|
|
c.Assert(strings.TrimSpace(out), check.Equals, "Container name cannot be empty")
|
|
|
|
}
|