Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #860 +/- ##
==========================================
+ Coverage 80.65% 80.86% +0.20%
==========================================
Files 246 246
Lines 18837 18832 -5
==========================================
+ Hits 15193 15228 +35
+ Misses 3644 3604 -40 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
WilliamBergamin
left a comment
There was a problem hiding this comment.
🧪 Thanks @mwbrooks! Backdating a real file with Chtimes checks that cleanup actually runs, not just that the code paths execute.
Left a few comments, nothing blocking 🙏
|
|
||
| err := io.InitLogFile(ctx) | ||
| if tc.expectedErr { | ||
| assert.Error(t, err) |
There was a problem hiding this comment.
🧪 suggestion (non-blocking): Could the error case check the code, like update_test.go does? Right now any error passes it, including the log file failing to open. It needs the slackerror import.
| assert.Error(t, err) | |
| assert.Equal(t, slackerror.ErrContextValueNotFound, slackerror.ToSlackError(err).Code) |
| assert.Contains(t, string(logFile), sessionID) | ||
| assert.Contains(t, string(logFile), traceID) |
There was a problem hiding this comment.
🧪 suggestion (non-blocking): Could we match the labeled lines? A bare UUID would still match if the two labels were swapped.
| assert.Contains(t, string(logFile), sessionID) | |
| assert.Contains(t, string(logFile), traceID) | |
| assert.Contains(t, string(logFile), "SessionID: ["+sessionID+"]") | |
| assert.Contains(t, string(logFile), "Slack-CLI-TraceID: ["+traceID+"]") |
| assert.Contains(t, string(logFile), "------------------------------------") | ||
| assert.Contains(t, string(logFile), sessionID) | ||
| assert.Contains(t, string(logFile), traceID) | ||
| assert.NoFileExists(t, oldLogFilePath) |
There was a problem hiding this comment.
🧪 suggestion (non-blocking): Could we add two files that must survive cleanup: a 6-day-old slack-debug- log and an 8-day-old file without that prefix? Without them, the test still passes if the prefix or age check in deleteLogFilesOlderThanOneWeek is dropped.
There was a problem hiding this comment.
Added in commit 9319d07, great catch! Both files now have to survive cleanup.
| }{ | ||
| "writes the session details to the log file and removes week old logs": {}, | ||
| "returns an error when the trace ID is missing from the context": { | ||
| missingTraceID: true, |
There was a problem hiding this comment.
🔭 suggestion (non-blocking): This case shows that InitLogFile leaves the log file open when it returns early, because defer errorLogFile.Close() only runs at the end. Moving the defer right after os.OpenFile fixes it. Otherwise t.TempDir cleanup can fail on Windows. Fine here or as a follow-up.
There was a problem hiding this comment.
Good catch! I'll open a follow-up PR to move the defer so this one stays test-only.
Changelog
N/A - adds tests only, with no user-facing changes.
Summary
This pull request adds unit tests for
InitLogFileininternal/iostreams/logfile.go, which had no test coverage. It is one in a series of small coverage PRs.Test_IOStreams_InitLogFiletointernal/iostreams/logfile_test.gowith cases for the session details written to the log file, the cleanup of week-old logs, and a missing trace IDinternal/iostreamscoverage from 57.2% to 63.5%Testing
go test ./internal/iostreams/... -run Test_IOStreams_InitLogFile -vand confirm the cases passRequirements