Skip to content
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

Merged
merged 14 commits into from Feb 2, 2022

Conversation

k15r
Copy link
Contributor

@k15r k15r commented Feb 1, 2022

Description

Changes proposed in this pull request:

  • more consistent way to setup resource in our test

Related issue(s)

@k15r k15r requested a review from a user February 1, 2022 16:10
@k15r k15r requested a review from vpaskar as a code owner February 1, 2022 16:10
@k15r k15r added the area/eventing Issues or PRs related to eventing label Feb 1, 2022
@kyma-bot kyma-bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Feb 1, 2022
@netlify
Copy link

netlify bot commented Feb 1, 2022

✔️ 🥰 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

@friedrichwilken friedrichwilken self-assigned this Feb 1, 2022
@nachtmaar nachtmaar self-assigned this Feb 2, 2022
@k15r k15r added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 2, 2022
}

// WithServiceWithPathAsSink sets a kubernetes service as the sink
func WithServiceWithPathAsSink(svc *corev1.Service, path string) SubscriptionOpt {
Copy link
Contributor

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

Copy link
Contributor

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 :)

Copy link
Contributor Author

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 {
Copy link
Contributor

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 :)

Copy link
Contributor Author

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 {
Copy link
Contributor

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 {
Copy link
Contributor

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 WithFilterOrderCreated and if yes why ? :)

Copy link
Contributor Author

@k15r k15r Feb 2, 2022

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

components/eventing-controller/testing/test_helpers.go Outdated Show resolved Hide resolved
return &eventingv1alpha1.EventingBackend{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: ns,
Namespace: namespace,
Copy link
Contributor

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 ?

Copy link
Contributor

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.

Copy link
Contributor Author

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,
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄

nachtmaar
nachtmaar previously approved these changes Feb 2, 2022
@kyma-bot kyma-bot added the lgtm Looks good to me! label Feb 2, 2022
@kyma-bot kyma-bot removed the lgtm Looks good to me! label Feb 2, 2022
@k15r k15r removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 2, 2022
@kyma-bot kyma-bot added the lgtm Looks good to me! label Feb 2, 2022
@kyma-bot kyma-bot merged commit fbc8561 into kyma-project:main Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/eventing Issues or PRs related to eventing lgtm Looks good to me! size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants