-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
🏃Add unit tests for machine controller #1493
Conversation
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 Once the patch is verified, the new status will be reflected by the 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. |
/ok-to-test I'll take a look this afternoon |
/lgtm |
|
||
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()) |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
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.
clusterv1.AddToScheme(scheme.Scheme) | ||
mr := &MachineReconciler{ | ||
Client: fake.NewFakeClientWithScheme( | ||
scheme.Scheme, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know, thanks!
|
||
func TestRemoveMachineFinalizerAfterDeleteReconcile(t *testing.T) { | ||
RegisterTestingT(t) | ||
clusterv1.AddToScheme(scheme.Scheme) |
There was a problem hiding this comment.
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>
eaa3d91
to
73af52b
Compare
[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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
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