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

Function TestContainerListWithFormat

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

Source from the content-addressed store, hash-verified

309}
310
311func TestContainerListWithFormat(t *testing.T) {
312 cli := test.NewFakeCli(&fakeClient{
313 containerListFunc: func(_ client.ContainerListOptions) (client.ContainerListResult, error) {
314 return client.ContainerListResult{
315 Items: []container.Summary{
316 *builders.Container("c1", builders.WithLabel("some.label", "value")),
317 *builders.Container("c2", builders.WithName("foo/bar"), builders.WithLabel("foo", "bar")),
318 },
319 }, nil
320 },
321 })
322
323 t.Run("with format", func(t *testing.T) {
324 cli.OutBuffer().Reset()
325 cmd := newListCommand(cli)
326 cmd.SetArgs([]string{})
327 cmd.SetOut(io.Discard)
328 cmd.SetErr(io.Discard)
329 assert.Check(t, cmd.Flags().Set("format", "{{ .Names }} {{ .Image }} {{ .Labels }}"))
330 assert.NilError(t, cmd.Execute())
331 golden.Assert(t, cli.OutBuffer().String(), "container-list-with-format.golden")
332 })
333
334 t.Run("with format and quiet", func(t *testing.T) {
335 cli.OutBuffer().Reset()
336 cmd := newListCommand(cli)
337 cmd.SetArgs([]string{})
338 cmd.SetOut(io.Discard)
339 cmd.SetErr(io.Discard)
340 assert.Check(t, cmd.Flags().Set("format", "{{ .Names }} {{ .Image }} {{ .Labels }}"))
341 assert.Check(t, cmd.Flags().Set("quiet", "true"))
342 assert.NilError(t, cmd.Execute())
343 assert.Equal(t, cli.ErrBuffer().String(), "WARNING: Ignoring custom format, because both --format and --quiet are set.\n")
344 golden.Assert(t, cli.OutBuffer().String(), "container-list-quiet.golden")
345 })
346}

Callers

nothing calls this directly

Calls 9

OutBufferMethod · 0.95
ErrBufferMethod · 0.95
ContainerMethod · 0.80
SetArgsMethod · 0.80
newListCommandFunction · 0.70
StringMethod · 0.65
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…