Fix testcases that expect trailing whitespace

and broken integration tests based of nil pointers

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2016-09-13 14:21:07 -04:00
parent db0952ad22
commit 2f8c4333fe
7 changed files with 22 additions and 14 deletions

View File

@ -111,13 +111,13 @@ func runPs(dockerCli *command.DockerCli, opts *psOptions) error {
if len(dockerCli.ConfigFile().PsFormat) > 0 && !opts.quiet { if len(dockerCli.ConfigFile().PsFormat) > 0 && !opts.quiet {
format = dockerCli.ConfigFile().PsFormat format = dockerCli.ConfigFile().PsFormat
} else { } else {
format = "table" format = formatter.TableFormatKey
} }
} }
containerCtx := formatter.Context{ containerCtx := formatter.Context{
Output: dockerCli.Out(), Output: dockerCli.Out(),
Format: formatter.NewContainerFormat(format, opts.quiet, opts.size), Format: formatter.NewContainerFormat(format, opts.quiet, listOptions.Size),
Trunc: !opts.noTrunc, Trunc: !opts.noTrunc,
} }
return formatter.ContainerWrite(containerCtx, containers) return formatter.ContainerWrite(containerCtx, containers)

View File

@ -41,7 +41,15 @@ func NewContainerFormat(source string, quiet bool, size bool) Format {
if quiet { if quiet {
return `container_id: {{.ID}}` 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 { if size {
format += `size: {{.Size}}\n` format += `size: {{.Size}}\n`
} }

View File

@ -36,7 +36,7 @@ func NewVolumeFormat(source string, quiet bool) Format {
func VolumeWrite(ctx Context, volumes []*types.Volume) error { func VolumeWrite(ctx Context, volumes []*types.Volume) error {
render := func(format func(subContext subContext) error) error { render := func(format func(subContext subContext) error) error {
for _, volume := range volumes { for _, volume := range volumes {
if err := format(&volumeContext{v: volume}); err != nil { if err := format(&volumeContext{v: *volume}); err != nil {
return err return err
} }
} }
@ -47,7 +47,7 @@ func VolumeWrite(ctx Context, volumes []*types.Volume) error {
type volumeContext struct { type volumeContext struct {
HeaderContext HeaderContext
v *types.Volume v types.Volume
} }
func (c *volumeContext) Name() string { func (c *volumeContext) Name() string {

View File

@ -21,22 +21,22 @@ func TestVolumeContext(t *testing.T) {
call func() string call func() string
}{ }{
{volumeContext{ {volumeContext{
v: &types.Volume{Name: volumeName}, v: types.Volume{Name: volumeName},
}, volumeName, nameHeader, ctx.Name}, }, volumeName, nameHeader, ctx.Name},
{volumeContext{ {volumeContext{
v: &types.Volume{Driver: "driver_name"}, v: types.Volume{Driver: "driver_name"},
}, "driver_name", driverHeader, ctx.Driver}, }, "driver_name", driverHeader, ctx.Driver},
{volumeContext{ {volumeContext{
v: &types.Volume{Scope: "local"}, v: types.Volume{Scope: "local"},
}, "local", scopeHeader, ctx.Scope}, }, "local", scopeHeader, ctx.Scope},
{volumeContext{ {volumeContext{
v: &types.Volume{Mountpoint: "mountpoint"}, v: types.Volume{Mountpoint: "mountpoint"},
}, "mountpoint", mountpointHeader, ctx.Mountpoint}, }, "mountpoint", mountpointHeader, ctx.Mountpoint},
{volumeContext{ {volumeContext{
v: &types.Volume{}, v: types.Volume{},
}, "", labelsHeader, ctx.Labels}, }, "", labelsHeader, ctx.Labels},
{volumeContext{ {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}, }, "label1=value1,label2=value2", labelsHeader, ctx.Labels},
} }

View File

@ -69,7 +69,7 @@ func runImages(dockerCli *command.DockerCli, opts imagesOptions) error {
if len(dockerCli.ConfigFile().ImagesFormat) > 0 && !opts.quiet { if len(dockerCli.ConfigFile().ImagesFormat) > 0 && !opts.quiet {
format = dockerCli.ConfigFile().ImagesFormat format = dockerCli.ConfigFile().ImagesFormat
} else { } else {
format = "table" format = formatter.TableFormatKey
} }
} }

View File

@ -61,7 +61,7 @@ func runList(dockerCli *command.DockerCli, opts listOptions) error {
if len(dockerCli.ConfigFile().NetworksFormat) > 0 && !opts.quiet { if len(dockerCli.ConfigFile().NetworksFormat) > 0 && !opts.quiet {
format = dockerCli.ConfigFile().NetworksFormat format = dockerCli.ConfigFile().NetworksFormat
} else { } else {
format = "table" format = formatter.TableFormatKey
} }
} }

View File

@ -61,7 +61,7 @@ func runList(dockerCli *command.DockerCli, opts listOptions) error {
if len(dockerCli.ConfigFile().VolumesFormat) > 0 && !opts.quiet { if len(dockerCli.ConfigFile().VolumesFormat) > 0 && !opts.quiet {
format = dockerCli.ConfigFile().VolumesFormat format = dockerCli.ConfigFile().VolumesFormat
} else { } else {
format = "table" format = formatter.TableFormatKey
} }
} }