From a9bbf92b3f2f766f4ca454a5fcec9c1603733a66 Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Sat, 12 Nov 2016 11:10:27 -0500 Subject: [PATCH] Fix issue with missing fields for `ps` template Signed-off-by: Brian Goff --- cli/command/container/list.go | 13 ++++++------- cli/command/formatter/container_test.go | 26 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/cli/command/container/list.go b/cli/command/container/list.go index 80de7c5ff4..b4cdfa2eb3 100644 --- a/cli/command/container/list.go +++ b/cli/command/container/list.go @@ -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, diff --git a/cli/command/formatter/container_test.go b/cli/command/formatter/container_test.go index 0a844efb65..cdfc911a94 100644 --- a/cli/command/formatter/container_test.go +++ b/cli/command/formatter/container_test.go @@ -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() + } +}