github.com/lacework-dev/go-moby@v20.10.12+incompatible/integration/container/inspect_test.go (about)

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