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

Refactor kncloudevent package to be able to use a test client #7075

Closed
wants to merge 4 commits into from

Conversation

creydr
Copy link
Member

@creydr creydr commented Jul 3, 2023

Currently the kncloudevents.NewRequest always uses an http(s) client to do the requests. This can make unit testing sometimes a bit harder.
This PR addresses it and refactors the package, so we abstract the current behavior behind a new interface (Client) and also adds a new testClient, which kind of mocks the behavior of the http client.

@knative-prow
Copy link

knative-prow bot commented Jul 3, 2023

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@knative-prow knative-prow bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 3, 2023
@creydr
Copy link
Member Author

creydr commented Jul 3, 2023

/test all

@knative-prow
Copy link

knative-prow bot commented Jul 3, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: creydr

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot requested review from lberk and matzew July 3, 2023 17:11
@knative-prow knative-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 3, 2023
@codecov
Copy link

codecov bot commented Jul 3, 2023

Codecov Report

Patch coverage: 66.85% and project coverage change: -0.19 ⚠️

Comparison is base (cb2a891) 78.75% compared to head (268d918) 78.57%.

❗ Current head 268d918 differs from pull request most recent head d60666d. Consider uploading reports for the commit d60666d to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7075      +/-   ##
==========================================
- Coverage   78.75%   78.57%   -0.19%     
==========================================
  Files         248      251       +3     
  Lines       13148    13297     +149     
==========================================
+ Hits        10355    10448      +93     
- Misses       2273     2319      +46     
- Partials      520      530      +10     
Impacted Files Coverage Δ
pkg/adapter/mtping/runner.go 80.48% <0.00%> (ø)
pkg/reconciler/source/duck/duck.go 74.68% <0.00%> (-2.05%) ⬇️
pkg/resolver/kresource_resolver.go 0.00% <ø> (ø)
pkg/broker/ingress/ingress_handler.go 70.23% <11.11%> (-7.10%) ⬇️
pkg/channel/message_dispatcher.go 73.30% <28.57%> (-1.70%) ⬇️
pkg/kncloudevents/request.go 80.90% <40.00%> (ø)
pkg/kncloudevents/client.go 57.14% <57.14%> (ø)
pkg/broker/ttl.go 71.42% <66.66%> (ø)
pkg/broker/eventtypes.go 72.22% <72.22%> (ø)
pkg/kncloudevents/test/client.go 85.18% <85.18%> (ø)
... and 5 more

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@creydr creydr changed the title [WIP] Refactor kncloudevent package to be able to use a test client Refactor kncloudevent package to be able to use a test client Jul 4, 2023
@creydr creydr marked this pull request as ready for review July 4, 2023 07:37
@knative-prow knative-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 4, 2023
@creydr
Copy link
Member Author

creydr commented Jul 4, 2023

/assign @pierDipi

@pierDipi
Copy link
Member

pierDipi commented Jul 4, 2023

Currently the kncloudevents.NewRequest always uses an http(s) client to do the requests. This can make unit testing sometimes a bit harder.

Can you expand on this? what's harder?

@creydr
Copy link
Member Author

creydr commented Jul 4, 2023

Currently the kncloudevents.NewRequest always uses an http(s) client to do the requests. This can make unit testing sometimes a bit harder.

Can you expand on this? what's harder?

tl;dr; with the FakeClient it's not required anymore to spin up a server in a unit test, to check if events were sent, when using a kncloudevents.Client.

In another branch, I am currently working on replacing the CloudEventsSDK client with the kncloudevents package client. The CE SDK client is used in some places with a FakeClient (e.g. in

ce := adaptertesting.NewTestClient()
). So instead of requiring the developer in a unit test to spin up a server with some custom handlers to check if events were sent, I added this FakeClient, which implements the Client interface and provides a method to check the sent events via this client.

@knative-prow
Copy link

knative-prow bot commented Jul 4, 2023

@creydr: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
reconciler-tests_eventing_main d60666d link true /test reconciler-tests

Your PR dashboard.

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.

@creydr
Copy link
Member Author

creydr commented Jul 5, 2023

/test unit-tests

@creydr creydr closed this Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants