Browse code

Testing: create new daemon (only) if needed

Some tests were skipped if the local daemon did not have
experimental features enabled; at the same time, some tests
unconditionally created a new (experimental) daemon, even if
the local daemon already had experimental enabled.

This patch;

- Checks if the "testEnv" is an experimental Linux daemon
- If not, and the daemon is running locally; spin up a new
experimental daemon to be used during the test.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2018/12/25 00:55:22
Showing 4 changed files
... ...
@@ -21,13 +21,19 @@ import (
21 21
 )
22 22
 
23 23
 func TestBuildWithSession(t *testing.T) {
24
-	skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
25 24
 	skip.If(t, testEnv.DaemonInfo.OSType == "windows")
26
-	d := daemon.New(t, daemon.WithExperimental)
27
-	d.StartWithBusybox(t)
28
-	defer d.Stop(t)
29 25
 
30
-	client := d.NewClientT(t)
26
+	var client dclient.APIClient
27
+	if !testEnv.DaemonInfo.ExperimentalBuild {
28
+		skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
29
+
30
+		d := daemon.New(t, daemon.WithExperimental)
31
+		d.StartWithBusybox(t)
32
+		defer d.Stop(t)
33
+		client = d.NewClientT(t)
34
+	} else {
35
+		client = testEnv.APIClient()
36
+	}
31 37
 
32 38
 	dockerfile := `
33 39
 		FROM busybox
... ...
@@ -9,6 +9,7 @@ import (
9 9
 	"testing"
10 10
 
11 11
 	"github.com/docker/docker/api/types"
12
+	dclient "github.com/docker/docker/client"
12 13
 	"github.com/docker/docker/integration/internal/container"
13 14
 	"github.com/docker/docker/internal/test/daemon"
14 15
 	"github.com/docker/docker/internal/test/fakecontext"
... ...
@@ -20,13 +21,18 @@ import (
20 20
 
21 21
 func TestBuildSquashParent(t *testing.T) {
22 22
 	skip.If(t, testEnv.DaemonInfo.OSType == "windows")
23
-	skip.If(t, !testEnv.DaemonInfo.ExperimentalBuild)
24
-	skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
25
-	d := daemon.New(t, daemon.WithExperimental)
26
-	d.StartWithBusybox(t)
27
-	defer d.Stop(t)
28 23
 
29
-	client := d.NewClientT(t)
24
+	var client dclient.APIClient
25
+	if !testEnv.DaemonInfo.ExperimentalBuild {
26
+		skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
27
+
28
+		d := daemon.New(t, daemon.WithExperimental)
29
+		d.StartWithBusybox(t)
30
+		defer d.Stop(t)
31
+		client = d.NewClientT(t)
32
+	} else {
33
+		client = testEnv.APIClient()
34
+	}
30 35
 
31 36
 	dockerfile := `
32 37
 		FROM busybox
... ...
@@ -4,6 +4,7 @@ import (
4 4
 	"net/http"
5 5
 	"testing"
6 6
 
7
+	"github.com/docker/docker/internal/test/daemon"
7 8
 	req "github.com/docker/docker/internal/test/request"
8 9
 	"gotest.tools/assert"
9 10
 	is "gotest.tools/assert/cmp"
... ...
@@ -11,16 +12,27 @@ import (
11 11
 )
12 12
 
13 13
 func TestSessionCreate(t *testing.T) {
14
-	skip.If(t, !testEnv.DaemonInfo.ExperimentalBuild)
15 14
 	skip.If(t, testEnv.OSType == "windows", "FIXME")
16 15
 
17 16
 	defer setupTest(t)()
17
+	daemonHost := req.DaemonHost()
18
+	if !testEnv.DaemonInfo.ExperimentalBuild {
19
+		skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
18 20
 
19
-	res, body, err := req.Post("/session", req.With(func(r *http.Request) error {
20
-		r.Header.Set("X-Docker-Expose-Session-Uuid", "testsessioncreate") // so we don't block default name if something else is using it
21
-		r.Header.Set("Upgrade", "h2c")
22
-		return nil
23
-	}))
21
+		d := daemon.New(t, daemon.WithExperimental)
22
+		d.StartWithBusybox(t)
23
+		defer d.Stop(t)
24
+		daemonHost = d.Sock()
25
+	}
26
+
27
+	res, body, err := req.Post("/session",
28
+		req.Host(daemonHost),
29
+		req.With(func(r *http.Request) error {
30
+			r.Header.Set("X-Docker-Expose-Session-Uuid", "testsessioncreate") // so we don't block default name if something else is using it
31
+			r.Header.Set("Upgrade", "h2c")
32
+			return nil
33
+		}),
34
+	)
24 35
 	assert.NilError(t, err)
25 36
 	assert.NilError(t, body.Close())
26 37
 	assert.Check(t, is.DeepEqual(res.StatusCode, http.StatusSwitchingProtocols))
... ...
@@ -28,20 +40,33 @@ func TestSessionCreate(t *testing.T) {
28 28
 }
29 29
 
30 30
 func TestSessionCreateWithBadUpgrade(t *testing.T) {
31
-	skip.If(t, !testEnv.DaemonInfo.ExperimentalBuild)
32 31
 	skip.If(t, testEnv.OSType == "windows", "FIXME")
33 32
 
34
-	res, body, err := req.Post("/session")
33
+	defer setupTest(t)()
34
+	daemonHost := req.DaemonHost()
35
+	if !testEnv.DaemonInfo.ExperimentalBuild {
36
+		skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
37
+
38
+		d := daemon.New(t, daemon.WithExperimental)
39
+		d.StartWithBusybox(t)
40
+		defer d.Stop(t)
41
+		daemonHost = d.Sock()
42
+	}
43
+
44
+	res, body, err := req.Post("/session", req.Host(daemonHost))
35 45
 	assert.NilError(t, err)
36 46
 	assert.Check(t, is.DeepEqual(res.StatusCode, http.StatusBadRequest))
37 47
 	buf, err := req.ReadBody(body)
38 48
 	assert.NilError(t, err)
39 49
 	assert.Check(t, is.Contains(string(buf), "no upgrade"))
40 50
 
41
-	res, body, err = req.Post("/session", req.With(func(r *http.Request) error {
42
-		r.Header.Set("Upgrade", "foo")
43
-		return nil
44
-	}))
51
+	res, body, err = req.Post("/session",
52
+		req.Host(daemonHost),
53
+		req.With(func(r *http.Request) error {
54
+			r.Header.Set("Upgrade", "foo")
55
+			return nil
56
+		}),
57
+	)
45 58
 	assert.NilError(t, err)
46 59
 	assert.Check(t, is.DeepEqual(res.StatusCode, http.StatusBadRequest))
47 60
 	buf, err = req.ReadBody(body)
... ...
@@ -88,6 +88,7 @@ func New(t testingT, ops ...func(*Daemon)) *Daemon {
88 88
 	if ht, ok := t.(test.HelperT); ok {
89 89
 		ht.Helper()
90 90
 	}
91
+	t.Log("Creating a new daemon")
91 92
 	dest := os.Getenv("DOCKER_INTEGRATION_DAEMON_DEST")
92 93
 	if dest == "" {
93 94
 		dest = os.Getenv("DEST")