Allow go template to work properly with inspect
Closes #11641 Signed-off-by: Srini Brahmaroutu <srbrahma@us.ibm.com> Upstream-commit: 231d362db73310a5243a72dcdb6df2df57c74488 Component: engine
This commit is contained in:
committed by
Srini Brahmaroutu
parent
0b0a96ad89
commit
12be8c3158
@ -1,7 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/go-check/check"
|
||||
@ -41,3 +43,58 @@ func (s *DockerSuite) TestInspectInt64(c *check.C) {
|
||||
c.Fatalf("inspect got wrong value, got: %q, expected: 314572800", inspectOut)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectImageFilterInt(c *check.C) {
|
||||
imageTest := "emptyfs"
|
||||
imagesCmd := exec.Command(dockerBinary, "inspect", "--format='{{.Size}}'", imageTest)
|
||||
out, exitCode, err := runCommandWithOutput(imagesCmd)
|
||||
if exitCode != 0 || err != nil {
|
||||
c.Fatalf("failed to inspect image: %s, %v", out, err)
|
||||
}
|
||||
size, err := strconv.Atoi(strings.TrimSuffix(out, "\n"))
|
||||
if err != nil {
|
||||
c.Fatalf("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)
|
||||
imagesCmd = exec.Command(dockerBinary, "inspect", formatStr, imageTest)
|
||||
out, exitCode, err = runCommandWithOutput(imagesCmd)
|
||||
if exitCode != 0 || err != nil {
|
||||
c.Fatalf("failed to inspect image: %s, %v", out, err)
|
||||
}
|
||||
if result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n")); err != nil || !result {
|
||||
c.Fatalf("Expected size: %d for image: %s but received size: %s", size, imageTest, strings.TrimSuffix(out, "\n"))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestInspectContainerFilterInt(c *check.C) {
|
||||
runCmd := exec.Command("bash", "-c", `echo "blahblah" | docker run -i -a stdin busybox cat`)
|
||||
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
||||
if err != nil {
|
||||
c.Fatalf("failed to run container: %v, output: %q", err, out)
|
||||
}
|
||||
|
||||
id := strings.TrimSpace(out)
|
||||
|
||||
runCmd = exec.Command(dockerBinary, "inspect", "--format='{{.State.ExitCode}}'", id)
|
||||
out, _, err = runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
c.Fatalf("failed to inspect container: %s, %v", out, err)
|
||||
}
|
||||
exitCode, err := strconv.Atoi(strings.TrimSuffix(out, "\n"))
|
||||
if err != nil {
|
||||
c.Fatalf("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)
|
||||
runCmd = exec.Command(dockerBinary, "inspect", formatStr, id)
|
||||
out, _, err = runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
c.Fatalf("failed to inspect container: %s, %v", out, err)
|
||||
}
|
||||
if result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n")); err != nil || !result {
|
||||
c.Fatalf("Expected exitcode: %d for container: %s", exitCode, id)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user