refactor(tests): clean up captureStdout function and remove unused fmt import

Signed-off-by: Boris Bliznioukov <blib@mail.com>
This commit is contained in:
Boris Bliznioukov 2026-03-04 22:13:13 +01:00
parent 328e489356
commit 4bb4200ca0
No known key found for this signature in database

View file

@ -3,7 +3,6 @@ package tools
import ( import (
"bytes" "bytes"
"context" "context"
"fmt"
"os" "os"
"strings" "strings"
"sync" "sync"
@ -161,14 +160,20 @@ func captureStdout(t *testing.T, fn func()) string {
old := os.Stdout old := os.Stdout
os.Stdout = w os.Stdout = w
defer func() {
os.Stdout = old
_ = w.Close()
_ = r.Close()
}()
fn() fn()
w.Close() _ = w.Close()
os.Stdout = old
var buf bytes.Buffer var buf bytes.Buffer
buf.ReadFrom(r) if _, err := buf.ReadFrom(r); err != nil {
t.Fatal(err)
}
return buf.String() return buf.String()
} }
@ -265,6 +270,3 @@ func TestNewExecToolWithConfig_EnableDenyPatternsFalseWarning(t *testing.T) {
t.Errorf("expected warning in NewExecToolWithConfig output: %s", out) t.Errorf("expected warning in NewExecToolWithConfig output: %s", out)
} }
} }
// Suppress unused import lint for fmt (used by captureStdout indirectly).
var _ = fmt.Sprintf