Ai
2 Star 0 Fork 0

mirrors_sourcegraph/stripe-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
error_test.go 959 Bytes
一键复制 编辑 原始数据 按行查看 历史
package stripe
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
assert "github.com/stretchr/testify/require"
)
func TestErrorError(t *testing.T) {
err := &Error{Type: "foo", Msg: "bar"}
assert.Equal(t, `{"message":"bar","type":"foo"}`, err.Error())
}
func TestErrorResponse(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Request-Id", "req_123")
w.WriteHeader(http.StatusUnauthorized)
fmt.Fprintln(w, `{"error":{"message":"bar","type":"`+ErrorTypeInvalidRequest+`"}}`)
}))
defer ts.Close()
backend := GetBackendWithConfig(APIBackend, &BackendConfig{
URL: ts.URL,
})
err := backend.Call(http.MethodGet, "/v1/account", "sk_test_badKey", nil, nil)
assert.Error(t, err)
stripeErr := err.(*Error)
assert.Equal(t, ErrorTypeInvalidRequest, stripeErr.Type)
assert.Equal(t, "req_123", stripeErr.RequestID)
assert.Equal(t, 401, stripeErr.HTTPStatusCode)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_sourcegraph/stripe-go.git
git@gitee.com:mirrors_sourcegraph/stripe-go.git
mirrors_sourcegraph
stripe-go
stripe-go
master

搜索帮助