Migrates session tests in integration-cli to api tests
This fix migrates session tests in integration-cli to api tests in integration. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
178ebca0b9
commit
1d40c6a899
3 changed files with 81 additions and 48 deletions
|
@ -1,48 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/request"
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestSessionCreate(c *check.C) {
|
||||
testRequires(c, ExperimentalDaemon)
|
||||
|
||||
res, body, err := request.Post("/session", 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
|
||||
})
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(res.StatusCode, checker.Equals, http.StatusSwitchingProtocols)
|
||||
c.Assert(res.Header.Get("Upgrade"), checker.Equals, "h2c")
|
||||
c.Assert(body.Close(), checker.IsNil)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestSessionCreateWithBadUpgrade(c *check.C) {
|
||||
testRequires(c, ExperimentalDaemon)
|
||||
|
||||
res, body, err := request.Post("/session")
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
|
||||
buf, err := request.ReadBody(body)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
out := string(buf)
|
||||
c.Assert(out, checker.Contains, "no upgrade")
|
||||
|
||||
res, body, err = request.Post("/session", func(r *http.Request) error {
|
||||
r.Header.Set("Upgrade", "foo")
|
||||
return nil
|
||||
})
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(res.StatusCode, checker.Equals, http.StatusBadRequest)
|
||||
buf, err = request.ReadBody(body)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
out = string(buf)
|
||||
c.Assert(out, checker.Contains, "not supported")
|
||||
}
|
33
integration/session/main_test.go
Normal file
33
integration/session/main_test.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package session // import "github.com/docker/docker/integration/session"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/internal/test/environment"
|
||||
)
|
||||
|
||||
var testEnv *environment.Execution
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
var err error
|
||||
testEnv, err = environment.New()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
err = environment.EnsureFrozenImagesLinux(testEnv)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
testEnv.Print()
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func setupTest(t *testing.T) func() {
|
||||
environment.ProtectAll(t, testEnv)
|
||||
return func() { testEnv.Clean(t) }
|
||||
}
|
48
integration/session/session_test.go
Normal file
48
integration/session/session_test.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package session // import "github.com/docker/docker/integration/session"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
req "github.com/docker/docker/integration-cli/request"
|
||||
"github.com/gotestyourself/gotestyourself/skip"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSessionCreate(t *testing.T) {
|
||||
skip.If(t, !testEnv.DaemonInfo.ExperimentalBuild)
|
||||
|
||||
defer setupTest(t)()
|
||||
|
||||
res, body, err := req.Post("/session", 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
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, body.Close())
|
||||
assert.Equal(t, res.StatusCode, http.StatusSwitchingProtocols)
|
||||
assert.Equal(t, res.Header.Get("Upgrade"), "h2c")
|
||||
}
|
||||
|
||||
func TestSessionCreateWithBadUpgrade(t *testing.T) {
|
||||
skip.If(t, !testEnv.DaemonInfo.ExperimentalBuild)
|
||||
|
||||
res, body, err := req.Post("/session")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, res.StatusCode, http.StatusBadRequest)
|
||||
buf, err := req.ReadBody(body)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, string(buf), "no upgrade")
|
||||
|
||||
res, body, err = req.Post("/session", func(r *http.Request) error {
|
||||
r.Header.Set("Upgrade", "foo")
|
||||
return nil
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, res.StatusCode, http.StatusBadRequest)
|
||||
buf, err = req.ReadBody(body)
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, string(buf), "not supported")
|
||||
}
|
Loading…
Reference in a new issue