From 2f8c4333fea63e4d5ae9158a2b13905c2e322e81 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 13 Sep 2016 14:21:07 -0400 Subject: [PATCH] Fix testcases that expect trailing whitespace and broken integration tests based of nil pointers Signed-off-by: Daniel Nephin --- command/container/ps.go | 4 ++-- command/formatter/container.go | 10 +++++++++- command/formatter/volume.go | 4 ++-- command/formatter/volume_test.go | 12 ++++++------ command/image/images.go | 2 +- command/network/list.go | 2 +- command/volume/list.go | 2 +- 7 files changed, 22 insertions(+), 14 deletions(-) diff --git a/command/container/ps.go b/command/container/ps.go index 9d015fd707..b5a3be06e9 100644 --- a/command/container/ps.go +++ b/command/container/ps.go @@ -111,13 +111,13 @@ func runPs(dockerCli *command.DockerCli, opts *psOptions) error { if len(dockerCli.ConfigFile().PsFormat) > 0 && !opts.quiet { format = dockerCli.ConfigFile().PsFormat } else { - format = "table" + format = formatter.TableFormatKey } } containerCtx := formatter.Context{ Output: dockerCli.Out(), - Format: formatter.NewContainerFormat(format, opts.quiet, opts.size), + Format: formatter.NewContainerFormat(format, opts.quiet, listOptions.Size), Trunc: !opts.noTrunc, } return formatter.ContainerWrite(containerCtx, containers) diff --git a/command/formatter/container.go b/command/formatter/container.go index 6f3a162fe3..30a6492476 100644 --- a/command/formatter/container.go +++ b/command/formatter/container.go @@ -41,7 +41,15 @@ func NewContainerFormat(source string, quiet bool, size bool) Format { if quiet { return `container_id: {{.ID}}` } - format := `container_id: {{.ID}}\nimage: {{.Image}}\ncommand: {{.Command}}\ncreated_at: {{.CreatedAt}}\nstatus: {{.Status}}\nnames: {{.Names}}\nlabels: {{.Labels}}\nports: {{.Ports}}\n` + format := `container_id: {{.ID}} +image: {{.Image}} +command: {{.Command}} +created_at: {{.CreatedAt}} +status: {{- pad .Status 1 0}} +names: {{.Names}} +labels: {{- pad .Labels 1 0}} +ports: {{- pad .Ports 1 0}} +` if size { format += `size: {{.Size}}\n` } diff --git a/command/formatter/volume.go b/command/formatter/volume.go index 2fec59d8fb..e41ee266bf 100644 --- a/command/formatter/volume.go +++ b/command/formatter/volume.go @@ -36,7 +36,7 @@ func NewVolumeFormat(source string, quiet bool) Format { func VolumeWrite(ctx Context, volumes []*types.Volume) error { render := func(format func(subContext subContext) error) error { for _, volume := range volumes { - if err := format(&volumeContext{v: volume}); err != nil { + if err := format(&volumeContext{v: *volume}); err != nil { return err } } @@ -47,7 +47,7 @@ func VolumeWrite(ctx Context, volumes []*types.Volume) error { type volumeContext struct { HeaderContext - v *types.Volume + v types.Volume } func (c *volumeContext) Name() string { diff --git a/command/formatter/volume_test.go b/command/formatter/volume_test.go index 1d5f74e42c..8c715b3438 100644 --- a/command/formatter/volume_test.go +++ b/command/formatter/volume_test.go @@ -21,22 +21,22 @@ func TestVolumeContext(t *testing.T) { call func() string }{ {volumeContext{ - v: &types.Volume{Name: volumeName}, + v: types.Volume{Name: volumeName}, }, volumeName, nameHeader, ctx.Name}, {volumeContext{ - v: &types.Volume{Driver: "driver_name"}, + v: types.Volume{Driver: "driver_name"}, }, "driver_name", driverHeader, ctx.Driver}, {volumeContext{ - v: &types.Volume{Scope: "local"}, + v: types.Volume{Scope: "local"}, }, "local", scopeHeader, ctx.Scope}, {volumeContext{ - v: &types.Volume{Mountpoint: "mountpoint"}, + v: types.Volume{Mountpoint: "mountpoint"}, }, "mountpoint", mountpointHeader, ctx.Mountpoint}, {volumeContext{ - v: &types.Volume{}, + v: types.Volume{}, }, "", labelsHeader, ctx.Labels}, {volumeContext{ - v: &types.Volume{Labels: map[string]string{"label1": "value1", "label2": "value2"}}, + v: types.Volume{Labels: map[string]string{"label1": "value1", "label2": "value2"}}, }, "label1=value1,label2=value2", labelsHeader, ctx.Labels}, } diff --git a/command/image/images.go b/command/image/images.go index b7dbd05671..0229734ce4 100644 --- a/command/image/images.go +++ b/command/image/images.go @@ -69,7 +69,7 @@ func runImages(dockerCli *command.DockerCli, opts imagesOptions) error { if len(dockerCli.ConfigFile().ImagesFormat) > 0 && !opts.quiet { format = dockerCli.ConfigFile().ImagesFormat } else { - format = "table" + format = formatter.TableFormatKey } } diff --git a/command/network/list.go b/command/network/list.go index dd7b72fea7..9ba803275b 100644 --- a/command/network/list.go +++ b/command/network/list.go @@ -61,7 +61,7 @@ func runList(dockerCli *command.DockerCli, opts listOptions) error { if len(dockerCli.ConfigFile().NetworksFormat) > 0 && !opts.quiet { format = dockerCli.ConfigFile().NetworksFormat } else { - format = "table" + format = formatter.TableFormatKey } } diff --git a/command/volume/list.go b/command/volume/list.go index cdbbaafc61..77ce359771 100644 --- a/command/volume/list.go +++ b/command/volume/list.go @@ -61,7 +61,7 @@ func runList(dockerCli *command.DockerCli, opts listOptions) error { if len(dockerCli.ConfigFile().VolumesFormat) > 0 && !opts.quiet { format = dockerCli.ConfigFile().VolumesFormat } else { - format = "table" + format = formatter.TableFormatKey } }