Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test coverage of pkg/controllers/context #5310

Conversation

anujagrawal699
Copy link
Contributor

Description:
This PR enhances the test coverage for the pkg/controllers/context package, increasing its test coverage from 42.3% to 100%. The new tests are designed to ensure the functionality and reliability of the package, improving its overall maintainability.

Implemented Tests:

  1. TestInitializers_ControllerNames: Checks that ControllerNames() correctly returns all controller names.
  2. TestInitializers_StartControllers: Tests the StartControllers() method under different conditions, including successful starts, error handling, and scenarios with disabled controllers.

Test Coverage:
Implementing this tests increased it's test coverage from 42.3% to 100%. This can be verified in the file directory i.e. pkg/controllers/context using command
go test -coverprofile=coverage.out

What type of PR is this?
/kind failing-test
/kind feature

What this PR does / why we need it:
The tests introduced in this PR will:
Improve test coverage of pkg/controllers/context from 42.3% to 100%
Help catch potential issues in future changes

Which issue(s) this PR fixes:
Fixes a part #5236

Special notes for your reviewer:
These commits are part of my introduction to the Karmada project and provide me with hands-on experience in implementing unit tests within the project. I look forward to implement more unit tests in the LFX Mentorship program.

Does this PR introduce a user-facing change?:

NONE

@karmada-bot karmada-bot added kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. kind/feature Categorizes issue or PR as related to a new feature. labels Aug 6, 2024
@karmada-bot karmada-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 6, 2024
@codecov-commenter
Copy link

codecov-commenter commented Aug 6, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 28.43%. Comparing base (8b4e006) to head (4632376).
Report is 292 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5310      +/-   ##
==========================================
+ Coverage   28.36%   28.43%   +0.07%     
==========================================
  Files         632      632              
  Lines       43774    43810      +36     
==========================================
+ Hits        12416    12457      +41     
+ Misses      30458    30448      -10     
- Partials      900      905       +5     
Flag Coverage Δ
unittests 28.43% <ø> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@anujagrawal699
Copy link
Contributor Author

@XiShanYongYe-Chang

@XiShanYongYe-Chang
Copy link
Member

Hi @anujagrawal699, it seems that current has more than one commit, and one of them is not a file involved in the current PR description, can you help to remove it?

@anujagrawal699
Copy link
Contributor Author

@XiShanYongYe-Chang The second file was the file added in PR #5301. I was unaware of it being present in the commit because git diff of that file with master was empty. Now should i change the description of this PR or git rm pkg/util/gclient_test.go from this branch.

@XiShanYongYe-Chang
Copy link
Member

Let me review #5301 first, then we can come back to this pr.

@XiShanYongYe-Chang
Copy link
Member

Hi @anujagrawal699, we can continue this pr, can you help remove the other commit?

@anujagrawal699 anujagrawal699 force-pushed the improveTestCoverage-pkg/controllers/context branch from 560ffb3 to baff21a Compare August 7, 2024 03:58
@anujagrawal699
Copy link
Contributor Author

@XiShanYongYe-Chang Thanks, i removed the other commit. Can i add more PR's like this?

@XiShanYongYe-Chang
Copy link
Member

@XiShanYongYe-Chang Thanks, i removed the other commit. Can i add more PR's like this?

Can wait a bit for me to reivew to finish this pr.

Copy link
Member

@XiShanYongYe-Chang XiShanYongYe-Chang left a comment

Choose a reason for hiding this comment

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

Thanks~

@@ -1,5 +1,5 @@
/*
Copyright 2022 The Karmada Authors.
Copyright 2024 The Karmada Authors.
Copy link
Member

Choose a reason for hiding this comment

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

This is the creation time of the file. we do not need to change it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, i'll update the commit.

@@ -34,49 +36,63 @@ func TestContext_IsControllerEnabled(t *testing.T) {
name: "on by name",
controllerName: "bravo",
disabledByDefaultControllers: []string{"delta", "echo"},
controllers: []string{"alpha", "bravo", "-charlie"}, // --controllers=alpha,bravo,-charlie
Copy link
Member

Choose a reason for hiding this comment

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

The comments help us to understand the test better and can be kept.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@XiShanYongYe-Chang Made the suggested changes. Thanks!

@karmada-bot karmada-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 7, 2024
Comment on lines 84 to 90
{
name: "on by star, not in disabled list",
controllerName: "foxtrot",
disabledByDefaultControllers: []string{"delta", "echo"},
controllers: []string{"*"}, // --controllers=*
expected: true,
},
Copy link
Member

Choose a reason for hiding this comment

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

You can reposition this case so that it is adjacent to similar test cases, making it easier for other users to read and understand.

Copy link
Contributor Author

@anujagrawal699 anujagrawal699 Aug 7, 2024

Choose a reason for hiding this comment

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

Okay.

@XiShanYongYe-Chang
Copy link
Member

/assign

Copy link
Member

@XiShanYongYe-Chang XiShanYongYe-Chang left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution @anujagrawal699
/lgtm
/approve

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 9, 2024
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: XiShanYongYe-Chang

The full list of commands accepted by this bot can be found here.

The pull request process is described here

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

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 9, 2024
@karmada-bot karmada-bot merged commit 6e9136d into karmada-io:master Aug 9, 2024
12 checks passed
@XiShanYongYe-Chang
Copy link
Member

I was remiss and forgot to tell you to compress all commits into one commit. q_q

@anujagrawal699
Copy link
Contributor Author

anujagrawal699 commented Aug 9, 2024

I was remiss and forgot to tell you to compress all commits into one commit. q_q

You helped a lot though. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants