Skip to content

test(device): add unit tests for DeviceInfo DeepCopy and DeepCopyDeviceInfos - #2972

Open
Norway-02 wants to merge 1 commit into
Project-HAMi:masterfrom
Norway-02:test-device-deepcopy
Open

test(device): add unit tests for DeviceInfo DeepCopy and DeepCopyDeviceInfos#2972
Norway-02 wants to merge 1 commit into
Project-HAMi:masterfrom
Norway-02:test-device-deepcopy

Conversation

@Norway-02

@Norway-02 Norway-02 commented Sep 5, 2026

Copy link
Copy Markdown

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

Adds table-driven unit tests TestDeviceInfoDeepCopy and TestDeepCopyDeviceInfos in pkg/device/devices_test.go to test the deep copy implementations of DeviceInfo and []DeviceInfo.

Specifically, these tests verify:

  1. DeviceInfo.DeepCopy(). creates independent copies of all nested collections (MIGTemplate, CustomInfo, DevicePairScore.Scores).
  2. Mutating fields, maps, or slice elements on the copied DeviceInfo does NOT mutate the original DeviceInfo.
  3. DeepCopyDeviceInfos() correctly handles nil, empty slices, and multi-element slices with deep memory isolation.

Follows the unit testing precedent established in maintainer PR #2825.

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

This PR was written primarily by Claude Code.

All unit tests pass with race detection (go test -race ./pkg/device), and license/import-alias checks (make verify) pass cleanly.

Does this PR introduce a user-facing change?:
No.

Summary by CodeRabbit

  • Tests
    • Added coverage verifying that device information can be deeply copied without sharing nested data.
    • Added coverage for deep-copy behavior across nil, empty, and populated device collections.

…ceInfos

Signed-off-by: Norway-02 <anshulkhetade02@gmail.com>
@hami-robot

hami-robot Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Norway-02
Once this PR has been reviewed and has the lgtm label, please assign fouof for approval. For more information see the Kubernetes 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 Sep 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 238f377b-09d2-45b5-97c9-77fb92519d26

📥 Commits

Reviewing files that changed from the base of the PR and between 42cdc78 and 72aba9c.

📒 Files selected for processing (1)
  • pkg/device/devices_test.go

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The change adds tests for DeviceInfo.DeepCopy and DeepCopyDeviceInfos. The tests cover nested values, maps, nil inputs, empty inputs, populated slices, and mutation independence.

Changes

Deep Copy Test Coverage

Layer / File(s) Summary
Device deep-copy validation
pkg/device/devices_test.go
Adds tests for individual and slice deep copies. The tests verify deep equality and confirm that mutations to copied scalar, nested, and map fields do not change the originals.

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

Merge Risk: ⚪ Minimal · up to 72aba

This change adds device deep-copy test coverage without altering runtime behavior. The tested copy and slice contracts are covered with no remaining merge-readiness risk.

Suggested labels: enhancement

Poem

A rabbit reads each line,
The patch grows clear beneath the moon,
Small changes hop in place,
Tests guard the garden path,
Reviews bloom before the dawn.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the addition of unit tests for both DeviceInfo.DeepCopy and DeepCopyDeviceInfos, which is the main 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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch test-device-deepcopy
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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