Skip to content

ROSAENG-60113 | test(unit): add clusterrosa/hcp validator coverage#1243

Open
amandahla wants to merge 1 commit into
terraform-redhat:mainfrom
amandahla:ROSAENG-60113-unit-tests-4
Open

ROSAENG-60113 | test(unit): add clusterrosa/hcp validator coverage#1243
amandahla wants to merge 1 commit into
terraform-redhat:mainfrom
amandahla:ROSAENG-60113-unit-tests-4

Conversation

@amandahla

@amandahla amandahla commented Jul 3, 2026

Copy link
Copy Markdown
Member

Summary

  • Add unit tests for HCP cluster update validators and small pure helpers in provider/clusterrosa/hcp.
  • PR 4 of 6 in the ROSAENG-60113 unit-test coverage series.

Planned follow-up PRs

  1. provider/common/attrvalidators — merged (#1212)
  2. provider/clusterrosa/common + hcp/shared_vpc — merged (#1218)
  3. provider/common (root) — merged (#1231)
  4. provider/clusterrosa/hcp — untested validate* / small pure funcs — this PR
  5. provider/clusterrosa/classic — validators only (not CRUD)
  6. provider/proxyContains (optional, if still uncovered)

Detailed Description of the Issue

HCP cluster resource helpers for update-time validation (validateChannel*, validateNoImmutableAttChange, validateAutoNodeRoleARN) and small pure functions (getOcmVersionMinor, getAutoNodeMode, getAutoNodeRoleARN, shouldPatchProperties) had no direct unit tests.

Related Issues and PRs

Type of Change

  • feat - adds a new user-facing capability.
  • fix - resolves an incorrect behavior or bug.
  • docs - updates documentation only.
  • style - formatting or naming changes with no logic impact.
  • refactor - code restructuring with no behavior change.
  • test - adds or updates tests only.
  • chore - maintenance work (tooling, housekeeping, non-product code).
  • build - changes build system, packaging, or dependencies for build output.
  • ci - changes CI pipelines, jobs, or automation workflows.
  • perf - improves performance without changing intended behavior.

Previous Behavior

No unit tests covered HCP update validators or the listed pure helpers.

Behavior After This Change

Table-driven Ginkgo unit tests validate channel/version mutual-exclusion rules, immutability checks, auto-node role ARN validation, and property-patch logic. No production code changes.

Intentional skips (e2e/subsystem checklist)

  • validateUpgrade — requires OCM client; defer to subsystem/e2e upgrade flows.
  • Full immutability matrixvalidateNoImmutableAttChange has representative unit coverage; subsystem immutability tests cover resource wiring.
  • CRUD paths (Create/Read/Update/Delete) — out of scope for this PR series entry.

How to Test (Step-by-Step)

Preconditions

  • Go toolchain and repo dependencies installed.

Test Steps

  1. go test ./provider/clusterrosa/hcp -count=1
  2. make pre-push-checks

Expected Results

  • All provider/clusterrosa/hcp specs pass.
  • Pre-push checks pass.

Proof of the Fix

  • Logs/CLI output: local make pre-push-checks (9/9 passed) and CodeRabbit local review (0 findings).

Breaking Changes

  • No breaking changes
  • Yes, this PR introduces a breaking change (describe impact and migration plan below)

Breaking Change Details / Migration Plan

N/A

Developer Verification Checklist

  • Commit subject/title follows [JIRA-TICKET] | [TYPE][(scope)][!]: <MESSAGE>.
  • PR description clearly explains both what changed and why.
  • Relevant Jira/GitHub issues and related PRs are linked.
  • make install-hooks has been run in this clone.
  • make pre-push-checks passes.
  • Documentation was added/updated where appropriate.
  • Any risk, limitation, or follow-up work is documented.

Testing (check all that apply; use N/A when not relevant)

  • N/A — no provider resource/data source or provider/ / internal/ logic changes.
  • New or changed resource / data source — subsystem test added or updated under subsystem/classic/ or subsystem/hcp/.
  • New or changed validation, plan modifiers, or helpers — unit tests in the same package (*_test.go), or a subsystem negative test when integration-only (not both for the same cases unless a wiring smoke test is needed).
  • Schema / config validation — unit test and/or subsystem test expecting plan/apply failure (one primary layer per rule; see CONTRIBUTING.md).
  • make check-subsystem-registry passes.
  • I manually tested the change when behavior is user-visible.

Made with Cursor

Summary by CodeRabbit

  • Tests
    • Added a Ginkgo/Golang test suite for cluster ROSA HCP validators and helpers.
    • Verifies update validation rules across channel, channel group, and version change combinations.
    • Checks immutable-field validation and expected error messaging when names change.
    • Adds coverage for auto-node role ARN validation (valid, null/unknown, and malformed/invalid inputs).
    • Includes tests for version/minor parsing and property patching behavior, including default drift scenarios.

@openshift-ci

openshift-ci Bot commented Jul 3, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign jerichokeyne for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 24b671c0-3213-4aa1-ac41-1495844b6d11

📥 Commits

Reviewing files that changed from the base of the PR and between 3adbc52 and 44d2214.

📒 Files selected for processing (1)
  • provider/clusterrosa/hcp/validators_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • provider/clusterrosa/hcp/validators_test.go

Walkthrough

Adds a new Ginkgo test suite for provider/clusterrosa/hcp covering update validators, immutable attribute checks, auto-node ARN validation, helper extraction functions, version parsing, and property patch detection. No production code or exported entities are modified.

Changes

HCP Validators Test Suite

Layer / File(s) Summary
Baseline test state helper
provider/clusterrosa/hcp/validators_test.go
Adds cloneBasicState() producing a baseline ClusterRosaHcpState with null/default Framework values and fixed version 4.14.0 for reuse across tests.
Channel/version update validation tests
provider/clusterrosa/hcp/validators_test.go
Table-driven tests for validateChannelAndChannelGroupChanges, validateChannelGroupAndVersionChanges, and validateChannelAndVersionChanges, verifying independent changes are allowed and paired changes produce errors.
Immutable attribute and auto-node ARN validation tests
provider/clusterrosa/hcp/validators_test.go
Tests validateNoImmutableAttChange for Name-change errors and validateAutoNodeRoleARN() for null/unknown, valid ARN, and invalid ARN inputs.
Helper function tests
provider/clusterrosa/hcp/validators_test.go
Tests getAutoNodeMode, getAutoNodeRoleARN, getOcmVersionMinor() version parsing, and shouldPatchProperties() patch-detection scenarios.

Estimated code review effort: 2 (Simple) | ~12 minutes

Suggested reviewers: jerichokeyne, olucasfreitas

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: added clusterrosa/hcp validator test coverage.
Description check ✅ Passed The description covers the template sections with summary, issue context, related links, change type, testing, proof, and checklist items.
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.
Pr Checklist Claims Vs Evidence (Generic) ✅ Passed Title format matches, diff is test-only, links/risk docs are present. Command-run checklist items are unverified but not contradicted by the diff.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@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)
provider/clusterrosa/hcp/validators_test.go (2)

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

Consider extracting a shared harness for the three near-identical DescribeTable blocks.

validateChannelAndChannelGroupChanges (Lines 48-86), validateChannelGroupAndVersionChanges (Lines 88-135), and validateChannelAndVersionChanges (Lines 137-175) share the same clone/mutate/assert scaffolding, differing only in the mutate entries and the function under test. A small generic helper (e.g., accepting the validator func as a parameter) would remove this duplication.

♻️ Example shared harness
func runUpdateValidatorTable(
	validate func(state, plan *ClusterRosaHcpState) diag.Diagnostics,
	mutate func(state, plan *ClusterRosaHcpState),
	expectedErr bool,
) {
	state := cloneBasicState()
	plan := cloneBasicState()
	mutate(state, plan)

	diags := validate(state, plan)
	Expect(diags.HasError()).To(Equal(expectedErr))
}
🤖 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 `@provider/clusterrosa/hcp/validators_test.go` around lines 48 - 175, The three
DescribeTable blocks repeat the same clone/mutate/assert setup, so extract a
shared table harness and reuse it across
`validateChannelAndChannelGroupChanges`,
`validateChannelGroupAndVersionChanges`, and `validateChannelAndVersionChanges`.
Add a small helper that accepts the validator function plus the mutate callback
and expected error flag, then have each table entry call that helper instead of
duplicating `cloneBasicState`, `mutate`, and `Expect(diags.HasError())` logic.

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

Missing "state version null" entry, mirroring the sibling test suite.

validateChannelGroupAndVersionChanges tests include an entry for "version set when state version is null" (Lines 125-133) because the source function treats a null-state/non-null-plan version as changed (per validateChannelGroupAndVersionChanges in resource.go). validateChannelAndVersionChanges implements the identical null-handling branch but this test table has no equivalent entry, leaving that branch uncovered here.

As per path instructions, "Ensure assertions cover behavior changes, not only happy paths."

✅ Suggested additional entry
Entry("version set when state version is null -> counts as version change with channel",
	func(state, plan *ClusterRosaHcpState) {
		state.Channel = types.StringValue("stable")
		state.Version = types.StringNull()
		plan.Channel = types.StringValue("candidate")
		plan.Version = types.StringValue("4.15.0")
	},
	true,
),
🤖 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 `@provider/clusterrosa/hcp/validators_test.go` around lines 137 - 175, The
Channel and version update validation table is missing coverage for the
null-state version change branch. Add an Entry to the
validateChannelAndVersionChanges DescribeTable that mirrors the sibling
validateChannelGroupAndVersionChanges case by setting state.Version to
types.StringNull() while plan.Version is non-null and asserting the expected
error behavior when channel changes alongside it. Use the existing
validateChannelAndVersionChanges, cloneBasicState, and ClusterRosaHcpState
symbols to keep the new case aligned with the current table structure.

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 `@provider/clusterrosa/hcp/validators_test.go`:
- Around line 48-175: The three DescribeTable blocks repeat the same
clone/mutate/assert setup, so extract a shared table harness and reuse it across
`validateChannelAndChannelGroupChanges`,
`validateChannelGroupAndVersionChanges`, and `validateChannelAndVersionChanges`.
Add a small helper that accepts the validator function plus the mutate callback
and expected error flag, then have each table entry call that helper instead of
duplicating `cloneBasicState`, `mutate`, and `Expect(diags.HasError())` logic.
- Around line 137-175: The Channel and version update validation table is
missing coverage for the null-state version change branch. Add an Entry to the
validateChannelAndVersionChanges DescribeTable that mirrors the sibling
validateChannelGroupAndVersionChanges case by setting state.Version to
types.StringNull() while plan.Version is non-null and asserting the expected
error behavior when channel changes alongside it. Use the existing
validateChannelAndVersionChanges, cloneBasicState, and ClusterRosaHcpState
symbols to keep the new case aligned with the current table structure.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 7dad0353-c32f-49ba-a354-d148ff516d35

📥 Commits

Reviewing files that changed from the base of the PR and between 8247260 and 3adbc52.

📒 Files selected for processing (1)
  • provider/clusterrosa/hcp/validators_test.go

Cover HCP update validators, auto_node role ARN validation, and small
pure helpers used during cluster updates without exercising CRUD paths.

Signed-off-by: Amanda Hager Lopes de Andrade Katz <amanda.katz@redhat.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Amanda Hager Lopes de Andrade Katz <amanda.katz@redhat.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@amandahla amandahla force-pushed the ROSAENG-60113-unit-tests-4 branch from 3adbc52 to 44d2214 Compare July 3, 2026 18:17
@openshift-ci

openshift-ci Bot commented Jul 3, 2026

Copy link
Copy Markdown

@amandahla: 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/security 44d2214 link false /test security

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant