-
Notifications
You must be signed in to change notification settings - Fork 596
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
feat: add unit test for createLBStatus #2408
Conversation
Hi @sakshi-1505. Thanks for your PR. I'm waiting for a 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 |
Looks good I think, just needs a rebase. |
/retest |
@dulek please take a look now |
bump @dulek @pierreprinetti |
Please squash the commits before this can be merged. |
/approve I'm leaving approval, will lgtm once it's squashed. |
Sorry for the delay here. Got busy in my studies, I will get this done asap
…On Fri, 13 Oct 2023 at 20:55, Kubernetes Prow Robot < ***@***.***> wrote:
[APPROVALNOTIFIER] This PR is *APPROVED*
This pull-request has been approved by: *dulek
<#2408 (comment)>*
The full list of commands accepted by this bot can be found here
<https://go.k8s.io/bot-commands?repo=kubernetes%2Fcloud-provider-openstack>
.
The pull request process is described here
<https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process>
Needs approval from an approver in each of these files:
- pkg/openstack/OWNERS
<https://github.com/kubernetes/cloud-provider-openstack/blob/master/pkg/openstack/OWNERS>
[dulek]
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
—
Reply to this email directly, view it on GitHub
<#2408 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BDCZVU44OAU4X3BC5ACUOJDX7FMOJAVCNFSM6AAAAAA5YMYVCGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONRRG4YDCOBSGE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
c66e151
to
2da2817
Compare
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dulek 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 |
@pierreprinetti @dulek Can you please approve this now? I did the rebase, there is addition of another test in this PR because the authors are adding test in b/w of the file rather than appending things at the end which is the major cause of all this conflicts & errors. |
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.
Your test is correct, as in: it validates the logic that is currently in place.
However, I think you could walk an extra mile and make it more robust.
Essentially, your test validates two fields of Status
: Hostname
and IP
. Now, imagine that tomorrow we need to add another field: for example (and this is totally made up), maximumConcurrentConnections
, that defaults to 1000.
As soon as we add that new field, your test fails, because you are comparing for equality an entire corev1.LoadBalancerStatus
object.
One way to make your test future-proof is to only check the properties you are actually testing for. Instead of comparing the entire object, you could check that the single Hostname
and IP
properties match what you need them to. Do you want to try that?
pkg/openstack/loadbalancer_test.go
Outdated
@@ -824,7 +937,6 @@ func Test_buildPoolCreateOpt(t *testing.T) { | |||
}) | |||
} | |||
} | |||
|
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.
Woops! Please leave this blank line in :)
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.
Done
pkg/openstack/loadbalancer_test.go
Outdated
}, | ||
}, | ||
{ | ||
name: "it should return fakehostname if proxyProtocal & IngressHostName is enabled without svc annotation", |
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.
little typo:
name: "it should return fakehostname if proxyProtocal & IngressHostName is enabled without svc annotation", | |
name: "it should return fakehostname if proxyProtocol & IngressHostName is enabled without svc annotation", |
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.
Fixed
fields: fields{ | ||
LoadBalancer: LoadBalancer{ | ||
opts: LoadBalancerOpts{ | ||
EnableIngressHostname: false, | ||
IngressHostnameSuffix: "test", | ||
}, | ||
}, | ||
}, |
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.
Is this setup required for the test case? Why did you choose to include 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.
Actually, this is included to make sure that if at some later time we change the way of getHostFromSVC annotation the function doesn't go into this code block https://github.com/kubernetes/cloud-provider-openstack/blob/60ad70c0b53d545f323df71b4603bfc8a98dd2df/pkg/openstack/loadbalancer.go#L1881C1-L1882C1. Moreover this is to ensure the declarative behaviour of the unit test as they should be.
3deab8f
to
b823e48
Compare
pkg/openstack/loadbalancer_test.go
Outdated
LoadBalancer: tt.fields.LoadBalancer, | ||
} | ||
if tt.want.HostName != "" { | ||
assert.Equal(t, tt.want.HostName, lbaas.createLoadBalancerStatus(tt.args.service, tt.args.svcConf, tt.args.addr).Ingress[0].Hostname) |
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'd call the function under test just once, save the result in a variable, and assert the variable. I know it's not a big deal in this case, but calling it once per assertion can be a problematic pattern when the function under test is more expensive.
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.
done
pkg/openstack/loadbalancer_test.go
Outdated
lbaas := &LbaasV2{ | ||
LoadBalancer: tt.fields.LoadBalancer, | ||
} | ||
if tt.want.HostName != "" { |
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.
What happens if you remove this conditional?
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 don't know why I believed that the want.result would be a pointer where it's a string type itself. I removed both conditional
pkg/openstack/loadbalancer_test.go
Outdated
if tt.want.HostName != "" { | ||
assert.Equal(t, tt.want.HostName, lbaas.createLoadBalancerStatus(tt.args.service, tt.args.svcConf, tt.args.addr).Ingress[0].Hostname) | ||
} | ||
if tt.want.IPAddress != "" { |
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.
What happens if you remove this conditional?
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.
Please take a look again @pierreprinetti |
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.
Looks good to me! Please apply the little fix in the inline comments, then squash, and we're ready to merge. Thank you!
6cefdb3
to
5f7262f
Compare
PLease review again @pierreprinetti , I have made all requested changes |
/lgtm |
What this PR does / why we need it:
Which issue this PR fixes(if applicable):
refers #2400
Special notes for reviewers:
Release note: