-
Notifications
You must be signed in to change notification settings - Fork 367
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
Report usage of StripeClient #1698
Conversation
2cf8397
to
e2ece8d
Compare
@@ -121,6 +121,9 @@ public void setUpStripeMockUsage() { | |||
httpClientSpy = Mockito.spy(new HttpURLConnectionClient()); | |||
networkSpy = Mockito.spy(new LiveStripeResponseGetter(null, httpClientSpy)); | |||
mockClient = new StripeClient(networkSpy); | |||
// The StripeClient constructor calls .setUsage on networkSpy, let's reset that so | |||
// in the test cases we can just verify the calls we care about. | |||
Mockito.reset(networkSpy); |
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.
Should we change our test infra to have 2 spies / separate LiveStripeResponseGetter
s for APIResource
and StripeClient
?
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.
My worry with that, is that we would then need to make copies of all the other helper functions here that use networkSpy
and it might be a bad experience when you're writing a test to have to choose between them and select the right one, and I hesitated to make the experience worse in 95% of cases for an edge case that only affects usage-related tests.
I was on the fence though, let me know what you prefer.
Changelog
StripeClient
inX-Stripe-Client-Telemetry
. (You can disable telemetry viaStripe.enableTelemetry = false;
, see the README.)Details
LiveStripeResponseGetter
a mutable "usage" that it will set on all requests it creates.StripeClient
constructor to set usage on itsLiveStripeResponseGetter
to["stripe_client"]
.RequestTelemetry
to accept usage and set it appropriately onX-Stripe-Client-Telemetry
. Had to add a parameter to a public method, so I made a new overload and deprecated the old one. Had to disable a linter rule to do this.Testing
src/test/java/com/stripe/functional/StripeClientTest.java
and src/test/java/com/stripe/functional/LiveStripeResponseGetterTest.java mock at the HttpClient level.