mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
dc0c2340b8
integration-cli/docker_cli_pull_test.go:55:69: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_exec_test.go:46:64: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_service_health_test.go:86:65: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_api_images_test.go:128:66: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_api_swarm_node_test.go:79:69: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_health_test.go:51:57: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_health_test.go:159:73: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_swarm_unix_test.go:60:67: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_api_inspect_test.go:30:33: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_api_build_test.go:429:71: empty-lines: extra empty line at the start of a block (revive) integration-cli/docker_cli_attach_unix_test.go:19:78: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_api_build_test.go:470:70: empty-lines: extra empty line at the start of a block (revive) integration-cli/docker_cli_history_test.go:29:64: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_links_test.go:93:86: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_create_test.go:33:61: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_links_test.go:145:78: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_create_test.go:114:70: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_api_attach_test.go:226:153: empty-lines: extra empty line at the start of a block (revive) integration-cli/docker_cli_by_digest_test.go:239:71: empty-lines: extra empty line at the start of a block (revive) integration-cli/docker_cli_create_test.go:135:49: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_create_test.go:143:75: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_create_test.go:181:71: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_inspect_test.go:72:65: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_api_swarm_service_test.go:98:77: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_api_swarm_service_test.go:144:69: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_rmi_test.go:63:2: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_api_swarm_service_test.go:199:79: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_rmi_test.go:69:2: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_api_swarm_service_test.go:300:75: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_prune_unix_test.go:35:25: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_events_unix_test.go:393:60: empty-lines: extra empty line at the start of a block (revive) integration-cli/docker_cli_events_unix_test.go:441:71: empty-lines: extra empty line at the start of a block (revive) integration-cli/docker_cli_ps_test.go:33:67: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_ps_test.go:559:67: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_events_test.go:117:75: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_api_containers_test.go:547:74: empty-lines: extra empty line at the start of a block (revive) integration-cli/docker_api_containers_test.go:1054:84: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_api_containers_test.go:1076:87: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_api_containers_test.go:1232:72: empty-lines: extra empty line at the start of a block (revive) integration-cli/docker_api_containers_test.go:1801:21: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_network_unix_test.go:58:95: empty-lines: extra empty line at the start of a block (revive) integration-cli/docker_cli_network_unix_test.go:750:75: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_network_unix_test.go:765:76: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_swarm_test.go:617:100: empty-lines: extra empty line at the start of a block (revive) integration-cli/docker_cli_swarm_test.go:892:72: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_daemon_test.go:119:74: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_daemon_test.go:981:68: empty-lines: extra empty line at the start of a block (revive) integration-cli/docker_cli_daemon_test.go:1951:87: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_run_test.go:83:66: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_run_test.go:357:72: empty-lines: extra empty line at the start of a block (revive) integration-cli/docker_cli_build_test.go:89:83: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:114:83: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:183:80: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:290:71: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:314:65: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:331:67: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:366:76: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:403:67: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:648:67: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:708:72: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:938:66: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:1018:72: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:1097:2: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:1182:62: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:1244:66: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:1524:69: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:1546:80: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:1716:70: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:1730:65: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:2162:74: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:2270:71: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:2288:70: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:3206:65: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:3392:66: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:3433:72: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:3678:76: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:3732:67: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:3759:69: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:3802:61: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:3898:66: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:4107:9: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:4791:74: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:4821:73: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:4854:70: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:5341:74: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_cli_build_test.go:5593:81: empty-lines: extra empty line at the end of a block (revive) integration-cli/docker_api_containers_test.go:2145:11: empty-lines: extra empty line at the start of a block (revive) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
473 lines
17 KiB
Go
473 lines
17 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/api/types/container"
|
|
"gotest.tools/v3/assert"
|
|
"gotest.tools/v3/icmd"
|
|
)
|
|
|
|
type DockerCLIInspectSuite struct {
|
|
ds *DockerSuite
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TearDownTest(c *testing.T) {
|
|
s.ds.TearDownTest(c)
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) OnTimeout(c *testing.T) {
|
|
s.ds.OnTimeout(c)
|
|
}
|
|
|
|
func checkValidGraphDriver(c *testing.T, name string) {
|
|
if name != "devicemapper" && name != "overlay" && name != "vfs" && name != "zfs" && name != "btrfs" && name != "aufs" {
|
|
c.Fatalf("%v is not a valid graph driver name", name)
|
|
}
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectImage(c *testing.T) {
|
|
testRequires(c, DaemonIsLinux)
|
|
imageTest := "emptyfs"
|
|
// It is important that this ID remain stable. If a code change causes
|
|
// it to be different, this is equivalent to a cache bust when pulling
|
|
// a legacy-format manifest. If the check at the end of this function
|
|
// fails, fix the difference in the image serialization instead of
|
|
// updating this hash.
|
|
imageTestID := "sha256:11f64303f0f7ffdc71f001788132bca5346831939a956e3e975c93267d89a16d"
|
|
if containerdSnapshotterEnabled() {
|
|
// Under containerd ID of the image is the digest of the manifest list.
|
|
imageTestID = "sha256:e43ca824363c5c56016f6ede3a9035afe0e9bd43333215e0b0bde6193969725d"
|
|
}
|
|
|
|
id := inspectField(c, imageTest, "Id")
|
|
|
|
assert.Equal(c, id, imageTestID)
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectInt64(c *testing.T) {
|
|
dockerCmd(c, "run", "-d", "-m=300M", "--name", "inspectTest", "busybox", "true")
|
|
inspectOut := inspectField(c, "inspectTest", "HostConfig.Memory")
|
|
assert.Equal(c, inspectOut, "314572800")
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectDefault(c *testing.T) {
|
|
// Both the container and image are named busybox. docker inspect will fetch the container JSON.
|
|
// If the container JSON is not available, it will go for the image JSON.
|
|
|
|
out, _ := dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
|
|
containerID := strings.TrimSpace(out)
|
|
|
|
inspectOut := inspectField(c, "busybox", "Id")
|
|
assert.Equal(c, strings.TrimSpace(inspectOut), containerID)
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectStatus(c *testing.T) {
|
|
out := runSleepingContainer(c, "-d")
|
|
out = strings.TrimSpace(out)
|
|
|
|
inspectOut := inspectField(c, out, "State.Status")
|
|
assert.Equal(c, inspectOut, "running")
|
|
|
|
// Windows does not support pause/unpause on Windows Server Containers.
|
|
// (RS1 does for Hyper-V Containers, but production CI is not setup for that)
|
|
if testEnv.OSType != "windows" {
|
|
dockerCmd(c, "pause", out)
|
|
inspectOut = inspectField(c, out, "State.Status")
|
|
assert.Equal(c, inspectOut, "paused")
|
|
|
|
dockerCmd(c, "unpause", out)
|
|
inspectOut = inspectField(c, out, "State.Status")
|
|
assert.Equal(c, inspectOut, "running")
|
|
}
|
|
|
|
dockerCmd(c, "stop", out)
|
|
inspectOut = inspectField(c, out, "State.Status")
|
|
assert.Equal(c, inspectOut, "exited")
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectTypeFlagContainer(c *testing.T) {
|
|
// Both the container and image are named busybox. docker inspect will fetch container
|
|
// JSON State.Running field. If the field is true, it's a container.
|
|
runSleepingContainer(c, "--name=busybox", "-d")
|
|
|
|
formatStr := "--format={{.State.Running}}"
|
|
out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox")
|
|
assert.Equal(c, out, "true\n") // not a container JSON
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectTypeFlagWithNoContainer(c *testing.T) {
|
|
// Run this test on an image named busybox. docker inspect will try to fetch container
|
|
// JSON. Since there is no container named busybox and --type=container, docker inspect will
|
|
// not try to get the image JSON. It will throw an error.
|
|
|
|
dockerCmd(c, "run", "-d", "busybox", "true")
|
|
|
|
_, _, err := dockerCmdWithError("inspect", "--type=container", "busybox")
|
|
// docker inspect should fail, as there is no container named busybox
|
|
assert.ErrorContains(c, err, "")
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectTypeFlagWithImage(c *testing.T) {
|
|
// Both the container and image are named busybox. docker inspect will fetch image
|
|
// JSON as --type=image. if there is no image with name busybox, docker inspect
|
|
// will throw an error.
|
|
|
|
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
|
|
|
|
out, _ := dockerCmd(c, "inspect", "--type=image", "busybox")
|
|
// not an image JSON
|
|
assert.Assert(c, !strings.Contains(out, "State"))
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectTypeFlagWithInvalidValue(c *testing.T) {
|
|
// Both the container and image are named busybox. docker inspect will fail
|
|
// as --type=foobar is not a valid value for the flag.
|
|
|
|
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
|
|
|
|
out, exitCode, err := dockerCmdWithError("inspect", "--type=foobar", "busybox")
|
|
assert.Assert(c, err != nil, "%d", exitCode)
|
|
assert.Equal(c, exitCode, 1, fmt.Sprintf("%s", err))
|
|
assert.Assert(c, strings.Contains(out, "not a valid value for --type"))
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectImageFilterInt(c *testing.T) {
|
|
testRequires(c, DaemonIsLinux)
|
|
imageTest := "emptyfs"
|
|
out := inspectField(c, imageTest, "Size")
|
|
|
|
size, err := strconv.Atoi(out)
|
|
assert.Assert(c, err == nil, "failed to inspect size of the image: %s, %v", out, err)
|
|
|
|
// now see if the size turns out to be the same
|
|
formatStr := fmt.Sprintf("--format={{eq .Size %d}}", size)
|
|
out, _ = dockerCmd(c, "inspect", formatStr, imageTest)
|
|
result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n"))
|
|
assert.NilError(c, err)
|
|
assert.Equal(c, result, true)
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectContainerFilterInt(c *testing.T) {
|
|
result := icmd.RunCmd(icmd.Cmd{
|
|
Command: []string{dockerBinary, "run", "-i", "-a", "stdin", "busybox", "cat"},
|
|
Stdin: strings.NewReader("blahblah"),
|
|
})
|
|
result.Assert(c, icmd.Success)
|
|
out := result.Stdout()
|
|
id := strings.TrimSpace(out)
|
|
|
|
out = inspectField(c, id, "State.ExitCode")
|
|
|
|
exitCode, err := strconv.Atoi(out)
|
|
assert.Assert(c, err == nil, "failed to inspect exitcode of the container: %s, %v", out, err)
|
|
|
|
// now get the exit code to verify
|
|
formatStr := fmt.Sprintf("--format={{eq .State.ExitCode %d}}", exitCode)
|
|
out, _ = dockerCmd(c, "inspect", formatStr, id)
|
|
inspectResult, err := strconv.ParseBool(strings.TrimSuffix(out, "\n"))
|
|
assert.NilError(c, err)
|
|
assert.Equal(c, inspectResult, true)
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectImageGraphDriver(c *testing.T) {
|
|
testRequires(c, DaemonIsLinux, Devicemapper)
|
|
imageTest := "emptyfs"
|
|
name := inspectField(c, imageTest, "GraphDriver.Name")
|
|
|
|
checkValidGraphDriver(c, name)
|
|
|
|
deviceID := inspectField(c, imageTest, "GraphDriver.Data.DeviceId")
|
|
|
|
_, err := strconv.Atoi(deviceID)
|
|
assert.Assert(c, err == nil, "failed to inspect DeviceId of the image: %s, %v", deviceID, err)
|
|
|
|
deviceSize := inspectField(c, imageTest, "GraphDriver.Data.DeviceSize")
|
|
|
|
_, err = strconv.ParseUint(deviceSize, 10, 64)
|
|
assert.Assert(c, err == nil, "failed to inspect DeviceSize of the image: %s, %v", deviceSize, err)
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectContainerGraphDriver(c *testing.T) {
|
|
testRequires(c, DaemonIsLinux, Devicemapper)
|
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
|
out = strings.TrimSpace(out)
|
|
|
|
name := inspectField(c, out, "GraphDriver.Name")
|
|
|
|
checkValidGraphDriver(c, name)
|
|
|
|
imageDeviceID := inspectField(c, "busybox", "GraphDriver.Data.DeviceId")
|
|
|
|
deviceID := inspectField(c, out, "GraphDriver.Data.DeviceId")
|
|
|
|
assert.Assert(c, imageDeviceID != deviceID)
|
|
|
|
_, err := strconv.Atoi(deviceID)
|
|
assert.Assert(c, err == nil, "failed to inspect DeviceId of the image: %s, %v", deviceID, err)
|
|
|
|
deviceSize := inspectField(c, out, "GraphDriver.Data.DeviceSize")
|
|
|
|
_, err = strconv.ParseUint(deviceSize, 10, 64)
|
|
assert.Assert(c, err == nil, "failed to inspect DeviceSize of the image: %s, %v", deviceSize, err)
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectBindMountPoint(c *testing.T) {
|
|
modifier := ",z"
|
|
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
|
if testEnv.OSType == "windows" {
|
|
modifier = ""
|
|
// Linux creates the host directory if it doesn't exist. Windows does not.
|
|
os.Mkdir(`c:\data`, os.ModeDir)
|
|
}
|
|
|
|
dockerCmd(c, "run", "-d", "--name", "test", "-v", prefix+slash+"data:"+prefix+slash+"data:ro"+modifier, "busybox", "cat")
|
|
|
|
vol := inspectFieldJSON(c, "test", "Mounts")
|
|
|
|
var mp []types.MountPoint
|
|
err := json.Unmarshal([]byte(vol), &mp)
|
|
assert.NilError(c, err)
|
|
|
|
// check that there is only one mountpoint
|
|
assert.Equal(c, len(mp), 1)
|
|
|
|
m := mp[0]
|
|
|
|
assert.Equal(c, m.Name, "")
|
|
assert.Equal(c, m.Driver, "")
|
|
assert.Equal(c, m.Source, prefix+slash+"data")
|
|
assert.Equal(c, m.Destination, prefix+slash+"data")
|
|
if testEnv.OSType != "windows" { // Windows does not set mode
|
|
assert.Equal(c, m.Mode, "ro"+modifier)
|
|
}
|
|
assert.Equal(c, m.RW, false)
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectNamedMountPoint(c *testing.T) {
|
|
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
|
|
|
dockerCmd(c, "run", "-d", "--name", "test", "-v", "data:"+prefix+slash+"data", "busybox", "cat")
|
|
|
|
vol := inspectFieldJSON(c, "test", "Mounts")
|
|
|
|
var mp []types.MountPoint
|
|
err := json.Unmarshal([]byte(vol), &mp)
|
|
assert.NilError(c, err)
|
|
|
|
// check that there is only one mountpoint
|
|
assert.Equal(c, len(mp), 1)
|
|
|
|
m := mp[0]
|
|
|
|
assert.Equal(c, m.Name, "data")
|
|
assert.Equal(c, m.Driver, "local")
|
|
assert.Assert(c, m.Source != "")
|
|
assert.Equal(c, m.Destination, prefix+slash+"data")
|
|
assert.Equal(c, m.RW, true)
|
|
}
|
|
|
|
// #14947
|
|
func (s *DockerCLIInspectSuite) TestInspectTimesAsRFC3339Nano(c *testing.T) {
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
|
id := strings.TrimSpace(out)
|
|
startedAt := inspectField(c, id, "State.StartedAt")
|
|
finishedAt := inspectField(c, id, "State.FinishedAt")
|
|
created := inspectField(c, id, "Created")
|
|
|
|
_, err := time.Parse(time.RFC3339Nano, startedAt)
|
|
assert.NilError(c, err)
|
|
_, err = time.Parse(time.RFC3339Nano, finishedAt)
|
|
assert.NilError(c, err)
|
|
_, err = time.Parse(time.RFC3339Nano, created)
|
|
assert.NilError(c, err)
|
|
|
|
created = inspectField(c, "busybox", "Created")
|
|
|
|
_, err = time.Parse(time.RFC3339Nano, created)
|
|
assert.NilError(c, err)
|
|
}
|
|
|
|
// #15633
|
|
func (s *DockerCLIInspectSuite) TestInspectLogConfigNoType(c *testing.T) {
|
|
dockerCmd(c, "create", "--name=test", "--log-opt", "max-file=42", "busybox")
|
|
var logConfig container.LogConfig
|
|
|
|
out := inspectFieldJSON(c, "test", "HostConfig.LogConfig")
|
|
|
|
err := json.NewDecoder(strings.NewReader(out)).Decode(&logConfig)
|
|
assert.Assert(c, err == nil, "%v", out)
|
|
|
|
assert.Equal(c, logConfig.Type, "json-file")
|
|
assert.Equal(c, logConfig.Config["max-file"], "42", fmt.Sprintf("%v", logConfig))
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectNoSizeFlagContainer(c *testing.T) {
|
|
// Both the container and image are named busybox. docker inspect will fetch container
|
|
// JSON SizeRw and SizeRootFs field. If there is no flag --size/-s, there are no size fields.
|
|
|
|
runSleepingContainer(c, "--name=busybox", "-d")
|
|
|
|
formatStr := "--format={{.SizeRw}},{{.SizeRootFs}}"
|
|
out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox")
|
|
assert.Equal(c, strings.TrimSpace(out), "<nil>,<nil>", fmt.Sprintf("Expected not to display size info: %s", out))
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectSizeFlagContainer(c *testing.T) {
|
|
runSleepingContainer(c, "--name=busybox", "-d")
|
|
|
|
formatStr := "--format='{{.SizeRw}},{{.SizeRootFs}}'"
|
|
out, _ := dockerCmd(c, "inspect", "-s", "--type=container", formatStr, "busybox")
|
|
sz := strings.Split(out, ",")
|
|
|
|
assert.Assert(c, strings.TrimSpace(sz[0]) != "<nil>")
|
|
assert.Assert(c, strings.TrimSpace(sz[1]) != "<nil>")
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectTemplateError(c *testing.T) {
|
|
// Template parsing error for both the container and image.
|
|
|
|
runSleepingContainer(c, "--name=container1", "-d")
|
|
|
|
out, _, err := dockerCmdWithError("inspect", "--type=container", "--format='Format container: {{.ThisDoesNotExist}}'", "container1")
|
|
assert.Assert(c, err != nil)
|
|
assert.Assert(c, strings.Contains(out, "Template parsing error"))
|
|
out, _, err = dockerCmdWithError("inspect", "--type=image", "--format='Format container: {{.ThisDoesNotExist}}'", "busybox")
|
|
assert.Assert(c, err != nil)
|
|
assert.Assert(c, strings.Contains(out, "Template parsing error"))
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectJSONFields(c *testing.T) {
|
|
runSleepingContainer(c, "--name=busybox", "-d")
|
|
out, _, err := dockerCmdWithError("inspect", "--type=container", "--format={{.HostConfig.Dns}}", "busybox")
|
|
|
|
assert.NilError(c, err)
|
|
assert.Equal(c, out, "[]\n")
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectByPrefix(c *testing.T) {
|
|
id := inspectField(c, "busybox", "Id")
|
|
assert.Assert(c, strings.HasPrefix(id, "sha256:"))
|
|
|
|
id2 := inspectField(c, id[:12], "Id")
|
|
assert.Equal(c, id, id2)
|
|
|
|
id3 := inspectField(c, strings.TrimPrefix(id, "sha256:")[:12], "Id")
|
|
assert.Equal(c, id, id3)
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectStopWhenNotFound(c *testing.T) {
|
|
runSleepingContainer(c, "--name=busybox1", "-d")
|
|
runSleepingContainer(c, "--name=busybox2", "-d")
|
|
result := dockerCmdWithResult("inspect", "--type=container", "--format='{{.Name}}'", "busybox1", "busybox2", "missing")
|
|
|
|
assert.Assert(c, result.Error != nil)
|
|
assert.Assert(c, strings.Contains(result.Stdout(), "busybox1"))
|
|
assert.Assert(c, strings.Contains(result.Stdout(), "busybox2"))
|
|
assert.Assert(c, strings.Contains(result.Stderr(), "Error: No such container: missing"))
|
|
// test inspect would not fast fail
|
|
result = dockerCmdWithResult("inspect", "--type=container", "--format='{{.Name}}'", "missing", "busybox1", "busybox2")
|
|
|
|
assert.Assert(c, result.Error != nil)
|
|
assert.Assert(c, strings.Contains(result.Stdout(), "busybox1"))
|
|
assert.Assert(c, strings.Contains(result.Stdout(), "busybox2"))
|
|
assert.Assert(c, strings.Contains(result.Stderr(), "Error: No such container: missing"))
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectHistory(c *testing.T) {
|
|
dockerCmd(c, "run", "--name=testcont", "busybox", "echo", "hello")
|
|
dockerCmd(c, "commit", "-m", "test comment", "testcont", "testimg")
|
|
out, _, err := dockerCmdWithError("inspect", "--format='{{.Comment}}'", "testimg")
|
|
assert.NilError(c, err)
|
|
assert.Assert(c, strings.Contains(out, "test comment"))
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectContainerNetworkDefault(c *testing.T) {
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
contName := "test1"
|
|
dockerCmd(c, "run", "--name", contName, "-d", "busybox", "top")
|
|
netOut, _ := dockerCmd(c, "network", "inspect", "--format={{.ID}}", "bridge")
|
|
out := inspectField(c, contName, "NetworkSettings.Networks")
|
|
assert.Assert(c, strings.Contains(out, "bridge"))
|
|
out = inspectField(c, contName, "NetworkSettings.Networks.bridge.NetworkID")
|
|
assert.Equal(c, strings.TrimSpace(out), strings.TrimSpace(netOut))
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectContainerNetworkCustom(c *testing.T) {
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
netOut, _ := dockerCmd(c, "network", "create", "net1")
|
|
dockerCmd(c, "run", "--name=container1", "--net=net1", "-d", "busybox", "top")
|
|
out := inspectField(c, "container1", "NetworkSettings.Networks")
|
|
assert.Assert(c, strings.Contains(out, "net1"))
|
|
out = inspectField(c, "container1", "NetworkSettings.Networks.net1.NetworkID")
|
|
assert.Equal(c, strings.TrimSpace(out), strings.TrimSpace(netOut))
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectRootFS(c *testing.T) {
|
|
out, _, err := dockerCmdWithError("inspect", "busybox")
|
|
assert.NilError(c, err)
|
|
|
|
var imageJSON []types.ImageInspect
|
|
err = json.Unmarshal([]byte(out), &imageJSON)
|
|
assert.NilError(c, err)
|
|
assert.Assert(c, len(imageJSON[0].RootFS.Layers) >= 1)
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectAmpersand(c *testing.T) {
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
name := "test"
|
|
out, _ := dockerCmd(c, "run", "--name", name, "--env", `TEST_ENV="soanni&rtr"`, "busybox", "env")
|
|
assert.Assert(c, strings.Contains(out, `soanni&rtr`))
|
|
out, _ = dockerCmd(c, "inspect", name)
|
|
assert.Assert(c, strings.Contains(out, `soanni&rtr`))
|
|
}
|
|
|
|
func (s *DockerCLIInspectSuite) TestInspectPlugin(c *testing.T) {
|
|
testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
|
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
|
|
assert.NilError(c, err)
|
|
|
|
out, _, err := dockerCmdWithError("inspect", "--type", "plugin", "--format", "{{.Name}}", pNameWithTag)
|
|
assert.NilError(c, err)
|
|
assert.Equal(c, strings.TrimSpace(out), pNameWithTag)
|
|
|
|
out, _, err = dockerCmdWithError("inspect", "--format", "{{.Name}}", pNameWithTag)
|
|
assert.NilError(c, err)
|
|
assert.Equal(c, strings.TrimSpace(out), pNameWithTag)
|
|
|
|
// Even without tag the inspect still work
|
|
out, _, err = dockerCmdWithError("inspect", "--type", "plugin", "--format", "{{.Name}}", pNameWithTag)
|
|
assert.NilError(c, err)
|
|
assert.Equal(c, strings.TrimSpace(out), pNameWithTag)
|
|
|
|
out, _, err = dockerCmdWithError("inspect", "--format", "{{.Name}}", pNameWithTag)
|
|
assert.NilError(c, err)
|
|
assert.Equal(c, strings.TrimSpace(out), pNameWithTag)
|
|
|
|
_, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag)
|
|
assert.NilError(c, err)
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
|
|
assert.NilError(c, err)
|
|
assert.Assert(c, strings.Contains(out, pNameWithTag))
|
|
}
|
|
|
|
// Test case for 29185
|
|
func (s *DockerCLIInspectSuite) TestInspectUnknownObject(c *testing.T) {
|
|
// This test should work on both Windows and Linux
|
|
out, _, err := dockerCmdWithError("inspect", "foobar")
|
|
assert.ErrorContains(c, err, "")
|
|
assert.Assert(c, strings.Contains(out, "Error: No such object: foobar"))
|
|
assert.ErrorContains(c, err, "Error: No such object: foobar")
|
|
}
|