github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/integration/container/inspect_test.go (about)

     1  package container // import "github.com/demonoid81/moby/integration/container"
     2  
     3  import (
     4  	"context"
     5  	"encoding/json"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/demonoid81/moby/client"
    10  	"github.com/demonoid81/moby/integration/internal/container"
    11  	"github.com/demonoid81/moby/testutil/request"
    12  	"gotest.tools/v3/assert"
    13  	is "gotest.tools/v3/assert/cmp"
    14  	"gotest.tools/v3/poll"
    15  	"gotest.tools/v3/skip"
    16  )
    17  
    18  func TestInspectCpusetInConfigPre120(t *testing.T) {
    19  	skip.If(t, testEnv.DaemonInfo.OSType == "windows" || !testEnv.DaemonInfo.CPUSet)
    20  
    21  	defer setupTest(t)()
    22  	client := request.NewAPIClient(t, client.WithVersion("1.19"))
    23  	ctx := context.Background()
    24  
    25  	name := "cpusetinconfig-pre120-" + t.Name()
    26  	// Create container with up to-date-API
    27  	container.Run(ctx, t, request.NewAPIClient(t), container.WithName(name),
    28  		container.WithCmd("true"),
    29  		func(c *container.TestContainerConfig) {
    30  			c.HostConfig.Resources.CpusetCpus = "0"
    31  		},
    32  	)
    33  	poll.WaitOn(t, container.IsInState(ctx, client, name, "exited"), poll.WithDelay(100*time.Millisecond))
    34  
    35  	_, body, err := client.ContainerInspectWithRaw(ctx, name, false)
    36  	assert.NilError(t, err)
    37  
    38  	var inspectJSON map[string]interface{}
    39  	err = json.Unmarshal(body, &inspectJSON)
    40  	assert.NilError(t, err, "unable to unmarshal body for version 1.19: %s", err)
    41  
    42  	config, ok := inspectJSON["Config"]
    43  	assert.Check(t, is.Equal(true, ok), "Unable to find 'Config'")
    44  
    45  	cfg := config.(map[string]interface{})
    46  	_, ok = cfg["Cpuset"]
    47  	assert.Check(t, is.Equal(true, ok), "API version 1.19 expected to include Cpuset in 'Config'")
    48  }