moby/integration/container/inspect_test.go
Sebastiaan van Stijn f0dd554e3c
api: remove code for ContainerInspect on api < v1.20
API v1.23 and older are deprecated, so we can remove the code to adjust
responses for API v1.19 and lower.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-02-06 18:44:43 +01:00

66 lines
1.8 KiB
Go

package container // import "github.com/docker/docker/integration/container"
import (
"runtime"
"strings"
"testing"
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/testutil/request"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
func TestInspectAnnotations(t *testing.T) {
ctx := setupTest(t)
apiClient := request.NewAPIClient(t)
annotations := map[string]string{
"hello": "world",
"foo": "bar",
}
name := strings.ToLower(t.Name())
id := container.Create(ctx, t, apiClient,
container.WithName(name),
container.WithCmd("true"),
func(c *container.TestContainerConfig) {
c.HostConfig.Annotations = annotations
},
)
inspect, err := apiClient.ContainerInspect(ctx, id)
assert.NilError(t, err)
assert.Check(t, is.DeepEqual(inspect.HostConfig.Annotations, annotations))
}
// TestNetworkAliasesAreEmpty verifies that network-scoped aliases are not set
// for non-custom networks (network-scoped aliases are only supported for
// custom networks, except for the "Default Switch" network on Windows).
func TestNetworkAliasesAreEmpty(t *testing.T) {
ctx := setupTest(t)
apiClient := request.NewAPIClient(t)
netModes := []string{"host", "bridge", "none"}
if runtime.GOOS == "windows" {
netModes = []string{"nat", "none"}
}
for _, nwMode := range netModes {
t.Run(nwMode, func(t *testing.T) {
ctr := container.Create(ctx, t, apiClient,
container.WithName("ctr-"+nwMode),
container.WithImage("busybox:latest"),
container.WithNetworkMode(nwMode))
defer apiClient.ContainerRemove(ctx, ctr, containertypes.RemoveOptions{
Force: true,
})
inspect := container.Inspect(ctx, t, apiClient, ctr)
netAliases := inspect.NetworkSettings.Networks[nwMode].Aliases
assert.Check(t, is.Nil(netAliases))
})
}
}