Skip to content

HYPERFLEET-1162 - test: Update resource_references delete test#302

Merged
openshift-merge-bot[bot] merged 1 commit into
openshift-hyperfleet:mainfrom
ma-hill:HYPERFLEET-1162
Jul 21, 2026
Merged

HYPERFLEET-1162 - test: Update resource_references delete test#302
openshift-merge-bot[bot] merged 1 commit into
openshift-hyperfleet:mainfrom
ma-hill:HYPERFLEET-1162

Conversation

@ma-hill

@ma-hill ma-hill commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Refactors the resource reference deletion integration tests into organized subtests and adds coverage for previously untested scenarios. The delete tests were standalone functions with duplicated setup; this consolidates them under TestResourceReferences_Delete with t.Run() subtests and adds an unreferenced-target test and an end-to-end source-then-target deletion flow.

HYPERFLEET-1162

  • Which is specific to WIFConfig deletion protection, but IMO this test should suffice since it is a generic mapping of Source->Target

Changes

  • Refactored standalone delete test functions (TestResourceReferences_DeleteTargetWhileReferenced, TestResourceReferences_DeleteSourceSucceeds, TestResourceReferences_ForceDeleteReferencedTarget) into t.Run() subtests under TestResourceReferences_Delete
  • Added UnreferencedTarget_Succeeds subtest verifying that a target with no references can be deleted and is hard-deleted from the database
  • Added ContainSubstring("referenced by RefSource") assertion to the 409 conflict test, validating the error message identifies the referencing entity
  • Extended source deletion test (SourceAndTarget_Succeeds) to also delete the target after the source is removed, verifying the full lifecycle of reference cleanup
  • Added suffix helper closure for cleaner unique name generation across subtests

Test Plan

  • make test-all passes
  • make lint passes

@openshift-ci

openshift-ci Bot commented Jul 17, 2026

Copy link
Copy Markdown

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

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Soft deletion now clears outbound resource references before conditions are recomputed and saved. Integration coverage consolidates deletion scenarios into subtests for unreferenced, referenced, cascaded, and force-deleted resources. Additional coverage verifies descriptor setup for wif_config references and clearing optional references through an empty patch map.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: mliptak0, rh-amarin, kuudori

🚥 Pre-merge checks | ✅ 11
✅ Passed checks (11 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Sec-02: Secrets In Log Output ✅ Passed No non-test Go log/print statements include token/password/credential/secret; the resource.go change adds no logging. CWE-532.
No Hardcoded Secrets ✅ Passed No hardcoded secrets found; the diff adds tests and a soft-delete ref clear only, with no apiKey/secret/token/password literals, creds-in-URL, or long base64.
No Weak Cryptography ✅ Passed No banned primitives or secret comparisons added in the diff; touched files contain no crypto/md5, crypto/des, crypto/rc4, SHA1-for-security, ECB, or CWE-327/328/916 patterns.
No Injection Vectors ✅ Passed No CWE-89/78/79/502 injection pattern appears in the non-test diff; the only service change is ReplaceReferences(ctx, resource.ID, nil).
No Privileged Containers ✅ Passed No manifests, Helm templates, or Dockerfiles changed; grep found no privileged settings in touched files. CWE-250/269 not introduced.
No Pii Or Sensitive Data In Logs ✅ Passed No new logging/print statements in the touched files; only tests and delete-path code changed, with no PII or sensitive data emitted (CWE-532).
Title check ✅ Passed The title is concise and accurately reflects the main change: resource_references delete test updates.
Description check ✅ Passed The description matches the changeset and correctly describes the test refactor and added coverage.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

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

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are limited based on label configuration.

🚫 Excluded labels (none allowed) (2)
  • do-not-merge/work-in-progress
  • do-not-merge/hold

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 047faa26-3c59-47dd-a1db-84c405718c8a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

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

@ma-hill ma-hill changed the title HYPERFLEET-1162 - test: Add WIFConfig deletion protection for references HYPERFLEET-1162 - test: Update resource_references delete test Jul 17, 2026
@ma-hill
ma-hill marked this pull request as ready for review July 17, 2026 14:29
@openshift-ci
openshift-ci Bot requested review from mliptak0 and rh-amarin July 17, 2026 14:29

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
test/integration/resource_references_test.go (2)

434-440: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use the suffix helper for consistent unique-name generation.

TestResourceReferences_PatchClearOptionalRefs inlines fmt.Sprintf("target-clropt-%s", uuid.NewString()[:8]) and fmt.Sprintf("optsource-clr-%s", uuid.NewString()[:8]) instead of reusing the suffix closure pattern from TestResourceReferences_Delete. Extracting suffix to a package-level helper would eliminate this duplication.

♻️ Suggested extraction
+func refSuffix(label string) string {
+	return fmt.Sprintf("%s-%s", label, uuid.NewString()[:8])
+}

Then use refSuffix("target-clropt") and refSuffix("optsource-clr") in both tests.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/integration/resource_references_test.go` around lines 434 - 440, Extract
the shared unique-name generation into a package-level refSuffix helper,
following the suffix closure pattern used by TestResourceReferences_Delete.
Update TestResourceReferences_PatchClearOptionalRefs to use
refSuffix("target-clropt") and refSuffix("optsource-clr") instead of inline
fmt.Sprintf and UUID slicing, and reuse the helper in both tests.

Source: Path instructions


268-268: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add descriptive messages to bare assertions.

Lines 268, 319, and 327 have assertions without failure messages (Expect(svcErr.HTTPCode).To(Equal(409)), Expect(getErr).ToNot(BeNil())). Per HyperFleet testing standards, assertions should include descriptive messages to aid debugging. As per coding guidelines, assertions include descriptive messages — no bare t.Error(err).

♻️ Suggested messages
-		Expect(svcErr.HTTPCode).To(Equal(409))
+		Expect(svcErr.HTTPCode).To(Equal(409), "referenced target delete should return 409 conflict")
-		Expect(svcErr.HTTPCode).To(Equal(409))
+		Expect(svcErr.HTTPCode).To(Equal(409), "regular delete of referenced target should return 409")
-		Expect(getErr).ToNot(BeNil())
+		Expect(getErr).ToNot(BeNil(), "target should not be retrievable after force-delete")

Also applies to: 319-319, 327-327

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/integration/resource_references_test.go` at line 268, Update the
assertions at the affected resource-reference test cases, including the checks
around svcErr.HTTPCode and getErr, to include concise descriptive failure
messages explaining the expected HTTP status or error condition. Preserve the
existing matchers and expected values.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@test/integration/resource_references_test.go`:
- Around line 434-440: Extract the shared unique-name generation into a
package-level refSuffix helper, following the suffix closure pattern used by
TestResourceReferences_Delete. Update
TestResourceReferences_PatchClearOptionalRefs to use refSuffix("target-clropt")
and refSuffix("optsource-clr") instead of inline fmt.Sprintf and UUID slicing,
and reuse the helper in both tests.
- Line 268: Update the assertions at the affected resource-reference test cases,
including the checks around svcErr.HTTPCode and getErr, to include concise
descriptive failure messages explaining the expected HTTP status or error
condition. Preserve the existing matchers and expected values.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: bd660b9b-2c6d-4c86-8d6a-b6bc607f73a2

📥 Commits

Reviewing files that changed from the base of the PR and between 5aefe87 and 0fd525b.

📒 Files selected for processing (1)
  • test/integration/resource_references_test.go
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • openshift-hyperfleet/architecture (manual)
  • openshift-hyperfleet/hyperfleet-api (manual)
  • openshift-hyperfleet/hyperfleet-sentinel (manual)
  • openshift-hyperfleet/hyperfleet-adapter (manual)
  • openshift-hyperfleet/hyperfleet-broker (manual)

@hyperfleet-ci-bot

hyperfleet-ci-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

Risk Score: 2 — risk/medium

Signal Detail Points
PR size 210 lines (>200) +1
Sensitive paths none +0
Test coverage Missing tests for: pkg/services +1

Computed by hyperfleet-risk-scorer

Comment thread test/integration/resource_references_test.go Outdated
Comment thread test/integration/resource_references_test.go Outdated
@ma-hill
ma-hill marked this pull request as draft July 17, 2026 20:13
@ma-hill

ma-hill commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

/test

@ma-hill

ma-hill commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

/test all

@ma-hill
ma-hill marked this pull request as ready for review July 20, 2026 15:18
@openshift-ci
openshift-ci Bot requested a review from crizzo71 July 20, 2026 15:18
@kuudori

kuudori commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci

openshift-ci Bot commented Jul 21, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kuudori

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-merge-bot
openshift-merge-bot Bot merged commit 99c22d1 into openshift-hyperfleet:main Jul 21, 2026
9 checks passed
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.

3 participants