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

controller_util_test.go does not follow similar patterns as other unit tests in the repo. #119133

Closed
kannon92 opened this issue Jul 6, 2023 · 17 comments · Fixed by #119146 or #119214
Closed
Assignees
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/feature Categorizes issue or PR as related to a new feature. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. sig/apps Categorizes an issue or PR as relevant to SIG Apps.

Comments

@kannon92
Copy link
Contributor

kannon92 commented Jul 6, 2023

What would you like to be added?

During implementation of KEP 3393 (PodReplacementPolicy for Jobs) we found that the unit tests of controller_util_test.go do not follow common patterns established in k/k.

  1. The tests are not written using table driven design (https://dave.cheney.net/2019/05/07/prefer-table-driven-tests).

  2. The tests use Differences rather than Cmp.Diff.

This probably should be done as two separate PRs but wanted to highlight some areas that could use some cleanup.

Why is this needed?

#117015 (comment)

Not using Cmp.Diff means that we don't see diffs in the unit tests that makes this difficult.

And not using table driven tests makes it difficult to add new test cases as it usually is brought up during review that we should use a table-driven test but the entire file does not obey this format.

@kannon92 kannon92 added the kind/feature Categorizes issue or PR as related to a new feature. label Jul 6, 2023
@k8s-ci-robot k8s-ci-robot added needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jul 6, 2023
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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/test-infra repository.

@kannon92
Copy link
Contributor Author

kannon92 commented Jul 6, 2023

/sig apps
/kind cleanup
/help
/good-first-issue

@k8s-ci-robot
Copy link
Contributor

@kannon92:
This request has been marked as suitable for new contributors.

Guidelines

Please ensure that the issue body includes answers to the following questions:

  • Why are we solving this issue?
  • To address this issue, are there any code changes? If there are code changes, what needs to be done in the code and what places can the assignee treat as reference points?
  • Does this issue have zero to low barrier of entry?
  • How can the assignee reach out to you for help?

For more details on the requirements of such an issue, please see here and ensure that they are met.

If this request no longer meets these requirements, the label can be removed
by commenting with the /remove-good-first-issue command.

In response to this:

/sig apps
/kind cleanup
/help
/good-first-issue

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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added sig/apps Categorizes an issue or PR as relevant to SIG Apps. good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jul 6, 2023
@kaisoz
Copy link
Contributor

kaisoz commented Jul 6, 2023

I'd like to work on it 😊

/assign

@xuexu6666
Copy link
Contributor

I'd also like to make some contributions.
/assign

@xuexu6666
Copy link
Contributor

@kaisoz

Looks like this need two PRs.

  1. The tests are not written using table driven design (https://dave.cheney.net/2019/05/07/prefer-table-driven-tests).
  2. The tests use Differences rather than Cmp.Diff.

I think I can work on the 2nd one and leave the 1st one to you. Sounds good?

@xuexu6666
Copy link
Contributor

@kannon92

By looking through the gc_controller_test.go, I found the main function to comapre the results have already used cmp.Diff. Can you elaborate more on which part you expect to use cmp.Diff?

func verifyDeletedAndPatchedPods(t *testing.T, client *fake.Clientset, wantDeletedPodNames, wantPatchedPodNames sets.String) {
t.Helper()
deletedPodNames := getDeletedPodNames(client)
if diff := cmp.Diff(wantDeletedPodNames, deletedPodNames); diff != "" {
t.Errorf("Deleted pod names (-want,+got):\n%s", diff)
}
patchedPodNames := getPatchedPodNames(client)
if diff := cmp.Diff(wantPatchedPodNames, patchedPodNames); diff != "" {
t.Errorf("Patched pod names (-want,+got):\n%s", diff)
}
}

@kannon92 kannon92 changed the title gc_controller_test.go does not follow similar patterns as other unit tests in the repo. controller_util_test.go does not follow similar patterns as other unit tests in the repo. Jul 6, 2023
@kannon92
Copy link
Contributor Author

kannon92 commented Jul 6, 2023

I am really sorry about this. Too much multitasking!!

I meant https://github.com/kubernetes/kubernetes/blob/master/pkg/controller/controller_utils_test.go not gc_controller_test.go.

@kaisoz
Copy link
Contributor

kaisoz commented Jul 7, 2023

Hey @xuexu6666 ! Sorry, I didn't see this before.

No problem at all, but consider that one change depends on the other, and since my task implies a big refactor, there might be conflicts when merging your PR... That's why I see two possible scenarios happening:

  • Your PR gets merged before I raise mine: Then fine, I'll rebase your changes and adapt my code 😊
  • Mine is ready before yours is merged: In this case, I propose you commit your changes to my PR. Both of us will appear as coauthors of the change

Getting a PR merged in the Kubernetes project takes quite some time (trust me, I talk by experience and @kannon92 can confirm 😆 )

WDYT?

@xuexu6666
Copy link
Contributor

@kaisoz Let's see how it goes. We can always rebase the code change to adapt new.

@xuexu6666
Copy link
Contributor

@kaisoz btw, did you already begin to work on task 1? If not, I may just go ahead and work on it right away since I have already dig into it.

@kaisoz
Copy link
Contributor

kaisoz commented Jul 7, 2023

@xuexu6666 yes, I already started 😊 And If you ask me, better to keep it this way so we both have an opportunity to have a contribution

@xuexu6666
Copy link
Contributor

@kaisoz cool. Sounds good.

@kannon92
Copy link
Contributor Author

/reopen

@k8s-ci-robot k8s-ci-robot reopened this Jul 10, 2023
@k8s-ci-robot
Copy link
Contributor

@kannon92: Reopened this issue.

In response to this:

/reopen

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/test-infra repository.

@biswajit-9776
Copy link

Hi @kannon92, if this issue needs to be worked on any further, please assign me for the same.

@kannon92
Copy link
Contributor Author

@kaisoz has a PR up that will solve the second part of this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/feature Categorizes issue or PR as related to a new feature. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. sig/apps Categorizes an issue or PR as relevant to SIG Apps.
Projects
None yet
5 participants