refactor main and improve tests - #25
Conversation
PR Reviewer Guide 🔍(Review updated until commit 16f2032)Here are some key observations to aid the review process:
|
There was a problem hiding this comment.
Pull request overview
This PR refactors the CLI entrypoint by extracting option validation and request execution into smaller methods, adds more unit tests around request/verification behavior, and enhances build metadata injection (version + commit).
Changes:
- Refactor
mainflow intoOpt.verify(),Opt.BuildClient(), andOpt.run(), and extract request retry loops intorequest.go. - Add unit tests for option verification (
main_test.go) and request execution (request_test.go). - Update build to embed Git commit metadata and simplify Makefile build targets.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| writer.go | Simplifies buffer-cap logic using min() when appending to the capped writer buffer. |
| checker.go | Updates expected-status parsing to use strings.SplitSeq and adjusts header write error handling. |
| main.go | Refactors validation and run flow, adds commit metadata to version output, and changes flag parser options. |
| request.go | New file extracting runWaitFor / runRequest loops from main.go. |
| request_test.go | New tests covering request outcomes (success, status mismatch, body mismatch, wait-for behavior, timeouts). |
| main_test.go | New tests covering Opt.verify() validation and normalization behavior. |
| Makefile | Adds commit ldflag, simplifies build targets to go build package mode, adds lint target. |
Suppressed comments (1)
request.go:56
- Using time.After(opt.Interim) inside the retry loop allocates a fresh timer each iteration and cannot be stopped when ctx.Done() triggers, which is avoidable overhead in tight retry loops. Prefer time.NewTimer and stop/drain it on cancellation.
select {
case <-ctx.Done():
case <-time.After(opt.Interim):
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
Persistent review updated to latest commit dac0c6d |
|
Persistent review updated to latest commit 8f58720 |
PR Code Suggestions ✨Latest suggestions up to 8f58720 Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 8f58720
Suggestions up to commit e501ac2
|
…ctor-main-and-tests
|
Persistent review updated to latest commit b7f80de |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
|
Persistent review updated to latest commit 16f2032 |
PR Code Suggestions ✨No code suggestions found for the PR. |



PR Type
Enhancement, Tests, Bug fix
Description
Refactor
main.gointo focusedOptmethodsExtract request/wait loops into
request.goAdd unit tests for verify and request flows
Fix timer leak in retry loops
Diagram Walkthrough
flowchart LR main["_main"] --> verify["opt.verify"] verify --> build["opt.BuildClient"] build --> run["opt.run"] run --> decision{"WaitFor?"} decision -- "yes" --> wait["runWaitFor"] decision -- "no" --> req["runRequest"] wait --> request["opt.Request"] req --> requestFile Walkthrough
4 files
Use `strings.SplitSeq` and ignore `Write` errorsRefactor `_main` into `Opt` verify, build, and run methodsExtract request loops and fix timer cleanupReplace manual min logic with `min` builtin2 files
Add unit tests for `Opt.verify` validationsAdd unit tests for request and wait loops1 files
Embed git commit and add lint target