1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #28340 from cpuguy83/28337_fix_template_opts_ps

Fix issue with missing fields for `ps` template
This commit is contained in:
Victor Vieux 2016-11-14 14:25:01 -08:00 committed by GitHub
commit 8930aa0a86
2 changed files with 32 additions and 7 deletions

View file

@ -62,6 +62,12 @@ func newListCommand(dockerCli *command.DockerCli) *cobra.Command {
type preProcessor struct {
types.Container
opts *types.ContainerListOptions
// Fields that need to exist so the template doesn't error out
// These are needed since they are available on the final object but are not
// fields in types.Container
// TODO(cpuguy83): this seems rather broken
Networks, CreatedAt, RunningFor bool
}
// Size sets the size option when called by a template execution.
@ -70,13 +76,6 @@ func (p *preProcessor) Size() bool {
return true
}
// Networks does nothing but return true.
// It is needed to avoid the template check to fail as this field
// doesn't exist in `types.Container`
func (p *preProcessor) Networks() bool {
return true
}
func buildContainerListOptions(opts *psOptions) (*types.ContainerListOptions, error) {
options := &types.ContainerListOptions{
All: opts.all,

View file

@ -370,3 +370,29 @@ func TestContainerContextWriteJSONField(t *testing.T) {
assert.Equal(t, s, containers[i].ID)
}
}
func TestContainerBackCompat(t *testing.T) {
containers := []types.Container{types.Container{ID: "brewhaha"}}
cases := []string{
"ID",
"Names",
"Image",
"Command",
"CreatedAt",
"RunningFor",
"Ports",
"Status",
"Size",
"Labels",
"Mounts",
}
buf := bytes.NewBuffer(nil)
for _, c := range cases {
ctx := Context{Format: Format(fmt.Sprintf("{{ .%s }}", c)), Output: buf}
if err := ContainerWrite(ctx, containers); err != nil {
t.Log("could not render template for field '%s': %v", c, err)
t.Fail()
}
buf.Reset()
}
}