Skip to content

CNTRLPLANE-3899: Add shared cmd/ unit tests for create nodepool agent - #9162

Merged
openshift-merge-bot[bot] merged 1 commit into
openshift:mainfrom
mehabhalodiya:shared_nodepool
Aug 20, 2026
Merged

CNTRLPLANE-3899: Add shared cmd/ unit tests for create nodepool agent#9162
openshift-merge-bot[bot] merged 1 commit into
openshift:mainfrom
mehabhalodiya:shared_nodepool

Conversation

@mehabhalodiya

@mehabhalodiya mehabhalodiya commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

The Agent nodepool create has its own platform-specific options and validation logic that is completely untested.

What this PR does / why we need it:

New file: cmd/nodepool/agent/create_test.go

Tests added (4 functions, 7 subtests):

  1. TestCreateNodePool_When_flags_are_parsed_it_should_generate_correct_nodepool — fixture-based test with 3 cases (empty/single/multi label selector), matching the exact function name from the acceptance criteria
  2. TestUpdateNodePool_When_label_selector_is_parsed_it_should_set_agent_platform — validates the parsed LabelSelector struct for equality-based, set-based, and empty selectors
  3. TestUpdateNodePool_When_invalid_label_selector_is_provided_it_should_panic — tests the validation path (panic on invalid selector)
  4. TestType_it_should_return_AgentPlatform — verifies Type() returns AgentPlatform

Which issue(s) this PR fixes:

Fixes https://redhat.atlassian.net/browse/CNTRLPLANE-3899

Special notes for your reviewer:

Checklist:

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

Summary by CodeRabbit

  • Tests
    • Added coverage for configuring agent label selectors through the node pool creation command.
    • Added validation for empty, exact-match, set-based (notin), and invalid label selectors.
    • Added coverage confirming the agent platform type is correctly identified.
    • Verified that the node pool creation command is assembled with the expected configuration and behavior.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jul 29, 2026
@openshift-ci-robot

openshift-ci-robot commented Jul 29, 2026

Copy link
Copy Markdown

@mehabhalodiya: This pull request references CNTRLPLANE-3899 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "5.0.0" version, but no target version was set.

Details

In response to this:

The Agent nodepool create has its own platform-specific options and validation logic that is completely untested.

What this PR does / why we need it:

New file: cmd/nodepool/agent/create_test.go

Tests added (4 functions, 7 subtests):

  1. TestCreateNodePool_When_flags_are_parsed_it_should_generate_correct_nodepool — fixture-based test with 3 cases (empty/single/multi label selector), matching the exact function name from the acceptance criteria
  2. TestUpdateNodePool_When_label_selector_is_parsed_it_should_set_agent_platform — validates the parsed LabelSelector struct for equality-based, set-based, and empty selectors
  3. TestUpdateNodePool_When_invalid_label_selector_is_provided_it_should_panic — tests the validation path (panic on invalid selector)
  4. TestType_it_should_return_AgentPlatform — verifies Type() returns AgentPlatform

Which issue(s) this PR fixes:

Fixes https://redhat.atlassian.net/browse/CNTRLPLANE-3899

Special notes for your reviewer:

Checklist:

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

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 openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

An error occurred during the review process. Please try again later.

📝 Walkthrough

Walkthrough

Refactored agent nodepool create command construction so NewCreateCommand wires RunE using the returned platform options. Added tests for command configuration, agentLabelSelector parsing, label-selector conversion, invalid selector handling, fixture-based platform generation, and AgentPlatformCreateOptions.Type().

Suggested reviewers: cblecker

🚥 Pre-merge checks | ✅ 11
✅ Passed checks (11 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the addition of unit tests for the agent nodepool create command, which is the main pull request change.
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.
Stable And Deterministic Test Names ✅ Passed All changed test and subtest titles are static literals; no Ginkgo titles, generated identifiers, timestamps, nodes, namespaces, IPs, or runtime interpolation appear.
Test Structure And Quality ✅ Passed The added tests use standard testing, not Ginkgo; each subtest targets one behavior, creates no cluster resources, has no waits, uses diagnostic failures, fixtures, and repository-matching patterns.
Topology-Aware Scheduling Compatibility ✅ Passed The patch changes only the Agent nodepool CLI helper, unit tests, and fixtures; it adds no deployments, controllers, or topology-related scheduling constraints.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed Changed tests use Go testing.T/t.Run, not Ginkgo e2e; changed Go and YAML files contain no IPv4 literals, IP parsing, URLs, or external connectivity.
No-Weak-Crypto ✅ Passed The patch only adds nodepool command wiring, label-selector tests, and fixtures; it introduces no weak crypto algorithms, crypto APIs, custom crypto, or secret comparisons.
Container-Privileges ✅ Passed The pull request changes two Go files and three label-selector fixtures; searches found no privileged, hostPID/hostNetwork/hostIPC, SYS_ADMIN, securityContext, or root settings.
No-Sensitive-Data-In-Logs ✅ Passed The PR adds no production logging and contains only benign test selectors; the existing panic message was unchanged and no passwords, tokens, PII, hostnames, or customer data were added.
✨ 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
Contributor

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)
cmd/nodepool/agent/create_test.go (1)

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

Use the required test-description format consistently.

  • cmd/nodepool/agent/create_test.go#L24-L37: rename each table case to “When … it should …”.
  • cmd/nodepool/agent/create_test.go#L78-L105: rename each table case to “When … it should …”.
  • cmd/nodepool/agent/create_test.go#L158-L158: rename the test to include a “When … it should …” clause.

As per coding guidelines, “Always use "When ... it should ..." format for describing test cases when creating unit 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 `@cmd/nodepool/agent/create_test.go` around lines 24 - 37, Rename every
table-driven test case in cmd/nodepool/agent/create_test.go at lines 24-37 and
78-105 to consistently follow the “When … it should …” format, describing the
setup and expected behavior. Rename the test at line 158 to include the same
“When … it should …” clause; no behavioral changes are needed.

Source: Coding guidelines

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

Inline comments:
In `@cmd/nodepool/agent/create_test.go`:
- Around line 135-155: Update
TestUpdateNodePool_When_invalid_label_selector_is_provided_it_should_panic to
capture the error returned by AgentPlatformCreateOptions.UpdateNodePool instead
of discarding it, and include that error in the failure report when recover
returns nil; preserve the existing panic assertion behavior.
- Around line 43-51: Update the test around NewCreateCommand so it uses the
AgentPlatformCreateOptions instance wired by the command instead of constructing
a separate instance and manually copying agentLabelSelector. Ensure the test
parses the bound Cobra flags and validates the resulting command options,
exercising NewCreateCommand’s actual flag wiring.

---

Nitpick comments:
In `@cmd/nodepool/agent/create_test.go`:
- Around line 24-37: Rename every table-driven test case in
cmd/nodepool/agent/create_test.go at lines 24-37 and 78-105 to consistently
follow the “When … it should …” format, describing the setup and expected
behavior. Rename the test at line 158 to include the same “When … it should …”
clause; no behavioral changes are needed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Enterprise

Run ID: 3dfa70b5-073b-4694-8c14-1a74f79e06d0

📥 Commits

Reviewing files that changed from the base of the PR and between 845e625 and 8c36439.

⛔ Files ignored due to path filters (3)
  • cmd/nodepool/agent/testdata/zz_fixture_TestCreateNodePool_When_flags_are_parsed_it_should_generate_correct_nodepool_empty_label_selector.yaml is excluded by !**/testdata/**
  • cmd/nodepool/agent/testdata/zz_fixture_TestCreateNodePool_When_flags_are_parsed_it_should_generate_correct_nodepool_multi_label_selector.yaml is excluded by !**/testdata/**
  • cmd/nodepool/agent/testdata/zz_fixture_TestCreateNodePool_When_flags_are_parsed_it_should_generate_correct_nodepool_single_label_selector.yaml is excluded by !**/testdata/**
📒 Files selected for processing (1)
  • cmd/nodepool/agent/create_test.go

Comment thread cmd/nodepool/agent/create_test.go Outdated
Comment thread cmd/nodepool/agent/create_test.go Outdated
@openshift-ci
openshift-ci Bot requested review from bryan-cox and cblecker July 29, 2026 14:58
@openshift-ci openshift-ci Bot added area/cli Indicates the PR includes changes for CLI and removed do-not-merge/needs-area labels Jul 29, 2026
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 45.77%. Comparing base (4f411bd) to head (a881c6a).
⚠️ Report is 32 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9162      +/-   ##
==========================================
+ Coverage   45.74%   45.77%   +0.03%     
==========================================
  Files         781      781              
  Lines       97858    97861       +3     
==========================================
+ Hits        44765    44796      +31     
+ Misses      50024    49996      -28     
  Partials     3069     3069              
Files with missing lines Coverage Δ
cmd/nodepool/agent/create.go 100.00% <100.00%> (+100.00%) ⬆️
Flag Coverage Δ
cmd-support 38.93% <100.00%> (+0.09%) ⬆️
cpo-hostedcontrolplane 47.98% <ø> (ø)
cpo-other 46.02% <ø> (ø)
hypershift-operator 57.00% <ø> (ø)
other 34.38% <ø> (ø)

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
cmd/nodepool/agent/create_test.go (1)

23-35: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use the required subtest description format.

Rename these cases—and the cases in the selector-translation table—to When ... it should ... descriptions.

As per coding guidelines, “Always use When ... it should ... format for describing test cases when creating unit 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 `@cmd/nodepool/agent/create_test.go` around lines 23 - 35, Rename the test
cases in the selector-related table, including the selector-translation table,
to follow the required “When ... it should ...” description format. Update each
existing case description while preserving its arguments and expected behavior.

Source: Coding guidelines

🤖 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 `@cmd/nodepool/agent/create_test.go`:
- Around line 23-35: Rename the test cases in the selector-related table,
including the selector-translation table, to follow the required “When ... it
should ...” description format. Update each existing case description while
preserving its arguments and expected behavior.

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Enterprise

Run ID: 0d47374c-1515-49d0-9532-5e2049d6b0a0

📥 Commits

Reviewing files that changed from the base of the PR and between 8c36439 and 64bfa61.

⛔ Files ignored due to path filters (3)
  • cmd/nodepool/agent/testdata/zz_fixture_TestCreateNodePool_When_flags_are_parsed_it_should_generate_correct_nodepool_empty_label_selector.yaml is excluded by !**/testdata/**
  • cmd/nodepool/agent/testdata/zz_fixture_TestCreateNodePool_When_flags_are_parsed_it_should_generate_correct_nodepool_multi_label_selector.yaml is excluded by !**/testdata/**
  • cmd/nodepool/agent/testdata/zz_fixture_TestCreateNodePool_When_flags_are_parsed_it_should_generate_correct_nodepool_single_label_selector.yaml is excluded by !**/testdata/**
📒 Files selected for processing (1)
  • cmd/nodepool/agent/create_test.go

@bryan-cox bryan-cox left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

HyperShift Staff Engineer Agent Review

Standards: 4 hard violations (test naming x3, flag wiring bypass) + 2 judgement calls.
Spec: 1 partial (template deviation) + 1 questionable (panic enshrinement).

Worst issue on Standards: the flag-wiring test bypasses the actual binding and would miss real regressions. Worst issue on Spec: the fixture test only partially follows the template pattern.

Details in inline comments below.

Comment thread cmd/nodepool/agent/create_test.go Outdated
Comment thread cmd/nodepool/agent/create_test.go Outdated
Comment thread cmd/nodepool/agent/create_test.go Outdated
Comment thread cmd/nodepool/agent/create_test.go
Comment thread cmd/nodepool/agent/create_test.go
@cblecker

Copy link
Copy Markdown
Member

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Aug 10, 2026
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
/test e2e-aks
/test e2e-aws
/test e2e-aws-upgrade-hypershift-operator
/test e2e-kubevirt-aws-ovn-reduced
/test e2e-v2-aws
/test e2e-v2-azure-self-managed
/test e2e-v2-gke

@mehabhalodiya

Copy link
Copy Markdown
Contributor Author

/test e2e-v2-gke
/test e2e-kubevirt-aws-ovn-reduced

@mehabhalodiya

Copy link
Copy Markdown
Contributor Author

/verified by unit-tests

@openshift-ci-robot openshift-ci-robot added the verified Signifies that the PR passed pre-merge verification criteria label Aug 11, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@mehabhalodiya: This PR has been marked as verified by unit-tests.

Details

In response to this:

/verified by unit-tests

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 openshift-eng/jira-lifecycle-plugin repository.

@mehabhalodiya

Copy link
Copy Markdown
Contributor Author

@bryan-cox all test passed! PTAL! Thank you!

@bryan-cox bryan-cox left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for adding coverage here — the Agent create path genuinely needed it, and the test cases themselves (empty/equality/set-based/invalid selectors, Type()) are the right scenarios with real-world values. Two axes of feedback:

Standards (TESTING.md)

  • Test function names carry a When…, it should… clause, which the standard reserves for test cases. Function names must be Test<FunctionName> mapping 1:1 to the function under test. Please collapse to TestNewCreateCommand, a table-driven TestUpdateNodePool (selector + panic cases), and TestType.
  • TestNewCreateCommand_When_flags_are_parsed… actually exercises UpdateNodePool (it asserts on nodePool.Spec.Platform.Agent), so the name points at the wrong function. Move it under TestUpdateNodePool.
  • Minor: the two UpdateNodePool-driven tests duplicate identical setup — a shared nodePool fixture helper would remove the repetition.

Spec (CNTRLPLANE-3899 / PR description)

  • The AC names test #1 TestCreateNodePool_… ("the exact function name from the acceptance criteria") and test #4 TestType_it_should_return_AgentPlatform; the committed names differ, and the testdata fixtures encode the divergent name. Please reconcile the code with the AC (or update the AC if it's stale).
  • Scope vs. description: the PR says "4 functions, 7 subtests" and "New file: create_test.go", but the diff has 5 functions / 6 subtests and also refactors create.go (extracting newCreateCommandWithOpts()). The refactor is a fine testability seam — just call it out in the description so scope matches.

Behaviorally the tests look correct; the requested changes are naming/scope alignment rather than logic. Happy to re-review once the function names follow TESTING.md and the description/AC are reconciled.

Comment thread cmd/nodepool/agent/create_test.go Outdated
Comment thread cmd/nodepool/agent/create_test.go Outdated
Comment thread cmd/nodepool/agent/create_test.go Outdated
Comment thread cmd/nodepool/agent/create_test.go Outdated
Comment thread cmd/nodepool/agent/create_test.go Outdated
return cmd
}

func newCreateCommandWithOpts() (*cobra.Command, *AgentPlatformCreateOptions) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reasonable seam to make the command testable — no change requested. One note: the UpdateNodePool-driven tests reach through this helper mainly to re-assert coverage that a direct TestUpdateNodePool already gives. If you consolidate the tests as suggested, TestNewCreateCommand only needs to cover command wiring (Use/RunE/flag registration), so this split stays justified and minimal.

@openshift-ci openshift-ci Bot removed the lgtm Indicates that a PR is ready to be merged. label Aug 12, 2026
The Agent nodepool create has its own platform-specific
options and validation logic that is completely untested.

Signed-off-by: mehabhalodiya <mehabhalodiya@gmail.com>
@openshift-ci-robot openshift-ci-robot removed the verified Signifies that the PR passed pre-merge verification criteria label Aug 17, 2026
@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Aug 19, 2026
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
/test e2e-aks
/test e2e-aws
/test e2e-aws-upgrade-hypershift-operator
/test e2e-kubevirt-aws-ovn-reduced
/test e2e-v2-aws
/test e2e-v2-azure-self-managed
/test e2e-v2-gke

@openshift-ci

openshift-ci Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cblecker, mehabhalodiya

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 Aug 19, 2026
@bryan-cox

Copy link
Copy Markdown
Member

/test e2e-v2-gke

@mehabhalodiya

Copy link
Copy Markdown
Contributor Author

/test e2e-kubevirt-aws-ovn-reduced

@mehabhalodiya

Copy link
Copy Markdown
Contributor Author

/verified by unit tests

@openshift-ci-robot openshift-ci-robot added the verified Signifies that the PR passed pre-merge verification criteria label Aug 19, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@mehabhalodiya: This PR has been marked as verified by unit tests.

Details

In response to this:

/verified by unit tests

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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

/retest-required

Remaining retests: 0 against base HEAD 754facc and 2 for PR HEAD a881c6a in total

@openshift-ci

openshift-ci Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

@mehabhalodiya: all tests passed!

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.

@openshift-merge-bot
openshift-merge-bot Bot merged commit 80f529c into openshift:main Aug 20, 2026
43 checks passed
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. area/cli Indicates the PR includes changes for CLI jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged. verified Signifies that the PR passed pre-merge verification criteria

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants