From 5a748e8c9296c1483680ff710ff924015d06559b Mon Sep 17 00:00:00 2001 From: Brandur Date: Tue, 17 Jul 2018 11:25:18 -0700 Subject: [PATCH] Wire an `http.Client` from `NewBackends` through to backends In #611 I accidentally introduced a regression in the `NewBackends` function in that an `http.Client` passed into the function isn't actually wired through to the new backends. Here we fix that problem by changing the invocations to use `GetBackendWithConfig` like they were supposed to. Fixes #626. --- stripe.go | 5 +++-- stripe_test.go | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/stripe.go b/stripe.go index 81c25a62f6..533e6d194e 100644 --- a/stripe.go +++ b/stripe.go @@ -610,9 +610,10 @@ func Int64Value(v *int64) int64 { // NewBackends creates a new set of backends with the given HTTP client. You // should only need to use this for testing purposes or on App Engine. func NewBackends(httpClient *http.Client) *Backends { + config := &BackendConfig{HTTPClient: httpClient} return &Backends{ - API: GetBackend(APIBackend), - Uploads: GetBackend(UploadsBackend), + API: GetBackendWithConfig(APIBackend, config), + Uploads: GetBackendWithConfig(UploadsBackend, config), } } diff --git a/stripe_test.go b/stripe_test.go index 129b55699f..c1ad9b56df 100644 --- a/stripe_test.go +++ b/stripe_test.go @@ -126,6 +126,13 @@ func TestIdempotencyKey(t *testing.T) { assert.Equal(t, "idempotency-key", req.Header.Get("Idempotency-Key")) } +func TestNewBackends(t *testing.T) { + httpClient := &http.Client{} + backends := stripe.NewBackends(httpClient) + assert.Equal(t, httpClient, backends.API.(*stripe.BackendConfiguration).HTTPClient) + assert.Equal(t, httpClient, backends.Uploads.(*stripe.BackendConfiguration).HTTPClient) +} + func TestStripeAccount(t *testing.T) { c := stripe.GetBackend(stripe.APIBackend).(*stripe.BackendConfiguration) p := &stripe.Params{}