Skip to content

Commit 3b09b75

Browse files
committed
Expand tests for size auto-detection
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
1 parent 214ffc5 commit 3b09b75

1 file changed

Lines changed: 49 additions & 8 deletions

File tree

cli/command/container/list_test.go

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,56 @@ func TestContainerListFormatTemplateWithArg(t *testing.T) {
231231
}
232232

233233
func TestContainerListFormatSizeSetsOption(t *testing.T) {
234-
cli := test.NewFakeCli(&fakeClient{
235-
containerListFunc: func(options types.ContainerListOptions) ([]types.Container, error) {
236-
assert.Check(t, options.Size)
237-
return []types.Container{}, nil
234+
tests := []struct {
235+
doc, format, sizeFlag string
236+
sizeExpected bool
237+
}{
238+
{
239+
doc: "detect with all fields",
240+
format: `{{json .}}`,
241+
sizeExpected: true,
238242
},
239-
})
240-
cmd := newListCommand(cli)
241-
cmd.Flags().Set("format", `{{.Size}}`)
242-
assert.NilError(t, cmd.Execute())
243+
{
244+
doc: "detect with explicit field",
245+
format: `{{.Size}}`,
246+
sizeExpected: true,
247+
},
248+
{
249+
doc: "detect no size",
250+
format: `{{.Names}}`,
251+
sizeExpected: false,
252+
},
253+
{
254+
doc: "override enable",
255+
format: `{{.Names}}`,
256+
sizeFlag: "true",
257+
sizeExpected: true,
258+
},
259+
{
260+
doc: "override disable",
261+
format: `{{.Size}}`,
262+
sizeFlag: "false",
263+
sizeExpected: false,
264+
},
265+
}
266+
267+
for _, tc := range tests {
268+
tc := tc
269+
t.Run(tc.doc, func(t *testing.T) {
270+
cli := test.NewFakeCli(&fakeClient{
271+
containerListFunc: func(options types.ContainerListOptions) ([]types.Container, error) {
272+
assert.Check(t, is.Equal(options.Size, tc.sizeExpected))
273+
return []types.Container{}, nil
274+
},
275+
})
276+
cmd := newListCommand(cli)
277+
cmd.Flags().Set("format", tc.format)
278+
if tc.sizeFlag != "" {
279+
cmd.Flags().Set("size", tc.sizeFlag)
280+
}
281+
assert.NilError(t, cmd.Execute())
282+
})
283+
}
243284
}
244285

245286
func TestContainerListWithConfigFormat(t *testing.T) {

0 commit comments

Comments
 (0)