【发布时间】:2017-11-28 19:23:42
【问题描述】:
我正在使用stripe-go 执行 Stripe 操作,例如创建新客户、添加信用卡、创建订阅等。我想执行端到端测试。 stripe-mock 是一个模拟 HTTP 服务器,其响应类似于真正的 Stripe API。我在终端本地运行。如何将我在 Go 应用程序中使用的 stripe-go 指向这个模拟 HTTP 服务器而不是真正的 Stripe API。
在 stripe-go 文档中有这个
// Setup
stripe.Key = "sk_key"
stripe.SetBackend("api", backend) // optional, useful for mocking
我是否应该传递一些特殊的东西作为backend 以便stripe-go 知道然后调用http://localhost:12111 这是stripe-mock 的地址?
这是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
}
}
这是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
}
【问题讨论】:
标签: go integration-testing stripe-payments