From db827d583b42f5975a09135d8ba937f30401faf7 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 8 Feb 2023 02:27:51 +0100 Subject: [PATCH] cli/command/volume: suppress err output in tests These tests were deliberately producing errors as part of the test, but printing those errors could be confusing / make it more difficult to find actual test-failures. Before this patch: === RUN TestVolumeCreateErrors Error: conflicting options: either specify --name or provide positional arg, not both Error: "create" requires at most 1 argument. See 'create --help'. Usage: create [OPTIONS] [VOLUME] [flags] Create a volume Error: error creating volume --- PASS: TestVolumeCreateErrors (0.00s) PASS With this patch applied: === RUN TestVolumeCreateErrors --- PASS: TestVolumeCreateErrors (0.00s) PASS Signed-off-by: Sebastiaan van Stijn --- cli/command/volume/create_test.go | 1 + cli/command/volume/inspect_test.go | 1 + cli/command/volume/list_test.go | 1 + cli/command/volume/prune_test.go | 1 + cli/command/volume/remove_test.go | 1 + 5 files changed, 5 insertions(+) diff --git a/cli/command/volume/create_test.go b/cli/command/volume/create_test.go index f5c711bf8842..a37f9655b1d0 100644 --- a/cli/command/volume/create_test.go +++ b/cli/command/volume/create_test.go @@ -50,6 +50,7 @@ func TestVolumeCreateErrors(t *testing.T) { cmd.Flags().Set(key, value) } cmd.SetOut(io.Discard) + cmd.SetErr(io.Discard) assert.ErrorContains(t, cmd.Execute(), tc.expectedError) } } diff --git a/cli/command/volume/inspect_test.go b/cli/command/volume/inspect_test.go index bf1643752417..62c9c00aa83c 100644 --- a/cli/command/volume/inspect_test.go +++ b/cli/command/volume/inspect_test.go @@ -62,6 +62,7 @@ func TestVolumeInspectErrors(t *testing.T) { cmd.Flags().Set(key, value) } cmd.SetOut(io.Discard) + cmd.SetErr(io.Discard) assert.ErrorContains(t, cmd.Execute(), tc.expectedError) } } diff --git a/cli/command/volume/list_test.go b/cli/command/volume/list_test.go index dbed5a160629..45bbc955e471 100644 --- a/cli/command/volume/list_test.go +++ b/cli/command/volume/list_test.go @@ -43,6 +43,7 @@ func TestVolumeListErrors(t *testing.T) { cmd.Flags().Set(key, value) } cmd.SetOut(io.Discard) + cmd.SetErr(io.Discard) assert.ErrorContains(t, cmd.Execute(), tc.expectedError) } } diff --git a/cli/command/volume/prune_test.go b/cli/command/volume/prune_test.go index 7cfbad66b312..1bcafd57c840 100644 --- a/cli/command/volume/prune_test.go +++ b/cli/command/volume/prune_test.go @@ -49,6 +49,7 @@ func TestVolumePruneErrors(t *testing.T) { cmd.Flags().Set(key, value) } cmd.SetOut(io.Discard) + cmd.SetErr(io.Discard) assert.ErrorContains(t, cmd.Execute(), tc.expectedError) } } diff --git a/cli/command/volume/remove_test.go b/cli/command/volume/remove_test.go index 6f617f9ce027..61ac03578bca 100644 --- a/cli/command/volume/remove_test.go +++ b/cli/command/volume/remove_test.go @@ -33,6 +33,7 @@ func TestVolumeRemoveErrors(t *testing.T) { })) cmd.SetArgs(tc.args) cmd.SetOut(io.Discard) + cmd.SetErr(io.Discard) assert.ErrorContains(t, cmd.Execute(), tc.expectedError) } }