Skip to content

Testing: Implement missing unit tests for pkg/backup/snapshots.go - #10315

Open
opbot-xd wants to merge 1 commit into
velero-io:mainfrom
opbot-xd:add-snapshots-tests
Open

Testing: Implement missing unit tests for pkg/backup/snapshots.go#10315
opbot-xd wants to merge 1 commit into
velero-io:mainfrom
opbot-xd:add-snapshots-tests

Conversation

@opbot-xd

Copy link
Copy Markdown
Contributor

Thank you for contributing to Velero!

Please add a summary of your change

The pkg/backup/snapshots.go file contains the core logic for handling CSI snapshots and VolumeSnapshotTrackers (e.g., GetBackupCSIResources), but it currently lacks unit test coverage.

This PR introduces a brand new test file pkg/backup/snapshots_test.go and implements a comprehensive table-driven unit test suite for the GetBackupCSIResources function. It covers all branches of the function, ensuring that snapshot filtering, tracker sync logic, and object deduplication remain robust as Velero evolves.

Does your change fix a particular issue?

Fixes #10314

Please indicate you've done the following:

@opbot-xd
opbot-xd requested a review from a team as a code owner August 17, 2026 18:08
@opbot-xd
opbot-xd force-pushed the add-snapshots-tests branch from a0fbd17 to 2c29f00 Compare August 17, 2026 18:09
@codecov

codecov Bot commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Signed-off-by: opbot_xd <awasthikrishna23052005@gmail.com>
@opbot-xd
opbot-xd force-pushed the add-snapshots-tests branch from 2c29f00 to 62f5e38 Compare August 17, 2026 19:14
@netlify

netlify Bot commented Aug 17, 2026

Copy link
Copy Markdown

👷 Deploy request for velero pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 62f5e38

SnapshotMoveData: boolptr.True(),
},
},
csiFeatureEnabled: true,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it would be prudent to have existingObjects for cases 1 and 2 just to showcase that no ops happen on them
As is, turning the flags on and off wouldn't prove anything

SnapshotMoveData: boolptr.False(),
},
},
csiFeatureEnabled: false,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same as previous comment, existingObjects here would be wise


for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
if tc.csiFeatureEnabled {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Adding a defer to reset the feature flag set would be great, to prevent leakage into other tests
I believe that's good convention

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.

Testing: Implement missing unit tests for pkg/backup/snapshots.go

3 participants