1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Migrates docker info tests to integration api tests

This fix migrates docker info tests in integration-cli
to integration tests.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang 2018-02-07 18:23:31 +00:00
parent 2e8ccbb49e
commit 68d9beedbe
3 changed files with 60 additions and 62 deletions

View file

@ -1,61 +0,0 @@
package main
import (
"net/http"
"fmt"
"github.com/docker/docker/client"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/request"
"github.com/go-check/check"
"golang.org/x/net/context"
)
func (s *DockerSuite) TestInfoAPI(c *check.C) {
cli, err := client.NewEnvClient()
c.Assert(err, checker.IsNil)
defer cli.Close()
info, err := cli.Info(context.Background())
c.Assert(err, checker.IsNil)
// always shown fields
stringsToCheck := []string{
"ID",
"Containers",
"ContainersRunning",
"ContainersPaused",
"ContainersStopped",
"Images",
"LoggingDriver",
"OperatingSystem",
"NCPU",
"OSType",
"Architecture",
"MemTotal",
"KernelVersion",
"Driver",
"ServerVersion",
"SecurityOptions"}
out := fmt.Sprintf("%+v", info)
for _, linePrefix := range stringsToCheck {
c.Assert(out, checker.Contains, linePrefix)
}
}
func (s *DockerSuite) TestInfoAPIVersioned(c *check.C) {
testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later
res, body, err := request.Get("/v1.20/info")
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
c.Assert(err, checker.IsNil)
b, err := request.ReadBody(body)
c.Assert(err, checker.IsNil)
out := string(b)
c.Assert(out, checker.Contains, "ExecutionDriver")
c.Assert(out, checker.Contains, "not supported")
}

View file

@ -3,15 +3,17 @@
package system
import (
"net/http"
"testing"
req "github.com/docker/docker/integration-cli/request"
"github.com/docker/docker/integration/util/request"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/net/context"
)
func TestInfo_BinaryCommits(t *testing.T) {
func TestInfoBinaryCommits(t *testing.T) {
client := request.NewAPIClient(t)
info, err := client.Info(context.Background())
@ -32,3 +34,18 @@ func TestInfo_BinaryCommits(t *testing.T) {
assert.Equal(t, testEnv.DaemonInfo.RuncCommit.Expected, info.RuncCommit.Expected)
assert.Equal(t, info.RuncCommit.Expected, info.RuncCommit.ID)
}
func TestInfoAPIVersioned(t *testing.T) {
// Windows only supports 1.25 or later
res, body, err := req.Get("/v1.20/info")
require.NoError(t, err)
assert.Equal(t, res.StatusCode, http.StatusOK)
b, err := req.ReadBody(body)
require.NoError(t, err)
out := string(b)
assert.Contains(t, out, "ExecutionDriver")
assert.Contains(t, out, "not supported")
}

View file

@ -0,0 +1,42 @@
package system
import (
"fmt"
"testing"
"github.com/docker/docker/integration/util/request"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/net/context"
)
func TestInfoAPI(t *testing.T) {
client := request.NewAPIClient(t)
info, err := client.Info(context.Background())
require.NoError(t, err)
// always shown fields
stringsToCheck := []string{
"ID",
"Containers",
"ContainersRunning",
"ContainersPaused",
"ContainersStopped",
"Images",
"LoggingDriver",
"OperatingSystem",
"NCPU",
"OSType",
"Architecture",
"MemTotal",
"KernelVersion",
"Driver",
"ServerVersion",
"SecurityOptions"}
out := fmt.Sprintf("%+v", info)
for _, linePrefix := range stringsToCheck {
assert.Contains(t, out, linePrefix)
}
}