Skip to content

CNTRLPLANE-3900: Add shared cmd/ unit tests for destroy cluster - #9166

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

CNTRLPLANE-3900: Add shared cmd/ unit tests for destroy cluster#9166
mehabhalodiya wants to merge 1 commit into
openshift:mainfrom
mehabhalodiya:shared_destroy

Conversation

@mehabhalodiya

@mehabhalodiya mehabhalodiya commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Three platforms - KubeVirt, OpenStack, and Agent have zero shared unit test coverage for cluster destroy

What this PR does / why we need it:

3 new test files for zero-coverage destroy paths:

  1. cmd/cluster/kubevirt/destroy_test.go — Tests NewDestroyCommand wiring (Use, Short, SilenceUsage). KubeVirt's destroy is a thin delegate to none.DestroyCluster with no platform-specific logic.

  2. cmd/cluster/openstack/destroy_test.go — Tests NewDestroyCommand wiring + destroyPlatformSpecifics (verifies it's a no-op returning nil). OpenStack has its own DestroyCluster with InfraID validation, but the full flow can't be tested via FAKE_CLIENT because the fake client's scheme doesn't include hyperv1.HostedCluster.

  3. cmd/cluster/agent/destroy_test.go — Tests NewDestroyCommand wiring + the DestroyOptions struct (zero values and field retention). Agent's DestroyCluster is a direct delegation to none.DestroyCluster.

Verification: go test passes for all three packages, make lint-fix reports 0 issues, go vet is clean.

Which issue(s) this PR fixes:

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

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 automated coverage for cluster destruction commands across agent, KubeVirt, and OpenStack environments.
    • Verified command metadata (usage, description, and usage-silencing behavior), default option values, correct retention of provided option values, and platform-specific destroy handling.

@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-3900 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:

Three platforms - KubeVirt, OpenStack, and Agent have zero shared unit test coverage for cluster destroy

What this PR does / why we need it:

3 new test files for zero-coverage destroy paths:

  1. cmd/cluster/kubevirt/destroy_test.go — Tests NewDestroyCommand wiring (Use, Short, SilenceUsage). KubeVirt's destroy is a thin delegate to none.DestroyCluster with no platform-specific logic.

  2. cmd/cluster/openstack/destroy_test.go — Tests NewDestroyCommand wiring + destroyPlatformSpecifics (verifies it's a no-op returning nil). OpenStack has its own DestroyCluster with InfraID validation, but the full flow can't be tested via FAKE_CLIENT because the fake client's scheme doesn't include hyperv1.HostedCluster.

  3. cmd/cluster/agent/destroy_test.go — Tests NewDestroyCommand wiring + the DestroyOptions struct (zero values and field retention). Agent's DestroyCluster is a direct delegation to none.DestroyCluster.

Verification: go test passes for all three packages, make lint-fix reports 0 issues, go vet is clean.

Which issue(s) this PR fixes:

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

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: 30d179b5-ca0a-4a65-8d3c-11528b32357a

📥 Commits

Reviewing files that changed from the base of the PR and between 0ed9ac2 and 808ffc6.

📒 Files selected for processing (3)
  • cmd/cluster/agent/destroy_test.go
  • cmd/cluster/kubevirt/destroy_test.go
  • cmd/cluster/openstack/destroy_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • cmd/cluster/agent/destroy_test.go
  • cmd/cluster/openstack/destroy_test.go

📝 Walkthrough

Walkthrough

Adds unit tests for destroy command metadata in the agent, KubeVirt, and OpenStack implementations. The tests verify command usage strings and silenced usage output, validate zero-value and explicitly populated agent destroy options, and confirm OpenStack platform-specific destruction returns no error.

Suggested reviewers: enxebre, sdminonne

🚥 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: shared unit tests added under cmd/ for cluster destroy commands.
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 No Ginkgo-style titles contain dynamic data; the added subtest names are static, descriptive, and deterministic.
Test Structure And Quality ✅ Passed PASS: These are simple table-driven unit tests, not Ginkgo/cluster-integration tests; no resources, waits, or cleanup needed, and assertions match repo patterns.
Topology-Aware Scheduling Compatibility ✅ Passed Only new destroy unit tests were added; no manifests, controllers, or scheduling logic changed, so topology-awareness is not implicated.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed New tests are unit-only and contain no IPv4 assumptions or external connectivity requirements.
No-Weak-Crypto ✅ Passed Added files are tests only; scans found no MD5/SHA1/DES/RC4/3DES/Blowfish/ECB or secret-comparison code.
Container-Privileges ✅ Passed Only Go test files were added; no container/K8s manifests or privilege-related fields were changed.
No-Sensitive-Data-In-Logs ✅ Passed PASS: The PR adds only unit tests; no new logging statements or sensitive-data-bearing log output were added.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@openshift-ci
openshift-ci Bot requested review from enxebre and sdminonne July 29, 2026 15:47
@openshift-ci openshift-ci Bot added the area/cli Indicates the PR includes changes for CLI label 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 akalenyu, awels, cblecker, nunnatsa 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

@openshift-ci openshift-ci Bot added area/platform/kubevirt PR/issue for KubeVirt (KubevirtPlatform) platform area/platform/openstack PR/issue for OpenStack (OpenStackPlatform) platform and removed do-not-merge/needs-area labels Jul 29, 2026

@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/cluster/agent/destroy_test.go (1)

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

Use distinct names for nested test variables.

Each subtest closure shadows its enclosing t; rename the closure parameter to tt consistently.

  • cmd/cluster/agent/destroy_test.go#L24-L31: rename the closure parameter and pass tt to NewGomegaWithT.
  • cmd/cluster/kubevirt/destroy_test.go#L23-L30: rename the closure parameter and pass tt to NewGomegaWithT.
  • cmd/cluster/openstack/destroy_test.go#L24-L31: rename the closure parameter and pass tt to NewGomegaWithT.
Proposed change
- t.Run(name, func(t *testing.T) {
-     g := NewGomegaWithT(t)
+ t.Run(name, func(tt *testing.T) {
+     g := NewGomegaWithT(tt)
🤖 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/cluster/agent/destroy_test.go` around lines 24 - 31, Rename each nested
subtest closure parameter from t to tt and pass tt to NewGomegaWithT in
cmd/cluster/agent/destroy_test.go:24-31,
cmd/cluster/kubevirt/destroy_test.go:23-30, and
cmd/cluster/openstack/destroy_test.go:24-31; leave the surrounding test logic
unchanged.

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/cluster/agent/destroy_test.go`:
- Around line 24-31: Rename each nested subtest closure parameter from t to tt
and pass tt to NewGomegaWithT in cmd/cluster/agent/destroy_test.go:24-31,
cmd/cluster/kubevirt/destroy_test.go:23-30, and
cmd/cluster/openstack/destroy_test.go:24-31; leave the surrounding test logic
unchanged.

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Enterprise

Run ID: dd5a53a6-fa24-4ab0-8efb-a270f8ab2ad0

📥 Commits

Reviewing files that changed from the base of the PR and between deb7a80 and 0ed9ac2.

📒 Files selected for processing (3)
  • cmd/cluster/agent/destroy_test.go
  • cmd/cluster/kubevirt/destroy_test.go
  • cmd/cluster/openstack/destroy_test.go

@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 44.66%. Comparing base (845e625) to head (808ffc6).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9166      +/-   ##
==========================================
+ Coverage   44.62%   44.66%   +0.04%     
==========================================
  Files         775      775              
  Lines       97105    97085      -20     
==========================================
+ Hits        43329    43365      +36     
+ Misses      50781    50730      -51     
+ Partials     2995     2990       -5     

see 6 files with indirect coverage changes

Flag Coverage Δ
cmd-support 38.51% <ø> (+0.11%) ⬆️
cpo-hostedcontrolplane 47.23% <ø> (ø)
cpo-other 45.30% <ø> (+<0.01%) ⬆️
hypershift-operator 54.59% <ø> (+0.04%) ⬆️
other 33.30% <ø> (ø)

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.

Three platforms - KubeVirt, OpenStack and Agent  have
zero shared unit test coverage for cluster destroy

Signed-off-by: mehabhalodiya <mehabhalodiya@gmail.com>
@openshift-ci

openshift-ci Bot commented Jul 29, 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 area/platform/kubevirt PR/issue for KubeVirt (KubevirtPlatform) platform area/platform/openstack PR/issue for OpenStack (OpenStackPlatform) platform 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.

2 participants