mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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>
This commit is contained in:
parent
cbb885b07a
commit
b3407d2029
4 changed files with 61 additions and 23 deletions
|
@ -21,13 +21,19 @@ import (
|
|||
)
|
||||
|
||||
func TestBuildWithSession(t *testing.T) {
|
||||
skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
|
||||
skip.If(t, testEnv.DaemonInfo.OSType == "windows")
|
||||
|
||||
var client dclient.APIClient
|
||||
if !testEnv.DaemonInfo.ExperimentalBuild {
|
||||
skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
|
||||
|
||||
d := daemon.New(t, daemon.WithExperimental)
|
||||
d.StartWithBusybox(t)
|
||||
defer d.Stop(t)
|
||||
|
||||
client := d.NewClientT(t)
|
||||
client = d.NewClientT(t)
|
||||
} else {
|
||||
client = testEnv.APIClient()
|
||||
}
|
||||
|
||||
dockerfile := `
|
||||
FROM busybox
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
dclient "github.com/docker/docker/client"
|
||||
"github.com/docker/docker/integration/internal/container"
|
||||
"github.com/docker/docker/internal/test/daemon"
|
||||
"github.com/docker/docker/internal/test/fakecontext"
|
||||
|
@ -20,13 +21,18 @@ import (
|
|||
|
||||
func TestBuildSquashParent(t *testing.T) {
|
||||
skip.If(t, testEnv.DaemonInfo.OSType == "windows")
|
||||
skip.If(t, !testEnv.DaemonInfo.ExperimentalBuild)
|
||||
|
||||
var client dclient.APIClient
|
||||
if !testEnv.DaemonInfo.ExperimentalBuild {
|
||||
skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
|
||||
|
||||
d := daemon.New(t, daemon.WithExperimental)
|
||||
d.StartWithBusybox(t)
|
||||
defer d.Stop(t)
|
||||
|
||||
client := d.NewClientT(t)
|
||||
client = d.NewClientT(t)
|
||||
} else {
|
||||
client = testEnv.APIClient()
|
||||
}
|
||||
|
||||
dockerfile := `
|
||||
FROM busybox
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/internal/test/daemon"
|
||||
req "github.com/docker/docker/internal/test/request"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
|
@ -11,16 +12,27 @@ import (
|
|||
)
|
||||
|
||||
func TestSessionCreate(t *testing.T) {
|
||||
skip.If(t, !testEnv.DaemonInfo.ExperimentalBuild)
|
||||
skip.If(t, testEnv.OSType == "windows", "FIXME")
|
||||
|
||||
defer setupTest(t)()
|
||||
daemonHost := req.DaemonHost()
|
||||
if !testEnv.DaemonInfo.ExperimentalBuild {
|
||||
skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
|
||||
|
||||
res, body, err := req.Post("/session", req.With(func(r *http.Request) error {
|
||||
d := daemon.New(t, daemon.WithExperimental)
|
||||
d.StartWithBusybox(t)
|
||||
defer d.Stop(t)
|
||||
daemonHost = d.Sock()
|
||||
}
|
||||
|
||||
res, body, err := req.Post("/session",
|
||||
req.Host(daemonHost),
|
||||
req.With(func(r *http.Request) error {
|
||||
r.Header.Set("X-Docker-Expose-Session-Uuid", "testsessioncreate") // so we don't block default name if something else is using it
|
||||
r.Header.Set("Upgrade", "h2c")
|
||||
return nil
|
||||
}))
|
||||
}),
|
||||
)
|
||||
assert.NilError(t, err)
|
||||
assert.NilError(t, body.Close())
|
||||
assert.Check(t, is.DeepEqual(res.StatusCode, http.StatusSwitchingProtocols))
|
||||
|
@ -28,20 +40,33 @@ func TestSessionCreate(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSessionCreateWithBadUpgrade(t *testing.T) {
|
||||
skip.If(t, !testEnv.DaemonInfo.ExperimentalBuild)
|
||||
skip.If(t, testEnv.OSType == "windows", "FIXME")
|
||||
|
||||
res, body, err := req.Post("/session")
|
||||
defer setupTest(t)()
|
||||
daemonHost := req.DaemonHost()
|
||||
if !testEnv.DaemonInfo.ExperimentalBuild {
|
||||
skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
|
||||
|
||||
d := daemon.New(t, daemon.WithExperimental)
|
||||
d.StartWithBusybox(t)
|
||||
defer d.Stop(t)
|
||||
daemonHost = d.Sock()
|
||||
}
|
||||
|
||||
res, body, err := req.Post("/session", req.Host(daemonHost))
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.DeepEqual(res.StatusCode, http.StatusBadRequest))
|
||||
buf, err := req.ReadBody(body)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Contains(string(buf), "no upgrade"))
|
||||
|
||||
res, body, err = req.Post("/session", req.With(func(r *http.Request) error {
|
||||
res, body, err = req.Post("/session",
|
||||
req.Host(daemonHost),
|
||||
req.With(func(r *http.Request) error {
|
||||
r.Header.Set("Upgrade", "foo")
|
||||
return nil
|
||||
}))
|
||||
}),
|
||||
)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.DeepEqual(res.StatusCode, http.StatusBadRequest))
|
||||
buf, err = req.ReadBody(body)
|
||||
|
|
|
@ -88,6 +88,7 @@ func New(t testingT, ops ...func(*Daemon)) *Daemon {
|
|||
if ht, ok := t.(test.HelperT); ok {
|
||||
ht.Helper()
|
||||
}
|
||||
t.Log("Creating a new daemon")
|
||||
dest := os.Getenv("DOCKER_INTEGRATION_DAEMON_DEST")
|
||||
if dest == "" {
|
||||
dest = os.Getenv("DEST")
|
||||
|
|
Loading…
Add table
Reference in a new issue