docker_cli_links_unix_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // +build !windows
  2. package main
  3. import (
  4. "io/ioutil"
  5. "os"
  6. "strings"
  7. "github.com/go-check/check"
  8. )
  9. func (s *DockerSuite) TestLinksEtcHostsRegularFile(c *check.C) {
  10. out, _ := dockerCmd(c, "run", "--net=host", "busybox", "ls", "-la", "/etc/hosts")
  11. if !strings.HasPrefix(out, "-") {
  12. c.Errorf("/etc/hosts should be a regular file")
  13. }
  14. }
  15. func (s *DockerSuite) TestLinksEtcHostsContentMatch(c *check.C) {
  16. testRequires(c, SameHostDaemon)
  17. out, _ := dockerCmd(c, "run", "--net=host", "busybox", "cat", "/etc/hosts")
  18. hosts, err := ioutil.ReadFile("/etc/hosts")
  19. if os.IsNotExist(err) {
  20. c.Skip("/etc/hosts does not exist, skip this test")
  21. }
  22. if out != string(hosts) {
  23. c.Errorf("container")
  24. }
  25. }
  26. func (s *DockerSuite) TestLinksNetworkHostContainer(c *check.C) {
  27. dockerCmd(c, "run", "-d", "--net", "host", "--name", "host_container", "busybox", "top")
  28. out, _, err := dockerCmdWithError(c, "run", "--name", "should_fail", "--link", "host_container:tester", "busybox", "true")
  29. if err == nil || !strings.Contains(out, "--net=host can't be used with links. This would result in undefined behavior") {
  30. c.Fatalf("Running container linking to a container with --net host should have failed: %s", out)
  31. }
  32. }