refactor(test): Restructure SAC tests#19507
Draft
rhybrillou wants to merge 3 commits intomaster-yann/ROX-33511/update-tree-nodes-on-duplicate-cluster-or-namespacefrom
Draft
refactor(test): Restructure SAC tests#19507rhybrillou wants to merge 3 commits intomaster-yann/ROX-33511/update-tree-nodes-on-duplicate-cluster-or-namespacefrom
rhybrillou wants to merge 3 commits intomaster-yann/ROX-33511/update-tree-nodes-on-duplicate-cluster-or-namespacefrom
Conversation
|
Skipping CI for Draft Pull Request. |
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Switching from a slice to a map for
testCasesmakes subtest execution order non-deterministic; consider keeping a slice (or storing the keys in a separate ordered slice) if stable ordering is useful for debugging and CI output. - The map key and
descfield in the test cases now diverge in at least one case (the Giedi=Prime test), which may cause confusion when reading failures; consider either droppingdescand relying on the map key or keeping them identical. - In
conversion_test.go, the test name string "empty ruleset result in an empty selector" has a subject-verb agreement typo; consider changing it back to "results" for clarity.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Switching from a slice to a map for `testCases` makes subtest execution order non-deterministic; consider keeping a slice (or storing the keys in a separate ordered slice) if stable ordering is useful for debugging and CI output.
- The map key and `desc` field in the test cases now diverge in at least one case (the Giedi=Prime test), which may cause confusion when reading failures; consider either dropping `desc` and relying on the map key or keeping them identical.
- In `conversion_test.go`, the test name string "empty ruleset result in an empty selector" has a subject-verb agreement typo; consider changing it back to "results" for clarity.
## Individual Comments
### Comment 1
<location path="pkg/sac/effectiveaccessscope/effective_access_scope_test.go" line_range="93-97" />
<code_context>
- testCases := []testCase{
- {
+ testCaseMap := map[string]testCase{
+ "no access scope includes nothing": {
desc: "no access scope includes nothing",
</code_context>
<issue_to_address>
**suggestion (testing):** Using a map for table-driven tests makes subtest execution order nondeterministic
Using a map here makes subtest execution order arbitrary, which can introduce flaky tests or harder-to-reproduce failures if anything relies on a stable order (fixtures, logs, benchmarks). Prefer keeping a slice for deterministic iteration, or derive and sort the map keys before ranging so subtest order is stable.
Suggested implementation:
```golang
testCases := []testCase{
{
desc: "no access scope includes nothing",
scopeDesc: `nil => { }`,
scopeStr: "",
detail: v1.ComputeEffectiveAccessScopeRequest_HIGH,
hasError: false,
},
{
desc: "empty access scope includes nothing",
scopeDesc: `∅ => { }`,
scopeStr: "",
```
1. Update any loop that iterates over `testCaseMap` to instead iterate over the ordered slice `testCases`, for example:
- Replace `for name, tc := range testCaseMap { t.Run(name, func(t *testing.T) { ... }) }`
- With `for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { ... }) }`
2. Remove all remaining map literal keys (e.g., `"some case name": {`) in the test case composite literal and convert them to plain elements `{ ... }` in the `[]testCase` slice.
3. Ensure there is no remaining reference to `testCaseMap` in the file; all should now refer to `testCases`.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
bc87973 to
4828305
Compare
4 tasks
Contributor
|
Images are ready for the commit at 4ba92ae. To use with deploy scripts, first |
This was referenced Mar 19, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master-yann/ROX-33511/update-tree-nodes-on-duplicate-cluster-or-namespace #19507 +/- ##
=============================================================================================================
+ Coverage 49.72% 49.73% +0.01%
=============================================================================================================
Files 2701 2701
Lines 203509 203560 +51
=============================================================================================================
+ Hits 101202 101248 +46
- Misses 94783 94788 +5
Partials 7524 7524
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
5 tasks
6773139 to
9602a55
Compare
4828305 to
19352e5
Compare
9602a55 to
cbc8794
Compare
19352e5 to
71b5c7d
Compare
cbc8794 to
100b9a2
Compare
71b5c7d to
bbf3578
Compare
100b9a2 to
be5bb18
Compare
6b0b180 to
7371a4e
Compare
f8b1524 to
84daa73
Compare
7371a4e to
4ba92ae
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR is part of the split of #19351
The split results in the following stack of PRs:
This PR aims at ease of debugging for the effective access scope unit tests (currently, the test cases are quite big, and a compacter expression of the expectations may help the troubleshooting process.
User-facing documentation
is updated ORupdate is not neededis created and is linked above ORis not neededTesting and quality
Automated testing
How I validated my change
CI run