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 test for machine controller reconcile #650

Merged

Conversation

enxebre
Copy link
Member

@enxebre enxebre commented Dec 20, 2018

What this PR does / why we need it:
Add uni test for machine controller reconcile

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

Special notes for your reviewer:

Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.

Release note:


@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 20, 2018
@k8s-ci-robot
Copy link
Contributor

Hi @enxebre. 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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 20, 2018
@davidewatson
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 20, 2018
@davidewatson
Copy link
Contributor

@enxebre: This appears to conflict with an existing tests:

W1220 22:09:24.921] pkg/controller/machine/machine_controller_test.go:38:23: TestReconcile redeclared in this block
W1220 22:09:24.922] 	previous declaration at pkg/controller/machine/controller_test.go:31:23

@roberthbailey
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 21, 2018
Copy link
Contributor

@roberthbailey roberthbailey left a comment

Choose a reason for hiding this comment

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

},
},
}
err := c.Client.List(ctx, listOptions, &clusterList)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: This should be cuddled, e.g. if err := c.Client.List(...); err != nil { ... }

@enxebre enxebre force-pushed the machine-reconcile-test branch from e874214 to 9efd834 Compare December 21, 2018 08:31
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 21, 2018
@enxebre
Copy link
Member Author

enxebre commented Dec 21, 2018

@roberthbailey I changed the unit introduced here to TestReconcileRequest please let me know if anyone has a better suggestion

@detiber
Copy link
Member

detiber commented Dec 21, 2018

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 21, 2018
@enxebre enxebre force-pushed the machine-reconcile-test branch from 9efd834 to 6ec3bdd Compare December 21, 2018 15:55
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 21, 2018
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 Dec 21, 2018
@vincepri
Copy link
Member

/assign @roberthbailey @justinsb

)

func TestReconcileRequest(t *testing.T) {
m1 := v1alpha1.Machine{
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, use at least three letters long identifiers:

  • s/m1/machine1/
  • s/m2/machine2/
  • s/m3/machine3/
  • s/c/cluster/
  • s/cl/clusterList/

E.g. c identifies are very hard to find (as other identifiers contain the c letter), m1 (m, one) tends to look like (m, l), the same for cl (c, l) as (c, one).

DeletionTimestamp: &time,
},
}
c := v1alpha1.Cluster{
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if it is used only once. Though, if so, it can be embedded into ClusterList.

}
testCases := []struct {
request reconcile.Request
ExistsValue bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the field need to be exported? existsValue will do as well otherwise.

}

for _, tc := range testCases {
a := newTestActuator()
Copy link
Contributor

Choose a reason for hiding this comment

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

s/a/act, s/a/actuator or s/a/tesActuator

@ingvagabund
Copy link
Contributor

Can you also extend testactuator.go with:

var _ Actuator = &TestActuator{}

? So the fact that TestActuator implements Actuator interface is checked during compilation.

@enxebre enxebre force-pushed the machine-reconcile-test branch from 6ec3bdd to 63b02d9 Compare January 2, 2019 11:14
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 2, 2019
@roberthbailey
Copy link
Contributor

It looks like there are a couple of outstanding comments from @ingvagabund. Can you address / resolve those and then we can merge this.

@enxebre enxebre force-pushed the machine-reconcile-test branch from 63b02d9 to 16031bd Compare January 3, 2019 09:03
@enxebre
Copy link
Member Author

enxebre commented Jan 3, 2019

/test pull-cluster-api-test

@enxebre enxebre force-pushed the machine-reconcile-test branch from 16031bd to abc48d6 Compare January 3, 2019 10:03
@ingvagabund
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 4, 2019
@roberthbailey
Copy link
Contributor

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: enxebre, roberthbailey

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 Jan 8, 2019
@k8s-ci-robot k8s-ci-robot merged commit 59a129b into kubernetes-sigs:master Jan 8, 2019
jayunit100 pushed a commit to jayunit100/cluster-api that referenced this pull request Jan 31, 2020
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.

8 participants