github.com/guilhermebr/docker@v1.4.2-0.20150428121140-67da055cebca/integration-cli/docker_cli_inspect_test.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os/exec" 6 "strconv" 7 "strings" 8 9 "github.com/go-check/check" 10 ) 11 12 func (s *DockerSuite) TestInspectImage(c *check.C) { 13 imageTest := "emptyfs" 14 imageTestID := "511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158" 15 imagesCmd := exec.Command(dockerBinary, "inspect", "--format='{{.Id}}'", imageTest) 16 out, exitCode, err := runCommandWithOutput(imagesCmd) 17 if exitCode != 0 || err != nil { 18 c.Fatalf("failed to inspect image: %s, %v", out, err) 19 } 20 21 if id := strings.TrimSuffix(out, "\n"); id != imageTestID { 22 c.Fatalf("Expected id: %s for image: %s but received id: %s", imageTestID, imageTest, id) 23 } 24 25 } 26 27 func (s *DockerSuite) TestInspectInt64(c *check.C) { 28 runCmd := exec.Command(dockerBinary, "run", "-d", "-m=300M", "busybox", "true") 29 out, _, _, err := runCommandWithStdoutStderr(runCmd) 30 if err != nil { 31 c.Fatalf("failed to run container: %v, output: %q", err, out) 32 } 33 34 out = strings.TrimSpace(out) 35 36 inspectCmd := exec.Command(dockerBinary, "inspect", "-f", "{{.HostConfig.Memory}}", out) 37 inspectOut, _, err := runCommandWithOutput(inspectCmd) 38 if err != nil { 39 c.Fatalf("failed to inspect container: %v, output: %q", err, inspectOut) 40 } 41 42 if strings.TrimSpace(inspectOut) != "314572800" { 43 c.Fatalf("inspect got wrong value, got: %q, expected: 314572800", inspectOut) 44 } 45 } 46 47 func (s *DockerSuite) TestInspectImageFilterInt(c *check.C) { 48 imageTest := "emptyfs" 49 imagesCmd := exec.Command(dockerBinary, "inspect", "--format='{{.Size}}'", imageTest) 50 out, exitCode, err := runCommandWithOutput(imagesCmd) 51 if exitCode != 0 || err != nil { 52 c.Fatalf("failed to inspect image: %s, %v", out, err) 53 } 54 size, err := strconv.Atoi(strings.TrimSuffix(out, "\n")) 55 if err != nil { 56 c.Fatalf("failed to inspect size of the image: %s, %v", out, err) 57 } 58 59 //now see if the size turns out to be the same 60 formatStr := fmt.Sprintf("--format='{{eq .Size %d}}'", size) 61 imagesCmd = exec.Command(dockerBinary, "inspect", formatStr, imageTest) 62 out, exitCode, err = runCommandWithOutput(imagesCmd) 63 if exitCode != 0 || err != nil { 64 c.Fatalf("failed to inspect image: %s, %v", out, err) 65 } 66 if result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n")); err != nil || !result { 67 c.Fatalf("Expected size: %d for image: %s but received size: %s", size, imageTest, strings.TrimSuffix(out, "\n")) 68 } 69 } 70 71 func (s *DockerSuite) TestInspectContainerFilterInt(c *check.C) { 72 runCmd := exec.Command("bash", "-c", `echo "blahblah" | docker run -i -a stdin busybox cat`) 73 out, _, _, err := runCommandWithStdoutStderr(runCmd) 74 if err != nil { 75 c.Fatalf("failed to run container: %v, output: %q", err, out) 76 } 77 78 id := strings.TrimSpace(out) 79 80 runCmd = exec.Command(dockerBinary, "inspect", "--format='{{.State.ExitCode}}'", id) 81 out, _, err = runCommandWithOutput(runCmd) 82 if err != nil { 83 c.Fatalf("failed to inspect container: %s, %v", out, err) 84 } 85 exitCode, err := strconv.Atoi(strings.TrimSuffix(out, "\n")) 86 if err != nil { 87 c.Fatalf("failed to inspect exitcode of the container: %s, %v", out, err) 88 } 89 90 //now get the exit code to verify 91 formatStr := fmt.Sprintf("--format='{{eq .State.ExitCode %d}}'", exitCode) 92 runCmd = exec.Command(dockerBinary, "inspect", formatStr, id) 93 out, _, err = runCommandWithOutput(runCmd) 94 if err != nil { 95 c.Fatalf("failed to inspect container: %s, %v", out, err) 96 } 97 if result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n")); err != nil || !result { 98 c.Fatalf("Expected exitcode: %d for container: %s", exitCode, id) 99 } 100 }