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

🏃Add unit tests for machine controller #1493

Merged

Conversation

wfernandes
Copy link
Contributor

Signed-off-by: Warren Fernandes wfernandes@pivotal.io

What this PR does / why we need it:
This PR adds some additional unit tests for machine_controller.go. It also refactors other pre-existing tests to make them a little more readable.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
NA

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 7, 2019
@k8s-ci-robot
Copy link
Contributor

Hi @wfernandes. Thanks for your PR.

I'm waiting for a kubernetes-sigs or kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 7, 2019
@vincepri
Copy link
Member

vincepri commented Oct 8, 2019

/ok-to-test
/assign

I'll take a look this afternoon

@k8s-ci-robot k8s-ci-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Oct 8, 2019
@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Oct 8, 2019
@detiber
Copy link
Member

detiber commented Oct 8, 2019

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 8, 2019
controllers/machine_controller_test.go Outdated Show resolved Hide resolved
controllers/machine_controller_test.go Show resolved Hide resolved
controllers/machine_controller_test.go Show resolved Hide resolved
controllers/machine_controller_test.go Show resolved Hide resolved

key := client.ObjectKey{Namespace: tc.m.Namespace, Name: tc.m.Name}
if len(tc.expectedFinalizers) > 0 {
Expect(mr.Client.Get(ctx, key, tc.m)).ToNot(HaveOccurred())
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of storing into tc.m, let's create a var m clusterv1.Machine and store into &m, then compare m.Finalizers with tc.expectedFinalizers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ncdc The other reason I kept m in the struct was for key := client.ObjectKey{Namespace: tc.m.Namespace, Name: tc.m.Name}
I can pass in the namespace and name explicitly into the struct but I thought this was readable.

controllers/machine_controller_test.go Show resolved Hide resolved
controllers/machine_controller_test.go Outdated Show resolved Hide resolved
clusterv1.AddToScheme(scheme.Scheme)
mr := &MachineReconciler{
Client: fake.NewFakeClientWithScheme(
scheme.Scheme,
Copy link
Member

Choose a reason for hiding this comment

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

This can probably be omitted and use the other New method without the scheme, given that the scheme is initialized in suite_test.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason I used this method was because fake.NewFakeClient is marked as deprecated.

Copy link
Contributor Author

@wfernandes wfernandes Oct 8, 2019

Choose a reason for hiding this comment

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

@vincepri Also if you are referring to the scheme being initialized in the suite_test.go in the BeforeSuite, I assumed that this would be run as part of the ginkgo/integration tests and not for the unit tests when running go test -run=TestMachineFinalizer

Copy link
Member

Choose a reason for hiding this comment

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

Good to know, thanks!

controllers/machine_controller_test.go Outdated Show resolved Hide resolved

func TestRemoveMachineFinalizerAfterDeleteReconcile(t *testing.T) {
RegisterTestingT(t)
clusterv1.AddToScheme(scheme.Scheme)
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be needed

Signed-off-by: Warren Fernandes <wfernandes@pivotal.io>
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 8, 2019
@ncdc
Copy link
Contributor

ncdc commented Oct 8, 2019

/approve
@vincepri or @detiber - one of you want to do final review? If not, let me know & I'll look more closely 😄

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ncdc, wfernandes

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 8, 2019
Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 8, 2019
@k8s-ci-robot k8s-ci-robot merged commit aa86af2 into kubernetes-sigs:master Oct 8, 2019
@wfernandes wfernandes deleted the add-machine-controller-tests branch October 8, 2019 18:11
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants