Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Go 如何将条带指向条带模拟本地服务器?_Go_Integration Testing_Stripe Payments - Fatal编程技术网

Go 如何将条带指向条带模拟本地服务器?

Go 如何将条带指向条带模拟本地服务器?,go,integration-testing,stripe-payments,Go,Integration Testing,Stripe Payments,我正在使用执行条带操作,例如创建新客户、添加信用卡、创建订阅等。我想进行端到端测试。有一个模拟HTTP服务器,它的响应类似于真正的条带API。我在终端本地运行。我如何指向我在go应用程序中使用的stripe go来调用这个模拟HTTP服务器,而不是真正的stripe API 在stripe go文档中有以下内容 // Setup stripe.Key = "sk_key" stripe.SetBackend("api", backend) // optional, useful for moc

我正在使用执行条带操作,例如创建新客户、添加信用卡、创建订阅等。我想进行端到端测试。有一个模拟HTTP服务器,它的响应类似于真正的条带API。我在终端本地运行。我如何指向我在go应用程序中使用的stripe go来调用这个模拟HTTP服务器,而不是真正的stripe API

在stripe go文档中有以下内容

// Setup
stripe.Key = "sk_key"

stripe.SetBackend("api", backend) // optional, useful for mocking
我是否应该传递一些特殊的东西作为
后端
,以便stripe go知道然后调用哪个是stripe mock的地址

这是条带。收进

// 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 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
}
这是
后端

// 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 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
}
从内部看,公开的
后端配置
结构实现了
后端
接口。因此,以下措施应该有效:

httpClient := &http.Client{Timeout: defaultHTTPTimeout}

mockBackend := &stripe.BackendConfiguration{
      "api", 
      "http://localhost:12111", 
      httpClient,
}

stripe.SetBackend("api", mockBackend)