github.com/rish1988/moby@v25.0.2+incompatible/integration/container/inspect_test.go (about) 1 package container // import "github.com/docker/docker/integration/container" 2 3 import ( 4 "encoding/json" 5 "runtime" 6 "strings" 7 "testing" 8 "time" 9 10 containertypes "github.com/docker/docker/api/types/container" 11 "github.com/docker/docker/client" 12 "github.com/docker/docker/integration/internal/container" 13 "github.com/docker/docker/testutil/request" 14 "gotest.tools/v3/assert" 15 is "gotest.tools/v3/assert/cmp" 16 "gotest.tools/v3/poll" 17 "gotest.tools/v3/skip" 18 ) 19 20 func TestInspectCpusetInConfigPre120(t *testing.T) { 21 skip.If(t, testEnv.DaemonInfo.OSType == "windows" || !testEnv.DaemonInfo.CPUSet) 22 23 ctx := setupTest(t) 24 apiClient := request.NewAPIClient(t, client.WithVersion("1.19")) 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, apiClient, name, "exited"), poll.WithDelay(100*time.Millisecond)) 35 36 _, body, err := apiClient.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 } 50 51 func TestInspectAnnotations(t *testing.T) { 52 ctx := setupTest(t) 53 apiClient := request.NewAPIClient(t) 54 55 annotations := map[string]string{ 56 "hello": "world", 57 "foo": "bar", 58 } 59 60 name := strings.ToLower(t.Name()) 61 id := container.Create(ctx, t, apiClient, 62 container.WithName(name), 63 container.WithCmd("true"), 64 func(c *container.TestContainerConfig) { 65 c.HostConfig.Annotations = annotations 66 }, 67 ) 68 69 inspect, err := apiClient.ContainerInspect(ctx, id) 70 assert.NilError(t, err) 71 assert.Check(t, is.DeepEqual(inspect.HostConfig.Annotations, annotations)) 72 } 73 74 // TestNetworkAliasesAreEmpty verifies that network-scoped aliases are not set 75 // for non-custom networks (network-scoped aliases are only supported for 76 // custom networks, except for the "Default Switch" network on Windows). 77 func TestNetworkAliasesAreEmpty(t *testing.T) { 78 ctx := setupTest(t) 79 apiClient := request.NewAPIClient(t) 80 81 netModes := []string{"host", "bridge", "none"} 82 if runtime.GOOS == "windows" { 83 netModes = []string{"nat", "none"} 84 } 85 86 for _, nwMode := range netModes { 87 t.Run(nwMode, func(t *testing.T) { 88 ctr := container.Create(ctx, t, apiClient, 89 container.WithName("ctr-"+nwMode), 90 container.WithImage("busybox:latest"), 91 container.WithNetworkMode(nwMode)) 92 defer apiClient.ContainerRemove(ctx, ctr, containertypes.RemoveOptions{ 93 Force: true, 94 }) 95 96 inspect := container.Inspect(ctx, t, apiClient, ctr) 97 netAliases := inspect.NetworkSettings.Networks[nwMode].Aliases 98 99 assert.Check(t, is.Nil(netAliases)) 100 }) 101 } 102 }