MCPcopy Index your code
hub / github.com/docker/cli / TestContainerListFormatSizeSetsOption

Function TestContainerListFormatSizeSetsOption

cli/command/container/list_test.go:234–287  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

SetArgsMethod · 0.80
newListCommandFunction · 0.70
SetOutMethod · 0.45
SetErrMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…