Skip to content

Skip an accept-risk case on network-restricted environment#1332

Open
hongkailiu wants to merge 1 commit intoopenshift:mainfrom
hongkailiu:guard-more
Open

Skip an accept-risk case on network-restricted environment#1332
hongkailiu wants to merge 1 commit intoopenshift:mainfrom
hongkailiu:guard-more

Conversation

@hongkailiu
Copy link
Member

@hongkailiu hongkailiu commented Mar 4, 2026

Summary by CodeRabbit

  • Tests
    • Added network-awareness utilities to detect restricted network environments and optionally skip affected tests.
    • Tests that rely on external service connectivity will now automatically skip when network access is limited.
    • Updated an accept-risks test to use the new skip behavior to avoid false failures in constrained environments.

@coderabbitai
Copy link

coderabbitai bot commented Mar 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 53c11e34-3b01-4c0d-8222-058c91b99d2c

📥 Commits

Reviewing files that changed from the base of the PR and between 2ca740b and d2026cb.

📒 Files selected for processing (2)
  • test/cvo/accept_risks.go
  • test/util/util.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/util/util.go
  • test/cvo/accept_risks.go

Walkthrough

Adds 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

Cohort / File(s) Summary
Test utilities
test/util/util.go
Adds accessible(url string) bool (HTTP GET with 5s timeout), NetworkRestricted() bool (checks reachability, e.g., http://google.com), and SkipIfNetworkRestricted() (Ginkgo test skip when network is restricted). Adds net/http usage.
Test guard
test/cvo/accept_risks.go
Inserts util.SkipIfNetworkRestricted() at the start of the "should work with accept risks" test and adds a comment documenting reliance on a public Fauxinnati API URL.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Test Structure And Quality ⚠️ Warning Test code lacks meaningful failure messages on many assertions, violating established codebase patterns for diagnostic clarity. Add descriptive failure messages to all assertions matching the pattern in test/cvo/cvo.go to improve test failure diagnostics.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding network-restricted environment detection to skip a test case that requires external network access.
Stable And Deterministic Test Names ✅ Passed The pull request does not introduce test names with dynamic or unstable content. The only modified test is titled 'should work with accept risks,' which is a static, descriptive string with no generated identifiers or varying values.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 4, 2026

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 4, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 54dc4ef and 2ca740b.

📒 Files selected for processing (2)
  • test/cvo/accept_risks.go
  • test/util/util.go


func NetworkRestricted() bool {
// TODO: Use a more precise mothed
return !accessible("http://google.com")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hongkailiu
Copy link
Member Author

/retest-required

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 6, 2026

@hongkailiu: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-agnostic-ovn-techpreview-serial d2026cb link true /test e2e-agnostic-ovn-techpreview-serial

Full PR test history. Your PR dashboard.

Details

Instructions 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant