docker_cli_diff_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package main
  2. import (
  3. "strings"
  4. "github.com/docker/docker/pkg/integration/checker"
  5. "github.com/go-check/check"
  6. )
  7. // ensure that an added file shows up in docker diff
  8. func (s *DockerSuite) TestDiffFilenameShownInOutput(c *check.C) {
  9. testRequires(c, DaemonIsLinux)
  10. containerCmd := `echo foo > /root/bar`
  11. out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", containerCmd)
  12. cleanCID := strings.TrimSpace(out)
  13. out, _ = dockerCmd(c, "diff", cleanCID)
  14. found := false
  15. for _, line := range strings.Split(out, "\n") {
  16. if strings.Contains("A /root/bar", line) {
  17. found = true
  18. break
  19. }
  20. }
  21. c.Assert(found, checker.True)
  22. }
  23. // test to ensure GH #3840 doesn't occur any more
  24. func (s *DockerSuite) TestDiffEnsureInitLayerFilesAreIgnored(c *check.C) {
  25. testRequires(c, DaemonIsLinux)
  26. // this is a list of files which shouldn't show up in `docker diff`
  27. initLayerFiles := []string{"/etc/resolv.conf", "/etc/hostname", "/etc/hosts", "/.dockerenv"}
  28. containerCount := 5
  29. // we might not run into this problem from the first run, so start a few containers
  30. for i := 0; i < containerCount; i++ {
  31. containerCmd := `echo foo > /root/bar`
  32. out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", containerCmd)
  33. cleanCID := strings.TrimSpace(out)
  34. out, _ = dockerCmd(c, "diff", cleanCID)
  35. for _, filename := range initLayerFiles {
  36. c.Assert(out, checker.Not(checker.Contains), filename)
  37. }
  38. }
  39. }
  40. func (s *DockerSuite) TestDiffEnsureDefaultDevs(c *check.C) {
  41. testRequires(c, DaemonIsLinux)
  42. out, _ := dockerCmd(c, "run", "-d", "busybox", "sleep", "0")
  43. cleanCID := strings.TrimSpace(out)
  44. out, _ = dockerCmd(c, "diff", cleanCID)
  45. expected := map[string]bool{
  46. "C /dev": true,
  47. "A /dev/full": true, // busybox
  48. "C /dev/ptmx": true, // libcontainer
  49. "A /dev/mqueue": true,
  50. "A /dev/kmsg": true,
  51. "A /dev/fd": true,
  52. "A /dev/fuse": true,
  53. "A /dev/ptmx": true,
  54. "A /dev/null": true,
  55. "A /dev/random": true,
  56. "A /dev/stdout": true,
  57. "A /dev/stderr": true,
  58. "A /dev/tty1": true,
  59. "A /dev/stdin": true,
  60. "A /dev/tty": true,
  61. "A /dev/urandom": true,
  62. "A /dev/zero": true,
  63. }
  64. for _, line := range strings.Split(out, "\n") {
  65. c.Assert(line == "" || expected[line], checker.True, check.Commentf(line))
  66. }
  67. }
  68. // https://github.com/docker/docker/pull/14381#discussion_r33859347
  69. func (s *DockerSuite) TestDiffEmptyArgClientError(c *check.C) {
  70. out, _, err := dockerCmdWithError("diff", "")
  71. c.Assert(err, checker.NotNil)
  72. c.Assert(strings.TrimSpace(out), checker.Contains, "Container name cannot be empty")
  73. }