mirror of https://github.com/docker/cli.git
cli/command/container: set empty args in tests and discard output
Prevent some tests from failing when running from a pre-compiled testbinary, and discard output to make the output less noisy. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
31eeed7ca4
commit
3b38dc67be
|
@ -127,7 +127,6 @@ func TestContainerListBuildContainerListOptions(t *testing.T) {
|
||||||
|
|
||||||
func TestContainerListErrors(t *testing.T) {
|
func TestContainerListErrors(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
args []string
|
|
||||||
flags map[string]string
|
flags map[string]string
|
||||||
containerListFunc func(container.ListOptions) ([]container.Summary, error)
|
containerListFunc func(container.ListOptions) ([]container.Summary, error)
|
||||||
expectedError string
|
expectedError string
|
||||||
|
@ -157,10 +156,10 @@ func TestContainerListErrors(t *testing.T) {
|
||||||
containerListFunc: tc.containerListFunc,
|
containerListFunc: tc.containerListFunc,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
cmd.SetArgs(tc.args)
|
|
||||||
for key, value := range tc.flags {
|
for key, value := range tc.flags {
|
||||||
assert.Check(t, cmd.Flags().Set(key, value))
|
assert.Check(t, cmd.Flags().Set(key, value))
|
||||||
}
|
}
|
||||||
|
cmd.SetArgs([]string{})
|
||||||
cmd.SetOut(io.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetErr(io.Discard)
|
cmd.SetErr(io.Discard)
|
||||||
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
|
@ -180,6 +179,9 @@ func TestContainerListWithoutFormat(t *testing.T) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
cmd := newListCommand(cli)
|
cmd := newListCommand(cli)
|
||||||
|
cmd.SetArgs([]string{})
|
||||||
|
cmd.SetOut(io.Discard)
|
||||||
|
cmd.SetErr(io.Discard)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NilError(t, cmd.Execute())
|
||||||
golden.Assert(t, cli.OutBuffer().String(), "container-list-without-format.golden")
|
golden.Assert(t, cli.OutBuffer().String(), "container-list-without-format.golden")
|
||||||
}
|
}
|
||||||
|
@ -194,6 +196,9 @@ func TestContainerListNoTrunc(t *testing.T) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
cmd := newListCommand(cli)
|
cmd := newListCommand(cli)
|
||||||
|
cmd.SetArgs([]string{})
|
||||||
|
cmd.SetOut(io.Discard)
|
||||||
|
cmd.SetErr(io.Discard)
|
||||||
assert.Check(t, cmd.Flags().Set("no-trunc", "true"))
|
assert.Check(t, cmd.Flags().Set("no-trunc", "true"))
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NilError(t, cmd.Execute())
|
||||||
golden.Assert(t, cli.OutBuffer().String(), "container-list-without-format-no-trunc.golden")
|
golden.Assert(t, cli.OutBuffer().String(), "container-list-without-format-no-trunc.golden")
|
||||||
|
@ -210,6 +215,9 @@ func TestContainerListNamesMultipleTime(t *testing.T) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
cmd := newListCommand(cli)
|
cmd := newListCommand(cli)
|
||||||
|
cmd.SetArgs([]string{})
|
||||||
|
cmd.SetOut(io.Discard)
|
||||||
|
cmd.SetErr(io.Discard)
|
||||||
assert.Check(t, cmd.Flags().Set("format", "{{.Names}} {{.Names}}"))
|
assert.Check(t, cmd.Flags().Set("format", "{{.Names}} {{.Names}}"))
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NilError(t, cmd.Execute())
|
||||||
golden.Assert(t, cli.OutBuffer().String(), "container-list-format-name-name.golden")
|
golden.Assert(t, cli.OutBuffer().String(), "container-list-format-name-name.golden")
|
||||||
|
@ -226,6 +234,9 @@ func TestContainerListFormatTemplateWithArg(t *testing.T) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
cmd := newListCommand(cli)
|
cmd := newListCommand(cli)
|
||||||
|
cmd.SetArgs([]string{})
|
||||||
|
cmd.SetOut(io.Discard)
|
||||||
|
cmd.SetErr(io.Discard)
|
||||||
assert.Check(t, cmd.Flags().Set("format", `{{.Names}} {{.Label "some.label"}}`))
|
assert.Check(t, cmd.Flags().Set("format", `{{.Names}} {{.Label "some.label"}}`))
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NilError(t, cmd.Execute())
|
||||||
golden.Assert(t, cli.OutBuffer().String(), "container-list-format-with-arg.golden")
|
golden.Assert(t, cli.OutBuffer().String(), "container-list-format-with-arg.golden")
|
||||||
|
@ -275,6 +286,9 @@ func TestContainerListFormatSizeSetsOption(t *testing.T) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
cmd := newListCommand(cli)
|
cmd := newListCommand(cli)
|
||||||
|
cmd.SetArgs([]string{})
|
||||||
|
cmd.SetOut(io.Discard)
|
||||||
|
cmd.SetErr(io.Discard)
|
||||||
assert.Check(t, cmd.Flags().Set("format", tc.format))
|
assert.Check(t, cmd.Flags().Set("format", tc.format))
|
||||||
if tc.sizeFlag != "" {
|
if tc.sizeFlag != "" {
|
||||||
assert.Check(t, cmd.Flags().Set("size", tc.sizeFlag))
|
assert.Check(t, cmd.Flags().Set("size", tc.sizeFlag))
|
||||||
|
@ -297,6 +311,9 @@ func TestContainerListWithConfigFormat(t *testing.T) {
|
||||||
PsFormat: "{{ .Names }} {{ .Image }} {{ .Labels }} {{ .Size}}",
|
PsFormat: "{{ .Names }} {{ .Image }} {{ .Labels }} {{ .Size}}",
|
||||||
})
|
})
|
||||||
cmd := newListCommand(cli)
|
cmd := newListCommand(cli)
|
||||||
|
cmd.SetArgs([]string{})
|
||||||
|
cmd.SetOut(io.Discard)
|
||||||
|
cmd.SetErr(io.Discard)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NilError(t, cmd.Execute())
|
||||||
golden.Assert(t, cli.OutBuffer().String(), "container-list-with-config-format.golden")
|
golden.Assert(t, cli.OutBuffer().String(), "container-list-with-config-format.golden")
|
||||||
}
|
}
|
||||||
|
@ -314,6 +331,9 @@ func TestContainerListWithFormat(t *testing.T) {
|
||||||
t.Run("with format", func(t *testing.T) {
|
t.Run("with format", func(t *testing.T) {
|
||||||
cli.OutBuffer().Reset()
|
cli.OutBuffer().Reset()
|
||||||
cmd := newListCommand(cli)
|
cmd := newListCommand(cli)
|
||||||
|
cmd.SetArgs([]string{})
|
||||||
|
cmd.SetOut(io.Discard)
|
||||||
|
cmd.SetErr(io.Discard)
|
||||||
assert.Check(t, cmd.Flags().Set("format", "{{ .Names }} {{ .Image }} {{ .Labels }}"))
|
assert.Check(t, cmd.Flags().Set("format", "{{ .Names }} {{ .Image }} {{ .Labels }}"))
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NilError(t, cmd.Execute())
|
||||||
golden.Assert(t, cli.OutBuffer().String(), "container-list-with-format.golden")
|
golden.Assert(t, cli.OutBuffer().String(), "container-list-with-format.golden")
|
||||||
|
@ -322,6 +342,9 @@ func TestContainerListWithFormat(t *testing.T) {
|
||||||
t.Run("with format and quiet", func(t *testing.T) {
|
t.Run("with format and quiet", func(t *testing.T) {
|
||||||
cli.OutBuffer().Reset()
|
cli.OutBuffer().Reset()
|
||||||
cmd := newListCommand(cli)
|
cmd := newListCommand(cli)
|
||||||
|
cmd.SetArgs([]string{})
|
||||||
|
cmd.SetOut(io.Discard)
|
||||||
|
cmd.SetErr(io.Discard)
|
||||||
assert.Check(t, cmd.Flags().Set("format", "{{ .Names }} {{ .Image }} {{ .Labels }}"))
|
assert.Check(t, cmd.Flags().Set("format", "{{ .Names }} {{ .Image }} {{ .Labels }}"))
|
||||||
assert.Check(t, cmd.Flags().Set("quiet", "true"))
|
assert.Check(t, cmd.Flags().Set("quiet", "true"))
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NilError(t, cmd.Execute())
|
||||||
|
|
|
@ -21,6 +21,7 @@ func TestContainerPrunePromptTermination(t *testing.T) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
cmd := NewPruneCommand(cli)
|
cmd := NewPruneCommand(cli)
|
||||||
|
cmd.SetArgs([]string{})
|
||||||
cmd.SetOut(io.Discard)
|
cmd.SetOut(io.Discard)
|
||||||
cmd.SetErr(io.Discard)
|
cmd.SetErr(io.Discard)
|
||||||
test.TerminatePrompt(ctx, t, cmd, cli)
|
test.TerminatePrompt(ctx, t, cmd, cli)
|
||||||
|
|
Loading…
Reference in New Issue