inspect_test.go 1.5 KB

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