diff --git a/integration-cli/docker_cli_links_test.go b/integration-cli/docker_cli_links_test.go index 542adc379b..a64c2cf1ea 100644 --- a/integration-cli/docker_cli_links_test.go +++ b/integration-cli/docker_cli_links_test.go @@ -31,6 +31,8 @@ func TestLinksEtcHostsRegularFile(t *testing.T) { } func TestLinksEtcHostsContentMatch(t *testing.T) { + testRequires(t, SameHostDaemon) + runCmd := exec.Command(dockerBinary, "run", "--net=host", "busybox", "cat", "/etc/hosts") out, _, _, err := runCommandWithStdoutStderr(runCmd) if err != nil { @@ -93,6 +95,8 @@ func TestLinksPingLinkedContainersAfterRename(t *testing.T) { } func TestLinksIpTablesRulesWhenLinkAndUnlink(t *testing.T) { + testRequires(t, SameHostDaemon) + dockerCmd(t, "run", "-d", "--name", "child", "--publish", "8080:80", "busybox", "sleep", "10") dockerCmd(t, "run", "-d", "--name", "parent", "--link", "child:http", "busybox", "sleep", "10") @@ -197,6 +201,8 @@ func TestLinksNotStartedParentNotFail(t *testing.T) { } func TestLinksHostsFilesInject(t *testing.T) { + testRequires(t, SameHostDaemon) + defer deleteAllContainers() out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-itd", "--name", "one", "busybox", "top")) @@ -249,6 +255,8 @@ func TestLinksNetworkHostContainer(t *testing.T) { } func TestLinksUpdateOnRestart(t *testing.T) { + testRequires(t, SameHostDaemon) + defer deleteAllContainers() if out, err := exec.Command(dockerBinary, "run", "-d", "--name", "one", "busybox", "top").CombinedOutput(); err != nil { diff --git a/integration-cli/docker_cli_nat_test.go b/integration-cli/docker_cli_nat_test.go index 7e3b595a80..80e2cf2e74 100644 --- a/integration-cli/docker_cli_nat_test.go +++ b/integration-cli/docker_cli_nat_test.go @@ -9,6 +9,8 @@ import ( ) func TestNetworkNat(t *testing.T) { + testRequires(t, SameHostDaemon) + iface, err := net.InterfaceByName("eth0") if err != nil { t.Skipf("Test not running with `make test`. Interface eth0 not found: %s", err) diff --git a/integration-cli/docker_test_vars_cli.go b/integration-cli/docker_test_vars_cli.go new file mode 100644 index 0000000000..e7efb7ce8b --- /dev/null +++ b/integration-cli/docker_test_vars_cli.go @@ -0,0 +1,8 @@ +// +build !daemon + +package main + +const ( + // tests should not assume daemon runs on the same machine as CLI + isLocalDaemon = false +) diff --git a/integration-cli/docker_test_vars_daemon.go b/integration-cli/docker_test_vars_daemon.go new file mode 100644 index 0000000000..a4645900a8 --- /dev/null +++ b/integration-cli/docker_test_vars_daemon.go @@ -0,0 +1,8 @@ +// +build daemon + +package main + +const ( + // tests can assume daemon runs on the same machine as CLI + isLocalDaemon = true +) diff --git a/integration-cli/requirements.go b/integration-cli/requirements.go new file mode 100644 index 0000000000..9d283d8114 --- /dev/null +++ b/integration-cli/requirements.go @@ -0,0 +1,30 @@ +package main + +import ( + "testing" +) + +type TestCondition func() bool + +type TestRequirement struct { + Condition TestCondition + SkipMessage string +} + +// List test requirements +var ( + SameHostDaemon = TestRequirement{ + func() bool { return isLocalDaemon }, + "Test requires docker daemon to runs on the same machine as CLI", + } +) + +// testRequires checks if the environment satisfies the requirements +// for the test to run or skips the tests. +func testRequires(t *testing.T, requirements ...TestRequirement) { + for _, r := range requirements { + if !r.Condition() { + t.Skip(r.SkipMessage) + } + } +}