-
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
🌱 Adds tests for InitImages #3233
Conversation
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA. It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.
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. I understand the commands that are listed here. |
Welcome @joaopapereira! |
Hi @joaopapereira. Thanks for your PR. I'm waiting for a kubernetes-sigs 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. |
/check-cla |
/assign |
/ok-to-test |
/check-cla |
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.
Thanks so much for adding these tests! I made a few suggestions but so far it's looking good. 🙂
config.NewProvider("some-core-provider", "some-core-url", clusterctlv1.CoreProviderType), | ||
}, | ||
wantErr: true, | ||
expectedErrorMessage: "name cluster-api must be used with the CoreProvider type", |
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.
I suggest not asserting on the actual content of the error message but rather that an error occurred.
One reason is that the tests are a good source of documentation for the code. When I saw this, I went looking for the code that was returning this error only to find myself digging into the internals of config/providers_client.go
in the validateProvider
method.
Normally I lean towards testing the behavior that an error is expected to have occurred rather than an error with a specific message has occurred.
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.
lol, it took me a minute to write this comment out, because I do agree with you. Usually when testing a single function I would also not "care" about the type of error being returned. But in this case (I came with the lense of someone that is looking for the first time to the code) the InitImages function relies in at least 2 other functions that have their own use cases for errors. So I went this route, because I found myself having to look throught these functions to find a way to make the test that would break the current implementation.
I added the assertion on the error message itself, because I wanted to make sure that these tests where failing for the correct reasons, and not just failing, specially because we are backfilling tests, and not TDDing.
This being said, if you still feel like there is no need to have this assertion I am happy to remove it 😄
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.
Thanks for the explanation! Yeah...this is interesting because we aren't TDDing and instead backfilling the tests.
I think if there is potential for the given inputs in the test to produce different errors (due to the nested calls to other functions) then I guess it's fine to specify the error message or maybe that might hint to constraining the inputs further.
I do agree the important thing is to ensure that the test is failing for the correct reason. I see that this error is bubbled up through getComponentsByName
which could have returned an error from parsing the provider name. But since a valid provider name is used it goes past that to c.configClient.Providers().Get(name, providerType)
which then surfaces the error.
I guess we can't even use the errors.Cause
for something like this.
Hmm...this is definitely tripping me up as well and making me really think about this.
The only other concern is that I don't want other contributors to follow the pattern of performing substring matching on errors.
I see that @fabriziopandini 👍 so I think it's fine for now.
Feel free to squash commits regardless.
@wfernandes thanks for the review. Updated the PR with your comments |
I signed it |
bcbffbc
to
a91dd51
Compare
@joaopapereira thanks for this PR!
|
/check-cla |
a91dd51
to
c7aa27a
Compare
/check-cla |
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.
Found one minor thing but don't want to block the PR on it 🙂. Leaving approval for @fabriziopandini
/lgtm
cmd/clusterctl/client/init_test.go
Outdated
kubeconfigContext: "mgmt-context", | ||
}, | ||
wantErr: true, | ||
certManagerImagesErr: fmt.Errorf("failed to get cert images"), |
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.
minor nit: since we aren't really formatting the string.
certManagerImagesErr: fmt.Errorf("failed to get cert images"), | |
certManagerImagesErr: errors.New("failed to get cert images"), |
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.
I changed that in my last push
c7aa27a
to
f06f486
Compare
f06f486
to
abef442
Compare
- Add new functionality to creation of fake clusters to allow the cert manager client to be injected - Add constructor for fake certificate manager client
abef442
to
42c3212
Compare
As per #3233 (comment) comment, I'm fine with the code as it is. We can eventually remove in future if this is used as precedence. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: fabriziopandini 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 |
/lgtm |
What this PR does / why we need it:
As per the issue #2871 some test coverage was missing from Client InitImages. This PR adds more testing coverage of the functionality of this method.
This PR also changes the
fakeClusterClient
to enable the injection of afakeCertManagerClient
Which issue(s) this PR fixes
Fixes #2871