Skip an accept-risk case on network-restricted environment#1332
Skip an accept-risk case on network-restricted environment#1332hongkailiu wants to merge 1 commit intoopenshift:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: openshift/coderabbit/.coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughAdds network-availability checks to test utilities and calls the new test guard at the start of the "accept risks" test to optionally skip it when external network access is unavailable. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hongkailiu The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
test/util/util.go (1)
140-151: Consider idiomatic Go pattern for HTTP response handling.The defer with nil checks works but the conventional Go pattern is to check the error first, then defer the close. This improves readability.
♻️ Suggested idiomatic pattern
func accessible(url string) bool { client := &http.Client{ Timeout: 5 * time.Second, } resp, err := client.Get(url) - defer func() { - if resp != nil && resp.Body != nil { - _ = resp.Body.Close() - } - }() - return err == nil + if err != nil { + return false + } + defer resp.Body.Close() + return true }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/util/util.go` around lines 140 - 151, The accessible function currently defers closing resp.Body before checking the error; change it to call client.Get(url), check if err != nil and return false immediately, then defer closing resp.Body (resp.Body.Close()) and finally return true. Update the function accessible to follow the idiomatic pattern: perform resp, err := client.Get(url); if err != nil { return false }; defer resp.Body.Close(); return true.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@test/cvo/accept_risks.go`:
- Around line 65-66: Fix the typo in the comment ("replies" → "relies") and
replace the generic network check util.SkipIfNetworkRestricted() with a precise
URL accessibility check for the actual endpoint by adding a helper like
util.SkipIfURLNotAccessible(url string) (or util.SkipIfFauxinnatiUnavailable)
that attempts to reach util.FauxinnatiAPIURL and calls g.Skipf when unreachable;
then update the test in accept_risks.go to call
util.SkipIfURLNotAccessible(util.FauxinnatiAPIURL) instead of
util.SkipIfNetworkRestricted() so the skip reflects the real dependency.
In `@test/util/util.go`:
- Around line 153-156: Fix the typo in the comment inside the NetworkRestricted
function: change "mothed" to "method" in the TODO comment above
NetworkRestricted() (the function name and accessible() call are present in the
snippet) so the comment reads "TODO: Use a more precise method". Ensure only the
comment text is updated and no code logic is changed.
---
Nitpick comments:
In `@test/util/util.go`:
- Around line 140-151: The accessible function currently defers closing
resp.Body before checking the error; change it to call client.Get(url), check if
err != nil and return false immediately, then defer closing resp.Body
(resp.Body.Close()) and finally return true. Update the function accessible to
follow the idiomatic pattern: perform resp, err := client.Get(url); if err !=
nil { return false }; defer resp.Body.Close(); return true.
ℹ️ Review info
Run configuration
Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 623c1887-ee86-400b-969c-f47fc8c1f880
📒 Files selected for processing (2)
test/cvo/accept_risks.gotest/util/util.go
|
|
||
| func NetworkRestricted() bool { | ||
| // TODO: Use a more precise mothed | ||
| return !accessible("http://google.com") |
There was a problem hiding this comment.
oc does a similar thing.
https://github.com/openshift/oc/blob/2bd770b8f00d1f6b6a49afe8c5ee411665f2e308/test/e2e/util.go#L1008
|
/retest-required |
|
@hongkailiu: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
Summary by CodeRabbit