mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-05 21:21:42 +00:00
Use inspectField to simplify code
Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
This commit is contained in:
@@ -12,13 +12,10 @@ import (
|
||||
func (s *DockerSuite) TestInspectImage(c *check.C) {
|
||||
imageTest := "emptyfs"
|
||||
imageTestID := "511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158"
|
||||
imagesCmd := exec.Command(dockerBinary, "inspect", "--format='{{.Id}}'", imageTest)
|
||||
out, exitCode, err := runCommandWithOutput(imagesCmd)
|
||||
if exitCode != 0 || err != nil {
|
||||
c.Fatalf("failed to inspect image: %s, %v", out, err)
|
||||
}
|
||||
id, err := inspectField(imageTest, "Id")
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
if id := strings.TrimSuffix(out, "\n"); id != imageTestID {
|
||||
if id != imageTestID {
|
||||
c.Fatalf("Expected id: %s for image: %s but received id: %s", imageTestID, imageTest, id)
|
||||
}
|
||||
|
||||
@@ -33,33 +30,28 @@ func (s *DockerSuite) TestInspectInt64(c *check.C) {
|
||||
|
||||
out = strings.TrimSpace(out)
|
||||
|
||||
inspectCmd := exec.Command(dockerBinary, "inspect", "-f", "{{.HostConfig.Memory}}", out)
|
||||
inspectOut, _, err := runCommandWithOutput(inspectCmd)
|
||||
if err != nil {
|
||||
c.Fatalf("failed to inspect container: %v, output: %q", err, inspectOut)
|
||||
}
|
||||
inspectOut, err := inspectField(out, "HostConfig.Memory")
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
if strings.TrimSpace(inspectOut) != "314572800" {
|
||||
if inspectOut != "314572800" {
|
||||
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"))
|
||||
out, err := inspectField(imageTest, "Size")
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
size, err := strconv.Atoi(out)
|
||||
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)
|
||||
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)
|
||||
}
|
||||
@@ -77,12 +69,10 @@ func (s *DockerSuite) TestInspectContainerFilterInt(c *check.C) {
|
||||
|
||||
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"))
|
||||
out, err = inspectField(id, "State.ExitCode")
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
exitCode, err := strconv.Atoi(out)
|
||||
if err != nil {
|
||||
c.Fatalf("failed to inspect exitcode of the container: %s, %v", out, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user