Suppress intentional errLog output during tests
Tests that exercise error paths in errLog/warn were causing GitHub Actions to annotate test output with 'Error: R] ...' (GHA eats '[ERRO' from '[ERROR]' lines and surfaces the rest as workflow errors), making real failures hard to distinguish from expected behavior. - issues.go: route logIssue output through issueLogWriter (io.Writer, defaults to os.Stdout). errorCount/issues/notices recording is unchanged so tests still assert via errorCount. - testmain_test.go: TestMain sets issueLogWriter = io.Discard for the whole test binary. - issues_test.go: TestIssuesLogging temporarily redirects issueLogWriter to a bytes.Buffer (replacing os.Pipe stdout capture). go test -v ./... now contains zero stray '[ERROR]' lines; real test failures remain visible and 'go test' still exits non-zero on failure, failing the workflow. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+7
-11
@@ -12,27 +12,23 @@ func TestIssuesLogging(t *testing.T) {
|
||||
defer resetMocks()
|
||||
resetMocks()
|
||||
|
||||
// Capture stdout
|
||||
oldStdout := os.Stdout
|
||||
r, w, _ := os.Pipe()
|
||||
os.Stdout = w
|
||||
// Capture issue log output via the injectable writer.
|
||||
var buf bytes.Buffer
|
||||
oldWriter := issueLogWriter
|
||||
issueLogWriter = &buf
|
||||
defer func() { issueLogWriter = oldWriter }()
|
||||
|
||||
warn("something is deprecated")
|
||||
errLog("something failed")
|
||||
notice("please restart shell")
|
||||
|
||||
w.Close()
|
||||
os.Stdout = oldStdout
|
||||
|
||||
var buf bytes.Buffer
|
||||
io.Copy(&buf, r)
|
||||
output := buf.String()
|
||||
|
||||
if !strings.Contains(output, "[WARN] something is deprecated") {
|
||||
t.Errorf("stdout missing warning: %q", output)
|
||||
t.Errorf("output missing warning: %q", output)
|
||||
}
|
||||
if !strings.Contains(output, "[ERROR] something failed") {
|
||||
t.Errorf("stdout missing error: %q", output)
|
||||
t.Errorf("output missing error: %q", output)
|
||||
}
|
||||
|
||||
issuesMu.Lock()
|
||||
|
||||
Reference in New Issue
Block a user