Skip to content

Commit

Permalink
bugfix: fix error when input 'inspect -f {{.Id}}'
Browse files Browse the repository at this point in the history
Signed-off-by: KevinBetterQ <1093850932@qq.com>
  • Loading branch information
KevinBetterQ committed May 20, 2019
1 parent 7235f82 commit a778a84
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cli/inspect/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func NewTemplateInspectorFromString(out io.Writer, tmplStr string) (Inspector, e
if tmplStr == "" {
return NewIndentedInspector(out), nil
}
if strings.Contains(tmplStr, ".Id") {
tmplStr = strings.Replace(tmplStr, ".Id", ".ID", -1)
}

tmpl, err := templates.Parse(tmplStr)
if err != nil {
Expand Down
11 changes: 10 additions & 1 deletion cli/inspect/inspector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,20 @@ func TestInspect(t *testing.T) {
},
wantOut: "\n",
wantErr: false,
}, {
name: "testInspectTemplate{{.Id}}",
args: args{
references: []string{"reference"},
tmplStr: "{{.Id}}",
getRef: getRefFunc,
},
wantOut: "id",
wantErr: false,
}, {
name: "testInspectTemplateError",
args: args{
references: []string{"single reference"},
tmplStr: "{{.Id}}",
tmplStr: "{{.id}}",
getRef: getRefFunc,
},
wantOut: "",
Expand Down
4 changes: 4 additions & 0 deletions test/cli_inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func (suite *PouchInspectSuite) TestInspectCreateAndStartedFormat(c *check.C) {
output = command.PouchRun("inspect", "-f", "{{.ID}}", name).Stdout()
c.Assert(output, check.Equals, fmt.Sprintf("%s\n", containerID))

// inspect Container Id
output = command.PouchRun("inspect", "-f", "{{.Id}}", name).Stdout()
c.Assert(output, check.Equals, fmt.Sprintf("%s\n", containerID))

// inspect Memory
output = command.PouchRun("inspect", "-f", "{{.HostConfig.Memory}}", name).Stdout()
c.Assert(output, check.Equals, fmt.Sprintf("%d\n", result[0].HostConfig.Memory))
Expand Down

0 comments on commit a778a84

Please sign in to comment.