inspect_test.go 1.5 KB

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