integration-cli: add const to skip daemon-requiring cli tests
| ... | ... |
@@ -31,6 +31,8 @@ func TestLinksEtcHostsRegularFile(t *testing.T) {
|
| 31 | 31 |
} |
| 32 | 32 |
|
| 33 | 33 |
func TestLinksEtcHostsContentMatch(t *testing.T) {
|
| 34 |
+ testRequires(t, SameHostDaemon) |
|
| 35 |
+ |
|
| 34 | 36 |
runCmd := exec.Command(dockerBinary, "run", "--net=host", "busybox", "cat", "/etc/hosts") |
| 35 | 37 |
out, _, _, err := runCommandWithStdoutStderr(runCmd) |
| 36 | 38 |
if err != nil {
|
| ... | ... |
@@ -109,6 +111,8 @@ func TestLinksPingLinkedContainersAfterRename(t *testing.T) {
|
| 109 | 109 |
} |
| 110 | 110 |
|
| 111 | 111 |
func TestLinksIpTablesRulesWhenLinkAndUnlink(t *testing.T) {
|
| 112 |
+ testRequires(t, SameHostDaemon) |
|
| 113 |
+ |
|
| 112 | 114 |
dockerCmd(t, "run", "-d", "--name", "child", "--publish", "8080:80", "busybox", "sleep", "10") |
| 113 | 115 |
dockerCmd(t, "run", "-d", "--name", "parent", "--link", "child:http", "busybox", "sleep", "10") |
| 114 | 116 |
|
| ... | ... |
@@ -213,6 +217,8 @@ func TestLinksNotStartedParentNotFail(t *testing.T) {
|
| 213 | 213 |
} |
| 214 | 214 |
|
| 215 | 215 |
func TestLinksHostsFilesInject(t *testing.T) {
|
| 216 |
+ testRequires(t, SameHostDaemon) |
|
| 217 |
+ |
|
| 216 | 218 |
defer deleteAllContainers() |
| 217 | 219 |
|
| 218 | 220 |
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-itd", "--name", "one", "busybox", "top")) |
| ... | ... |
@@ -265,6 +271,8 @@ func TestLinksNetworkHostContainer(t *testing.T) {
|
| 265 | 265 |
} |
| 266 | 266 |
|
| 267 | 267 |
func TestLinksUpdateOnRestart(t *testing.T) {
|
| 268 |
+ testRequires(t, SameHostDaemon) |
|
| 269 |
+ |
|
| 268 | 270 |
defer deleteAllContainers() |
| 269 | 271 |
|
| 270 | 272 |
if out, err := exec.Command(dockerBinary, "run", "-d", "--name", "one", "busybox", "top").CombinedOutput(); err != nil {
|
| 0 | 8 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,30 @@ |
| 0 |
+package main |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "testing" |
|
| 4 |
+) |
|
| 5 |
+ |
|
| 6 |
+type TestCondition func() bool |
|
| 7 |
+ |
|
| 8 |
+type TestRequirement struct {
|
|
| 9 |
+ Condition TestCondition |
|
| 10 |
+ SkipMessage string |
|
| 11 |
+} |
|
| 12 |
+ |
|
| 13 |
+// List test requirements |
|
| 14 |
+var ( |
|
| 15 |
+ SameHostDaemon = TestRequirement{
|
|
| 16 |
+ func() bool { return isLocalDaemon },
|
|
| 17 |
+ "Test requires docker daemon to runs on the same machine as CLI", |
|
| 18 |
+ } |
|
| 19 |
+) |
|
| 20 |
+ |
|
| 21 |
+// testRequires checks if the environment satisfies the requirements |
|
| 22 |
+// for the test to run or skips the tests. |
|
| 23 |
+func testRequires(t *testing.T, requirements ...TestRequirement) {
|
|
| 24 |
+ for _, r := range requirements {
|
|
| 25 |
+ if !r.Condition() {
|
|
| 26 |
+ t.Skip(r.SkipMessage) |
|
| 27 |
+ } |
|
| 28 |
+ } |
|
| 29 |
+} |