-
Notifications
You must be signed in to change notification settings - Fork 60
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
🌱Added function to update control plane endpoint #1004
Conversation
Hi @janiskemper . Okay basic question. I have worked with a few unit tests earlier however they were for relatively simpler Go code probably hence they contained functions such as func Testxxx(). Now going through hetznercluster_controller_tests.go its a little different. I've tried going through the test file and I'm still understanding things, but can you maybe just point me to the right direction with where do I start. |
that's exactly why I said
yes you can and should proceed like that |
Oh okay okay. Aight. I'll proceed this way. Thank you Janis |
Hey @janiskemper can you please go through the below code?
|
I'm not sure what "args" is in your code... |
Oh I'm sorry. I had created a type which includes the hetznercluster. Wait I'll put in the code: (cc @janiskemper)
|
Hey @janiskemper . I'd really appreciate if you can provide feedback on the latest commit. As of now I've kept the two test cases almost same, I understand I will have to make changes to them. But I feel a little lost as to how do I make updates with the hetznercluster parameter. Like how do I set a case in which the test returns false, and how do I set a case in which a test returns true, this is what is confusing me. I hope I'm able to convey my point. I also hope I am going in the right direction. I'd really appreciate your feedback. |
From the code side you have created a pattern that you can use to write tests. But I would say that you struggle right now what you should test.. According to the pattern One shortcoming of your current approach is that not only it is interesting which boolean the function returns, but also the changes to the hetznerCluster have to be validated. I suggest that you first start with a list of tests that you wanna implement... Not writing code yet, just what would make sense to do. |
Okay so according to the code above I feel we'd want a few specefic test cases to take place which return true:
If none of these match then the function should return false. Seeing the above conditions, I think I should include three test cases. However, the problem still persists, how should I mention these conditions when writing the unit test? I dont think its supposed to be mentioned in the tests struct or is it? |
I believe that there are a lot more possible tests. Pretty much every if-else statement gives you another possibility to test something |
Oh, I'll look into this. I thought I'd maybe base my test cases solely on the return statements. |
@janiskemper whats confusing me is that if I take the if statement |
…ge to hetznercluster_controller.go
@janiskemper Can you please review the latest commit? |
the main part of the test should also be to check the changes that have been made to the hetznercluster... that you don't test currently" |
Ahan. @janiskemper can you please elaborate on that a little. Like are we talking about the changes to |
about hetznerCluster.Spec.ControlPlaneEndpoint in general, yeys |
I'm sorry @janiskemper I feel a little lost as to what am I missing. I'll add another commit maybe rephrasing the test case names. I've tried addressing changes being made to the ControlPlaneEndpoint.Host and ControlPlaneEndpoint.Port in the first two test cases. Can you please go through it? |
you just have to also include test cases for changes of hetznerCluster.Spec.ControlPlaneEndpoint.. At the moment you only test the return boolean in https://github.com/syself/cluster-api-provider-hetzner/pull/1004/files#diff-17dd1bcc2376d005c272189be910b2625e9a01d4bc08d71663eb972ed88f0df6R877. |
Hi @janiskemper. Upon going through the recent activity, I think I maybe have a better idea of what you're asking. Please verify if my understanding is right about this. |
yes, exactly! |
@janiskemper. So I was earlier adding test cases, but I think the test cases are fine, like I do not need to add more. The condition I added should be okay right? Or would you recommend adding another test case? |
can you maybe take a step back and think about every test that you could potentially do? Because I think this structure of the fixed table-driven test holds you back. Just make a list of tests that could be implemented. I believe we are still missing out many |
Am I approaching this correct? |
just for an example: What if controlPlaneLoadBalancer is not enabled? Then other things happen.. You can really go through the whole logic and pretty much any possible combination of things that might happen can be (theoretically) tested. |
Okay just clearing out with this example, wouldn't the answer just be that the
Can you go through the function maybe and point another example over here. I'd really appreciate it |
you can check what happens if load balancer is not enabled and if the controlPlaneEndpoint is nil / not nil. |
🤦 . I'm sorry @janiskemper. Earlier you mentioned about checking changes made to hetznercluster, I think I got very zoomed in on that only. I was trying to avoid want statements, which is why it did not make sense to me. Can you please go through the latest commit. I feel that there can be more test cases with more values, but they'll more or less be same. Is there still something that I'm missing. |
maybe you can do the following: I think the table-driven test really makes you think very one-directional. Can you completely get rid of it and do one test case after another? I think that would really help you... I mentioned a lot of tests in my previous comment that you can potentially do. |
I thought I made test cases for all the test cases you suggested? I'm defo missing some major point. I can discard all my tests and restart from line one. Would you suggest I do that? |
you implented table driven tests. Can you re-implement what you currently have (and maybe new tests) in a manner that doesn't use table-driven tests? |
Writing a function for each test counts? Something similar to whats mentioned in this link [https://golang.cafe/blog/golang-table-test-example] |
yes, but maybe a pattern that uses |
Aight. I'll get started with this right away. |
closing as this is replaced by #1023 |
What this PR does / why we need it:
This one fixes a part of the issue #977. Added utiltiy function to update control plane endpoints.
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 #977
Special notes for your reviewer:
This is not the complete PR. I'll add the unit tests. I request to get my function reviewed. I want to know what I can make better with my function. I'm currently feeling a little unsure about the false condition that I've added to the end of the function which can potentially set the status of the hetzner cluster to false. Is it okay if it stays that way? Or do I edit it up? I'd love feedback.
Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.
No it does not
TODOs: