How to point stripe-go to stripe-mock local server?

Viewed 1278

I am using stripe-go to perform Stripe actions such as create a new customer, add a credit card, create a subscription and so on. I want to perform end-to-end testing. There is stripe-mock which is a mock HTTP server that responds like the real Stripe API. I have that running locally in a terminal. How do I point my stripe-go which I am using in my Go application to make calls to this mock HTTP server instead of the real Stripe API.

In the stripe-go documentation there is this

// Setup
stripe.Key = "sk_key"

stripe.SetBackend("api", backend) // optional, useful for mocking

Am I supposed to pass something special as backend so that stripe-go knows to then make calls to http://localhost:12111 which is the address of stripe-mock?

This is stripe.SetBackend

// SetBackend sets the backend used in the binding.
func SetBackend(backend SupportedBackend, b Backend) {
    switch backend {
    case APIBackend:
        backends.API = b
    case UploadsBackend:
        backends.Uploads = b
    }
}

This is Backend

// Backend is an interface for making calls against a Stripe service.
// This interface exists to enable mocking for during testing if needed.
type Backend interface {
    Call(method, path, key string, body *RequestValues, params *Params, v interface{}) error
    CallMultipart(method, path, key, boundary string, body io.Reader, params *Params, v interface{}) error
}
1 Answers
Related