Migrate docker_api_inspect_unix_test.go to integration api test

This fix migrates docker_api_inspect_unix_test.go to integration api test

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang 2018-02-09 02:35:51 +00:00
parent 7e7f8160fc
commit 8197529ca2
2 changed files with 47 additions and 36 deletions

View file

@ -1,36 +0,0 @@
// +build !windows
package main
import (
"encoding/json"
"github.com/docker/docker/client"
"github.com/docker/docker/integration-cli/checker"
"github.com/go-check/check"
"golang.org/x/net/context"
)
// #16665
func (s *DockerSuite) TestInspectAPICpusetInConfigPre120(c *check.C) {
testRequires(c, DaemonIsLinux)
testRequires(c, cgroupCpuset)
name := "cpusetinconfig-pre120"
dockerCmd(c, "run", "--name", name, "--cpuset-cpus", "0", "busybox", "true")
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion("v1.19"))
c.Assert(err, checker.IsNil)
defer cli.Close()
_, body, err := cli.ContainerInspectWithRaw(context.Background(), name, false)
c.Assert(err, check.IsNil)
var inspectJSON map[string]interface{}
err = json.Unmarshal(body, &inspectJSON)
c.Assert(err, checker.IsNil, check.Commentf("unable to unmarshal body for version 1.19"))
config, ok := inspectJSON["Config"]
c.Assert(ok, checker.True, check.Commentf("Unable to find 'Config'"))
cfg := config.(map[string]interface{})
_, ok = cfg["Cpuset"]
c.Assert(ok, checker.True, check.Commentf("API version 1.19 expected to include Cpuset in 'Config'"))
}

View file

@ -0,0 +1,47 @@
package container // import "github.com/docker/docker/integration/container"
import (
"context"
"encoding/json"
"testing"
"time"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/client"
"github.com/docker/docker/integration/util/request"
"github.com/gotestyourself/gotestyourself/poll"
"github.com/gotestyourself/gotestyourself/skip"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestInspectCpusetInConfigPre120(t *testing.T) {
skip.If(t, testEnv.DaemonInfo.OSType != "linux" || !testEnv.DaemonInfo.CPUSet)
defer setupTest(t)()
client := request.NewAPIClient(t, client.WithVersion("1.19"))
ctx := context.Background()
name := "cpusetinconfig-pre120"
// Create container with up to-date-API
runSimpleContainer(ctx, t, request.NewAPIClient(t), name, func(config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig) {
config.Cmd = []string{"true"}
hostConfig.Resources.CpusetCpus = "0"
})
poll.WaitOn(t, containerIsInState(ctx, client, name, "exited"), poll.WithDelay(100*time.Millisecond))
_, body, err := client.ContainerInspectWithRaw(ctx, name, false)
require.NoError(t, err)
var inspectJSON map[string]interface{}
err = json.Unmarshal(body, &inspectJSON)
require.NoError(t, err, "unable to unmarshal body for version 1.19: %s", err)
config, ok := inspectJSON["Config"]
assert.Equal(t, ok, true, "Unable to find 'Config'")
cfg := config.(map[string]interface{})
_, ok = cfg["Cpuset"]
assert.Equal(t, ok, true, "API version 1.19 expected to include Cpuset in 'Config'")
}