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
use functional options pattern in tests #13242
Conversation
✔️ 🥰 Documentation preview ready! 🥰 🔨 Explore the source changes: 0b985bf 🔍 Inspect the deploy log: https://app.netlify.com/sites/kyma-project-docs-preview/deploys/61f95d3656081b00070edeed 😎 Browse the preview: https://deploy-preview-13242--kyma-project-docs-preview.netlify.app |
1bd9c8d
to
cdcd51d
Compare
} | ||
|
||
// WithServiceWithPathAsSink sets a kubernetes service as the sink | ||
func WithServiceWithPathAsSink(svc *corev1.Service, path string) SubscriptionOpt { |
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.
nit:I am thinking whether we can avoid double With
🤔 Since this is nothing else than WithSinkURL
but with input from the svc
and path
, what about the following name: WithSinkURLFromSvcAndPath
?
It is a bit long, but by autocompleting I can immediately see that it is similar to WithSinkURL
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.
If you like the suggestion we can also use it in WithServiceAsSink
=> WithSinkURLFromSvc
. If you don't, then just keep it as it is :)
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.
👍
}() | ||
func WithBinaryContentMode() ProtoOpt { | ||
return func(p *eventingv1alpha1.ProtocolSettings) { | ||
p.ContentMode = func() *string { |
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.
Don't we have a utility function to create a string pointer ?
I found utils.BoolPtr
and utils.Int32Ptr
here:https://github.com/nachtmaar/kyma/blob/13029-retry-fail-publish/components/eventing-controller/utils/utils.go#L56
We could add utils.StringPtr
as well :)
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.
👍
Port: &port, | ||
Host: &host, | ||
IsExternal: &isExternal, | ||
func WithService(host, svcName string) APIRuleOption { |
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.
👍 for returning a APIRuleOption instead of setting the variables directly.
return func(s *eventingv1alpha1.Subscription) { | ||
s.Spec.Sink = sinkURL | ||
} | ||
func WithOrderCreatedFilter() SubscriptionOpt { |
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.
Out of curiosity for our style guidelines: Do you prefer WithOrderCreatedFilter
over WithFilter
OrderCreated and if yes why ? :)
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 question:
WithOrderCreatedFilter
: it is a OrderCreatedFilter
, but a bit harder to spot in the IDEs completion popup
WithFilterOrderCreated
: it sounds a bit off, but really easy to spot in the IDE
I don't have any preference. If you want me to change it i will do this.
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.
WithFilterOrderCreated
sounds like we are filtering some OrderCreated
items. Putting Filter
at the end of the words makes --in my option-- clear, that this handles some kind of a Filter
object.
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 personally like WithFilterOrderCreated
more because it enables easier auto completion, but I agree that WithOrderCreatedFilter
sounds better. No need to change for me.
return &eventingv1alpha1.EventingBackend{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: name, | ||
Namespace: ns, | ||
Namespace: namespace, |
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.
(optional): Out of curiosity: Do you have a rule in your mind when you shorten or lengthen a variable name ?
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.
E.g. you shortened apiRule
to r
and lengthened ns
to namespace
.
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 point, will make it more consistent
optWebhook := reconcilertesting.WithWebhookAuthForBEB | ||
subscription := reconcilertesting.NewSubscription(subscriptionName, namespaceName, optFilter, optWebhook) | ||
reconcilertesting.WithValidSink(namespaceName, subscriberSvc.Name, subscription) | ||
subscription := reconcilertesting.NewSubscription(subscriptionName, namespaceName, |
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.
Much cleaner and easier to read IMHO 👍
@@ -98,8 +98,9 @@ func NewReconciler(ctx context.Context, client client.Client, applicationLister | |||
// +kubebuilder:rbac:groups=gateway.kyma-project.io,resources=apirules,verbs=get;list;watch;create;update;patch;delete | |||
// +kubebuilder:printcolumn:name="Ready",type=bool,JSONPath=`.status.Ready` | |||
|
|||
// TODO: Optimize number of reconciliation calls in eventing-controller #9766: https://github.com/kyma-project/kyma/issues/9766 | |||
// Reconcile sets up |
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 think there is something missing here :-D
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.
😄
b64d770
to
ffc3fb3
Compare
Co-authored-by: Nils Seip <github@nilstschmidt.de>
Description
Changes proposed in this pull request:
Related issue(s)