Browse Source

Merge pull request #10785 from ahmetalpbalkan/win-cli/TestLinks-skip

integration-cli: add const to skip daemon-requiring cli tests
Arnaud Porterie 10 years ago
parent
commit
306bb28569

+ 8 - 0
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 {
@@ -109,6 +111,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")
 
@@ -213,6 +217,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"))
@@ -265,6 +271,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 {

+ 2 - 0
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)

+ 8 - 0
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
+)

+ 8 - 0
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
+)

+ 30 - 0
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)
+		}
+	}
+}