test(cmd): improve error handling in completion test writer close
Handle potential errors when closing the pipe writer in TestCompletionCmd, and use a deferred anonymous function to ignore errors in defer.
This commit is contained in:
parent
d13731facb
commit
34789c50a5
@ -26,10 +26,12 @@ func TestCompletionCmd(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
os.Stdout = w
|
||||
defer w.Close()
|
||||
defer func() { _ = w.Close() }()
|
||||
cmd := &cobra.Command{}
|
||||
completionCmd.Run(cmd, []string{tt.shell})
|
||||
w.Close()
|
||||
if err := w.Close(); err != nil {
|
||||
t.Errorf("close: %v", err)
|
||||
}
|
||||
b, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user