Skip to content

Commit

Permalink
Wire an http.Client from NewBackends through to backends
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brandur committed Jul 17, 2018
1 parent d77c497 commit 5a748e8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions stripe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down
7 changes: 7 additions & 0 deletions stripe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down

0 comments on commit 5a748e8

Please sign in to comment.