Browse code

Fix testcases that expect trailing whitespace

and broken integration tests based of nil pointers

Signed-off-by: Daniel Nephin <dnephin@docker.com>

Daniel Nephin authored on 2016/09/14 03:21:07
Showing 8 changed files
... ...
@@ -111,13 +111,13 @@ func runPs(dockerCli *command.DockerCli, opts *psOptions) error {
111 111
 		if len(dockerCli.ConfigFile().PsFormat) > 0 && !opts.quiet {
112 112
 			format = dockerCli.ConfigFile().PsFormat
113 113
 		} else {
114
-			format = "table"
114
+			format = formatter.TableFormatKey
115 115
 		}
116 116
 	}
117 117
 
118 118
 	containerCtx := formatter.Context{
119 119
 		Output: dockerCli.Out(),
120
-		Format: formatter.NewContainerFormat(format, opts.quiet, opts.size),
120
+		Format: formatter.NewContainerFormat(format, opts.quiet, listOptions.Size),
121 121
 		Trunc:  !opts.noTrunc,
122 122
 	}
123 123
 	return formatter.ContainerWrite(containerCtx, containers)
... ...
@@ -41,7 +41,15 @@ func NewContainerFormat(source string, quiet bool, size bool) Format {
41 41
 		if quiet {
42 42
 			return `container_id: {{.ID}}`
43 43
 		}
44
-		format := `container_id: {{.ID}}\nimage: {{.Image}}\ncommand: {{.Command}}\ncreated_at: {{.CreatedAt}}\nstatus: {{.Status}}\nnames: {{.Names}}\nlabels: {{.Labels}}\nports: {{.Ports}}\n`
44
+		format := `container_id: {{.ID}}
45
+image: {{.Image}}
46
+command: {{.Command}}
47
+created_at: {{.CreatedAt}}
48
+status: {{- pad .Status 1 0}}
49
+names: {{.Names}}
50
+labels: {{- pad .Labels 1 0}}
51
+ports: {{- pad .Ports 1 0}}
52
+`
45 53
 		if size {
46 54
 			format += `size: {{.Size}}\n`
47 55
 		}
... ...
@@ -36,7 +36,7 @@ func NewVolumeFormat(source string, quiet bool) Format {
36 36
 func VolumeWrite(ctx Context, volumes []*types.Volume) error {
37 37
 	render := func(format func(subContext subContext) error) error {
38 38
 		for _, volume := range volumes {
39
-			if err := format(&volumeContext{v: volume}); err != nil {
39
+			if err := format(&volumeContext{v: *volume}); err != nil {
40 40
 				return err
41 41
 			}
42 42
 		}
... ...
@@ -47,7 +47,7 @@ func VolumeWrite(ctx Context, volumes []*types.Volume) error {
47 47
 
48 48
 type volumeContext struct {
49 49
 	HeaderContext
50
-	v *types.Volume
50
+	v types.Volume
51 51
 }
52 52
 
53 53
 func (c *volumeContext) Name() string {
... ...
@@ -21,22 +21,22 @@ func TestVolumeContext(t *testing.T) {
21 21
 		call      func() string
22 22
 	}{
23 23
 		{volumeContext{
24
-			v: &types.Volume{Name: volumeName},
24
+			v: types.Volume{Name: volumeName},
25 25
 		}, volumeName, nameHeader, ctx.Name},
26 26
 		{volumeContext{
27
-			v: &types.Volume{Driver: "driver_name"},
27
+			v: types.Volume{Driver: "driver_name"},
28 28
 		}, "driver_name", driverHeader, ctx.Driver},
29 29
 		{volumeContext{
30
-			v: &types.Volume{Scope: "local"},
30
+			v: types.Volume{Scope: "local"},
31 31
 		}, "local", scopeHeader, ctx.Scope},
32 32
 		{volumeContext{
33
-			v: &types.Volume{Mountpoint: "mountpoint"},
33
+			v: types.Volume{Mountpoint: "mountpoint"},
34 34
 		}, "mountpoint", mountpointHeader, ctx.Mountpoint},
35 35
 		{volumeContext{
36
-			v: &types.Volume{},
36
+			v: types.Volume{},
37 37
 		}, "", labelsHeader, ctx.Labels},
38 38
 		{volumeContext{
39
-			v: &types.Volume{Labels: map[string]string{"label1": "value1", "label2": "value2"}},
39
+			v: types.Volume{Labels: map[string]string{"label1": "value1", "label2": "value2"}},
40 40
 		}, "label1=value1,label2=value2", labelsHeader, ctx.Labels},
41 41
 	}
42 42
 
... ...
@@ -69,7 +69,7 @@ func runImages(dockerCli *command.DockerCli, opts imagesOptions) error {
69 69
 		if len(dockerCli.ConfigFile().ImagesFormat) > 0 && !opts.quiet {
70 70
 			format = dockerCli.ConfigFile().ImagesFormat
71 71
 		} else {
72
-			format = "table"
72
+			format = formatter.TableFormatKey
73 73
 		}
74 74
 	}
75 75
 
... ...
@@ -61,7 +61,7 @@ func runList(dockerCli *command.DockerCli, opts listOptions) error {
61 61
 		if len(dockerCli.ConfigFile().NetworksFormat) > 0 && !opts.quiet {
62 62
 			format = dockerCli.ConfigFile().NetworksFormat
63 63
 		} else {
64
-			format = "table"
64
+			format = formatter.TableFormatKey
65 65
 		}
66 66
 	}
67 67
 
... ...
@@ -61,7 +61,7 @@ func runList(dockerCli *command.DockerCli, opts listOptions) error {
61 61
 		if len(dockerCli.ConfigFile().VolumesFormat) > 0 && !opts.quiet {
62 62
 			format = dockerCli.ConfigFile().VolumesFormat
63 63
 		} else {
64
-			format = "table"
64
+			format = formatter.TableFormatKey
65 65
 		}
66 66
 	}
67 67
 
... ...
@@ -18,6 +18,7 @@ var basicFunctions = template.FuncMap{
18 18
 	"title": strings.Title,
19 19
 	"lower": strings.ToLower,
20 20
 	"upper": strings.ToUpper,
21
+	"pad":   padWithSpace,
21 22
 }
22 23
 
23 24
 // Parse creates a new annonymous template with the basic functions
... ...
@@ -31,3 +32,11 @@ func Parse(format string) (*template.Template, error) {
31 31
 func NewParse(tag, format string) (*template.Template, error) {
32 32
 	return template.New(tag).Funcs(basicFunctions).Parse(format)
33 33
 }
34
+
35
+// padWithSpace adds whitespace to the input if the input is non-empty
36
+func padWithSpace(source string, prefix, suffix int) string {
37
+	if source == "" {
38
+		return source
39
+	}
40
+	return strings.Repeat(" ", prefix) + source + strings.Repeat(" ", suffix)
41
+}