Skip to content

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

Open
mehabhalodiya wants to merge 1 commit into
openshift:mainfrom
mehabhalodiya:shared_nodepool
Open

CNTRLPLANE-3899: Add shared cmd/ unit tests for create nodepool agent#9162
mehabhalodiya wants to merge 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.

@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

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: 1b104839-6db6-44f7-83ec-e35f358788b1

📥 Commits

Reviewing files that changed from the base of the PR and between 64bfa61 and 673b347.

⛔ Files ignored due to path filters (3)
  • cmd/nodepool/agent/testdata/zz_fixture_TestNewCreateCommand_When_flags_are_parsed_it_should_generate_correct_nodepool_When_multi_label_selector_with_set_based_expression_is_provided__it_should_set_matchLabels_and_matchExpressions.yaml is excluded by !**/testdata/**
  • cmd/nodepool/agent/testdata/zz_fixture_TestNewCreateCommand_When_flags_are_parsed_it_should_generate_correct_nodepool_When_no_label_selector_flag_is_provided__it_should_generate_nodepool_with_empty_agent_label_selector.yaml is excluded by !**/testdata/**
  • cmd/nodepool/agent/testdata/zz_fixture_TestNewCreateCommand_When_flags_are_parsed_it_should_generate_correct_nodepool_When_single_equality_label_selector_is_provided__it_should_set_matchLabels_on_agent_platform.yaml is excluded by !**/testdata/**
📒 Files selected for processing (2)
  • cmd/nodepool/agent/create.go
  • cmd/nodepool/agent/create_test.go

📝 Walkthrough

Walkthrough

Refactored agent nodepool create command construction so NewCreateCommand wires execution using the returned platform options. Added Go tests covering --agentLabelSelector parsing, conversion to metav1.LabelSelector, invalid selector handling, fixture-based platform generation, and AgentPlatformCreateOptions.Type().

Possibly related PRs

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 matches the main change: adding unit tests for the nodepool agent create command.
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 new test titles are static, descriptive strings; none include generated or time-varying data.
Test Structure And Quality ✅ Passed PASS: these are pure unit tests; no cluster resources, waits, or Ginkgo hooks, and the table-driven cases use isolated setup with meaningful failure messages.
Topology-Aware Scheduling Compatibility ✅ Passed Only CLI flag parsing and label-selector conversion changed; no pod spec, replicas, affinities, tolerations, or node selectors were added.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed New tests are plain unit tests, not Ginkgo e2e, and contain no IPv4 literals, host/IP construction, or external connectivity.
No-Weak-Crypto ✅ Passed Touched files only add flag-parsing and selector tests; no MD5/SHA1/DES/RC4/3DES/Blowfish/ECB, custom crypto, or secret comparisons found.
Container-Privileges ✅ Passed PR only changes Go tests and label-selector fixtures; no container/K8s manifests or privilege flags were added.
No-Sensitive-Data-In-Logs ✅ Passed No new logging was added; create.go has no log calls, and tests/fixtures contain only label selectors, not sensitive data.
✨ 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
@openshift-ci

openshift-ci Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mehabhalodiya
Once this PR has been reviewed and has the lgtm label, please assign enxebre 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

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.80%. Comparing base (845e625) to head (673b347).
⚠️ Report is 36 commits behind head on main.

Files with missing lines Patch % Lines
cmd/nodepool/agent/create.go 40.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9162      +/-   ##
==========================================
+ Coverage   44.62%   44.80%   +0.18%     
==========================================
  Files         775      775              
  Lines       97105    97213     +108     
==========================================
+ Hits        43329    43555     +226     
+ Misses      50781    50657     -124     
- Partials     2995     3001       +6     
Files with missing lines Coverage Δ
cmd/nodepool/agent/create.go 87.09% <40.00%> (+87.09%) ⬆️

... and 20 files with indirect coverage changes

Flag Coverage Δ
cmd-support 38.50% <40.00%> (+0.10%) ⬆️
cpo-hostedcontrolplane 47.25% <ø> (+0.02%) ⬆️
cpo-other 45.45% <ø> (+0.15%) ⬆️
hypershift-operator 54.63% <ø> (+0.08%) ⬆️
other 34.32% <ø> (+1.01%) ⬆️

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

openshift-ci Bot commented Jul 30, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cli Indicates the PR includes changes for CLI jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants