Skip to content

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
master-yann/ROX-33511/test-refactor
Draft

refactor(test): Restructure SAC tests#19507
rhybrillou wants to merge 3 commits intomaster-yann/ROX-33511/update-tree-nodes-on-duplicate-cluster-or-namespacefrom
master-yann/ROX-33511/test-refactor

Conversation

@rhybrillou
Copy link
Contributor

@rhybrillou rhybrillou commented Mar 19, 2026

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

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

  • modified existing tests

How I validated my change

CI run

@openshift-ci
Copy link

openshift-ci bot commented Mar 19, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

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

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@rhacs-bot
Copy link
Contributor

rhacs-bot commented Mar 19, 2026

Images are ready for the commit at 4ba92ae.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.11.x-333-g7371a4ec3d.

@codecov
Copy link

codecov bot commented Mar 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.73%. Comparing base (84daa73) to head (4ba92ae).

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              
Flag Coverage Δ
go-unit-tests 49.73% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rhybrillou rhybrillou force-pushed the master-yann/ROX-33511/update-tree-nodes-on-duplicate-cluster-or-namespace branch from 6773139 to 9602a55 Compare March 19, 2026 17:31
@rhybrillou rhybrillou force-pushed the master-yann/ROX-33511/test-refactor branch from 4828305 to 19352e5 Compare March 19, 2026 17:31
@rhybrillou rhybrillou force-pushed the master-yann/ROX-33511/update-tree-nodes-on-duplicate-cluster-or-namespace branch from 9602a55 to cbc8794 Compare March 19, 2026 17:48
@rhybrillou rhybrillou force-pushed the master-yann/ROX-33511/test-refactor branch from 19352e5 to 71b5c7d Compare March 19, 2026 17:48
@rhybrillou rhybrillou force-pushed the master-yann/ROX-33511/update-tree-nodes-on-duplicate-cluster-or-namespace branch from cbc8794 to 100b9a2 Compare March 19, 2026 17:54
@rhybrillou rhybrillou force-pushed the master-yann/ROX-33511/test-refactor branch from 71b5c7d to bbf3578 Compare March 19, 2026 17:54
@rhybrillou rhybrillou force-pushed the master-yann/ROX-33511/update-tree-nodes-on-duplicate-cluster-or-namespace branch from 100b9a2 to be5bb18 Compare March 20, 2026 11:08
@rhybrillou rhybrillou force-pushed the master-yann/ROX-33511/test-refactor branch 2 times, most recently from 6b0b180 to 7371a4e Compare March 20, 2026 14:45
@rhybrillou rhybrillou force-pushed the master-yann/ROX-33511/update-tree-nodes-on-duplicate-cluster-or-namespace branch from f8b1524 to 84daa73 Compare March 20, 2026 15:28
@rhybrillou rhybrillou force-pushed the master-yann/ROX-33511/test-refactor branch from 7371a4e to 4ba92ae Compare March 20, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants