From 5579bec47be6279569e69c72cccf87864af481de Mon Sep 17 00:00:00 2001 From: Brandon Philips Date: Wed, 21 May 2014 15:07:40 -0700 Subject: [PATCH] integration-cli: tests for /etc/hosts and net=host Some basic tests to make sure this is acting correctly on machines. Docker-DCO-1.1-Signed-off-by: Brandon Philips (github: philips) --- integration-cli/docker_cli_links_test.go | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/integration-cli/docker_cli_links_test.go b/integration-cli/docker_cli_links_test.go index ed30288b7..0480183bc 100644 --- a/integration-cli/docker_cli_links_test.go +++ b/integration-cli/docker_cli_links_test.go @@ -3,10 +3,46 @@ package main import ( "fmt" "github.com/dotcloud/docker/pkg/iptables" + "io/ioutil" + "os" "os/exec" + "strings" "testing" ) +func TestEtcHostsRegularFile(t *testing.T) { + runCmd := exec.Command(dockerBinary, "run", "--net=host", "busybox", "ls", "-la", "/etc/hosts") + out, _, _, err := runCommandWithStdoutStderr(runCmd) + errorOut(err, t, out) + + if !strings.HasPrefix(out, "-") { + t.Errorf("/etc/hosts should be a regular file") + } + + deleteAllContainers() + + logDone("link - /etc/hosts is a regular file") +} + +func TestEtcHostsContentMatch(t *testing.T) { + runCmd := exec.Command(dockerBinary, "run", "--net=host", "busybox", "cat", "/etc/hosts") + out, _, _, err := runCommandWithStdoutStderr(runCmd) + errorOut(err, t, out) + + hosts, err := ioutil.ReadFile("/etc/hosts") + if os.IsNotExist(err) { + t.Skip("/etc/hosts does not exist, skip this test") + } + + if out != string(hosts) { + t.Errorf("container") + } + + deleteAllContainers() + + logDone("link - /etc/hosts matches hosts copy") +} + func TestPingUnlinkedContainers(t *testing.T) { runCmd := exec.Command(dockerBinary, "run", "--rm", "busybox", "sh", "-c", "ping -c 1 alias1 -W 1 && ping -c 1 alias2 -W 1") exitCode, err := runCommand(runCmd)