feat: save failed test logs and truncate WAF log when using --log-failures-only#626
feat: save failed test logs and truncate WAF log when using --log-failures-only#626
Conversation
|
@copilot fix the windows tests: https://github.com/coreruleset/go-ftw/actions/runs/24629480025/job/72128596838?pr=626 |
Fixed in a76dae6. The |
…nabled When the --show-failures-only flag is enabled, after each test stage: - If the test failed: append the WAF log lines (between markers) to a failed-tests.log file placed next to the WAF error log - Always truncate the WAF error log to zero bytes This leaves the WAF error log empty at the end of the run, and failed-tests.log (if it exists) contains only entries from failed tests. Changes: - waflog/waflog.go: open log file with O_RDWR for truncation support; add TruncateLogFile() and GetMarkedLines() public methods - runner/run.go: add appendToFailedTestsLog() and failedTestsLogFilePath() helpers; invoke log management after each stage in RunStage() - runner/testdata/TestShowFailuresOnly.yaml: test data for new test - runner/run_test.go: add TestShowFailuresOnly and TestFailedTestsLogFilePath - waflog/waflog_test.go: add TestTruncateLogFile, TestGetMarkedLinesWithoutMarkers, TestGetMarkedLinesWithOnlyStartMarker Agent-Logs-Url: https://github.com/coreruleset/go-ftw/sessions/8fe4ac6a-0744-4a39-a54f-ddf89c6fbf20 Co-authored-by: fzipi <3012076+fzipi@users.noreply.github.com>
- Use defer for test cleanup in TestShowFailuresOnly - Add comment explaining why os.O_CREATE is intentionally omitted Agent-Logs-Url: https://github.com/coreruleset/go-ftw/sessions/8fe4ac6a-0744-4a39-a54f-ddf89c6fbf20 Co-authored-by: fzipi <3012076+fzipi@users.noreply.github.com>
…atibility Agent-Logs-Url: https://github.com/coreruleset/go-ftw/sessions/08a5eea8-4782-49cf-9ee5-d48e4a5bbb00 Co-authored-by: fzipi <3012076+fzipi@users.noreply.github.com>
a76dae6 to
cf4861e
Compare
|
@copilot maybe adding a new flag instead, called |
Agent-Logs-Url: https://github.com/coreruleset/go-ftw/sessions/72d2b039-5b63-421d-9a0a-b95e36444114 Co-authored-by: fzipi <3012076+fzipi@users.noreply.github.com>
Done in 28666e9. Added a new |
…lures-only Agent-Logs-Url: https://github.com/coreruleset/go-ftw/sessions/72d2b039-5b63-421d-9a0a-b95e36444114 Co-authored-by: fzipi <3012076+fzipi@users.noreply.github.com>
When running tests, the WAF error log accumulates entries for every test—passing and failing—making CI artifact collection noisy. This adds a new
--log-failures-onlyflag that enables per-stage log management so only failed test entries are retained.Behavior
After each test stage, when
--log-failures-onlyis active (non-cloud mode only):failed-tests.log(placed alongside the WAF error log)Result: WAF error log is empty at run end;
failed-tests.logexists only if something failed and contains only those entries.Changes
waflog/waflog.goopenLogFile: switched fromos.Open(read-only) toos.OpenFile(…, os.O_RDWR, …)to enable truncation.O_CREATEis intentionally omitted—the WAF must create the log before go-ftw starts.TruncateLogFile(): truncates log to 0 bytes and seeks back to start.GetMarkedLines(): public, safe wrapper aroundgetMarkedLines()—returnsnilwhen markers are unset instead of callinglog.Fatal.runner/run.gofailedTestsLogFilePath(logFilePath): derives<dir>/failed-tests.logfrom the WAF log path.appendToFailedTestsLog(logFilePath, logLines): opensfailed-tests.login append/create mode and writes the marked lines.RunStage: calls the above afterdisplayResultwhenLogFailuresOnly && notRunningInCloudMode.config/runner_config.goandrunner/types.goLogFailuresOnly boolfield toRunnerConfigandTestRunContext.cmd/run/run.go--log-failures-onlyflag (independent of--show-failures-only).