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 c8336743a4
commit e16e9775d4
8 changed files with 31 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 {
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)

View File

@ -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`
}

View File

@ -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 {

View File

@ -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},
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -18,6 +18,7 @@ var basicFunctions = template.FuncMap{
"title": strings.Title,
"lower": strings.ToLower,
"upper": strings.ToUpper,
"pad": padWithSpace,
}
// Parse creates a new annonymous template with the basic functions
@ -31,3 +32,11 @@ func Parse(format string) (*template.Template, error) {
func NewParse(tag, format string) (*template.Template, error) {
return template.New(tag).Funcs(basicFunctions).Parse(format)
}
// padWithSpace adds whitespace to the input if the input is non-empty
func padWithSpace(source string, prefix, suffix int) string {
if source == "" {
return source
}
return strings.Repeat(" ", prefix) + source + strings.Repeat(" ", suffix)
}