Repository navigation
test: add unit tests for WatchManifest in internal/pkg/platform - #831
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #831 +/- ##
==========================================
+ Coverage 80.54% 80.60% +0.06%
==========================================
Files 246 246
Lines 18899 18899
==========================================
+ Hits 15222 15234 +12
+ Misses 3677 3665 -12 ☔ 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! Pinning the manifest source error and the remote note covers the two branches most likely to regress.
One blocking comment on the "waits for the context" case, the other is optional 🙏
| } { | ||
| t.Run(name, func(t *testing.T) { | ||
| ctx, cancel := context.WithCancel(slackcontext.MockContext(t.Context())) | ||
| cancel() |
There was a problem hiding this comment.
🧪 issue (blocking): Since the context is canceled before the call, this case still passes with the <-ctx.Done() wait removed (I tried it). That wait matters: slack run exits on the first value from errChan. Could we start WatchManifest in a goroutine on a live context, check it hasn't returned after a short wait, then cancel and expect nil?
There was a problem hiding this comment.
Fixed in commit c7a650c, thanks for trying it without the wait! 🙇 The test now starts WatchManifest on a live context, checks it hasn't returned after 50ms, then cancels and expects nil. Removing the <-ctx.Done() wait now fails both cases.
| } | ||
| } | ||
|
|
||
| func Test_LocalServer_WatchManifest(t *testing.T) { |
There was a problem hiding this comment.
🧪 suggestion (non-blocking): The enabled path (paths, filter regex, w.Start) is still untested, leaving WatchManifest at 46% coverage. A test there would hang today since nothing closes the watcher when the context ends, so closing w on ctx.Done() could be a nice follow-up that makes it testable.
There was a problem hiding this comment.
Great idea, thanks! I'll close the watcher on ctx.Done() in a follow-up PR, with a test for the enabled path, so this one stays test-only.
WilliamBergamin
left a comment
There was a problem hiding this comment.
💯 @mwbrooks thanks! Running WatchManifest on a live context and checking it stays blocked until cancel now pins the wait that keeps slack run going. Nothing else from me 🚀
| } | ||
| select { | ||
| case err := <-errChan: | ||
| require.FailNow(t, "WatchManifest returned before the context ended", "err: %v", err) |
There was a problem hiding this comment.
💯 praise: Asserting no return before cancel() makes this fail if the <-ctx.Done() wait is dropped (I tried it), which is exactly the regression that would end slack run early.
|
Heads up @WilliamBergamin: #838 made a missing |
|
Thanks @WilliamBergamin for the thorough review and for trying it without the wait! 🙇 |
Changelog
N/A - adds tests only, with no user-facing changes.
Summary
This pull request adds unit tests for
WatchManifestininternal/pkg/platform/localserver.go, which had no test coverage. It is one in a series of small coverage PRs.Test_LocalServer_WatchManifesttointernal/pkg/platform/localserver_test.gowith cases for a manifest source read error, manifest watching turned off, and a remote manifest sourceinternal/pkg/platformcoverage from 56.7% to 58.5%Testing
go test ./internal/pkg/platform/... -run Test_LocalServer_WatchManifest -vand confirm the cases passRequirements