test(cmd): improve error handling in completion test writer close
All checks were successful
CI / Test (push) Successful in 33s
CI / Lint (push) Successful in 25s
CI / Build (push) Successful in 20s

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:
Greg Gauthier 2026-03-02 22:19:47 +00:00
parent d13731facb
commit 34789c50a5

View File

@ -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)