Skip to content

Conversation

@yaten2302
Copy link

Fixes #21895

This PR adds unit test for argocd admin import command.

image

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • The title of the PR conforms to the Toolchain Guide
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).
  • My new feature complies with the feature status guidelines.
  • I have added a brief description of why this PR is necessary and/or what this PR solves.
  • Optional. My organization is added to USERS.md.
  • Optional. For bug fixes, I've indicated what older releases this fix should be cherry-picked into (this may or may not happen depending on risk/complexity).

@yaten2302 yaten2302 requested a review from a team as a code owner April 24, 2025 11:58
@bunnyshell
Copy link

bunnyshell bot commented Apr 24, 2025

❌ Preview Environment undeployed from Bunnyshell

Available commands (reply to this comment):

  • 🚀 /bns:deploy to deploy the environment

@codecov
Copy link

codecov bot commented Apr 24, 2025

Codecov Report

❌ Patch coverage is 27.75330% with 164 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (master@4a71661). Learn more about missing BASE report.

Files with missing lines Patch % Lines
cmd/argocd/commands/admin/backup.go 27.75% 157 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master   #22780   +/-   ##
=========================================
  Coverage          ?   60.87%           
=========================================
  Files             ?      351           
  Lines             ?    60548           
  Branches          ?        0           
=========================================
  Hits              ?    36858           
  Misses            ?    20762           
  Partials          ?     2928           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nitishfy nitishfy self-requested a review April 25, 2025 11:26
Copy link
Member

@nitishfy nitishfy left a comment

Choose a reason for hiding this comment

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

Is this PR ready for review? I only see one test case.

@yaten2302
Copy link
Author

@nitishfy , added 5 test cases 👍
All those are passing.

Copy link
Member

@nitishfy nitishfy left a comment

Choose a reason for hiding this comment

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

You're required to add all the test cases that checks these scenarios:

  • Resource should be pruned when --prune and missing from backup
  • Resource should be created when missing from live
  • Resource tracking annotation should not be updated when --ignore-tracking
  • Application operation should removed when --stop-operation
  • Update operation should retry on conflict when --override-on-conflict
  • Resource should not be pruned if present in backup and backup resource matches --skip-resources-with-label
  • Resource should not be pruned if missing from backup, but live matches --skip-resources-with-label
  • Test application-namespace feature
  • Test applicationset-namespace feature
  • Dry run should not modify any resources

@nitishfy
Copy link
Member

I'd suggest learning about these things one at a time. For eg. What is the use of import command, why do we use the prune flag, and what is the application namespace feature? Pick one test case at a time. Try to understand what this feature means, look at the code to see how it is written and then write a test case to validate it. You may be required to even put that logic in a new function and call that function in the test case to validate the scenario.

@yaten2302
Copy link
Author

You're required to add all the test cases that checks these scenarios:

  • Resource should be pruned when --prune and missing from backup
  • Resource should be created when missing from live
  • Resource tracking annotation should not be updated when --ignore-tracking
  • Application operation should removed when --stop-operation
  • Update operation should retry on conflict when --override-on-conflict
  • Resource should not be pruned if present in backup and backup resource matches --skip-resources-with-label
  • Resource should not be pruned if missing from backup, but live matches --skip-resources-with-label
  • Test application-namespace feature
  • Test applicationset-namespace feature
  • Dry run should not modify any resources

Yes, sure, will add with the flags as well 👍
Actually, first I just wanted to confirm if the tests which I'm creating must be created like this only or should I should do some changes in it. So, that's why, I didn't add the flags yet.
NVM, will push a commit for this 👍
Thanks for your suggestions!

@yaten2302
Copy link
Author

I'd suggest learning about these things one at a time. For eg. What is the use of import command, why do we use the prune flag, and what is the application namespace feature? Pick one test case at a time. Try to understand what this feature means, look at the code to see how it is written and then write a test case to validate it. You may be required to even put that logic in a new function and call that function in the test case to validate the scenario.

Yes, I've already read the entire input command code, and now I've a good understanding of the same.
(Previously, I was having some issues in understanding this, but now I'm quite familiar). I'm checking how can I add the tests for the flags, like - --prune, --stop-operation etc...
I'll also try to put that logic in a separate func (as suggested) to test the flags and all for testing in the Test_importResource 👍

@yaten2302
Copy link
Author

Hey @nitishfy , could you kindly have a look at the tests for the --prune flag.
The tests are passing, should I add any more TCs if required?

Copy link
Member

@agaudreault agaudreault left a comment

Choose a reason for hiding this comment

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

I like the structure of the tests, but reading a few different scenario names, I am not sure what it is actually testing. For instance, "It should update the live object according to the backup object if the backup object doesn't have the skip label". This test the happy path. where is the test that validates that it should not update the resource when it matches the label?

Similar comment for the following tests, they seem to all be testing the happy path, and not the conditional scenarios

  • "Spec should be updated correctly in live object according to the backup object"
  • "It should update the data of the live object according to the backup object"
  • "It should update live object's spec according to the backup object"

@yaten2302
Copy link
Author

Yes @agaudreault , actually I forgot to update the names of the test cases. Pushing the changes for the same 👍

@yaten2302
Copy link
Author

Hi @nitishfy @agaudreault , I've pushed a commit according to the suggestions.

Since, I didn't have any reviews how to proceed, I tried to refactor the Run func and I broke it down into executeImport() func and then I passed it to the Test_executeImport func where I unit tested it.

Kindly have a look at it, if I'm going in the correct direction?

Thanks

@yaten2302
Copy link
Author

Hi @nitishfy @agaudreault , I've pushed a commit in which I've refactored the NewImportCommand() by adding the required executeImport() func, as mentioned in this comment.

Could you kindly have a look that is this the desired behaviour which you are expecting? I've asked for review multiple times on this.
Kindly have a look at this.
Thanks

@nitishfy
Copy link
Member

Can you fix the failing tests?

@yaten2302
Copy link
Author

Sure, I'll push the commits today to fix the tests👍

@yaten2302
Copy link
Author

Hi @nitishfy , all checks are passing now. Previously there was 1 failing check, but when I pulled the latest changes, it's fixed 👍
Kindly have a look

Thanks :)

@yaten2302 yaten2302 requested a review from a team as a code owner October 6, 2025 18:04
@yaten2302
Copy link
Author

yaten2302 commented Oct 15, 2025

Hi @nitishfy , could you kindly review this :)
Thanks

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit test for argocd admin export/import CLI command

3 participants