github.com/rentongzhang/docker@v1.8.2-rc1/integration-cli/docker_cli_links_unix_test.go (about)

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