Documentation
¶
Index ¶
- func AssertBadRequest(t *testing.T, response *Response)
- func AssertBodyContains(t *testing.T, response *Response, substring string)
- func AssertBodyEquals(t *testing.T, response *Response, expected string)
- func AssertCreated(t *testing.T, response *Response)
- func AssertForbidden(t *testing.T, response *Response)
- func AssertHeader(t *testing.T, response *Response, key, expectedValue string)
- func AssertJSON(t *testing.T, response *Response, expectedJSON interface{})
- func AssertJSONPath(t *testing.T, response *Response, path string, expectedValue interface{})
- func AssertJSONSchema(t *testing.T, response *Response, requiredFields []string)
- func AssertNoContent(t *testing.T, response *Response)
- func AssertNotFound(t *testing.T, response *Response)
- func AssertOK(t *testing.T, response *Response)
- func AssertStatus(t *testing.T, response *Response, expectedCode int)
- func AssertUnauthorized(t *testing.T, response *Response)
- type HTTPClient
- func (c *HTTPClient) DELETE(path string, headers map[string]string) *Response
- func (c *HTTPClient) Do(req Request) *Response
- func (c *HTTPClient) GET(path string, query url.Values, headers map[string]string) *Response
- func (c *HTTPClient) PATCH(path string, body interface{}, headers map[string]string) *Response
- func (c *HTTPClient) POST(path string, body interface{}, headers map[string]string) *Response
- func (c *HTTPClient) PUT(path string, body interface{}, headers map[string]string) *Response
- func (c *HTTPClient) WithBaseURL(baseURL string) *HTTPClient
- type Request
- type Response
- type TestCase
- type TestSuite
- func (ts *TestSuite) AssertHeader(w *httptest.ResponseRecorder, key, value string)
- func (ts *TestSuite) AssertHeaderContains(w *httptest.ResponseRecorder, key, value string)
- func (ts *TestSuite) AssertJSON(w *httptest.ResponseRecorder, expected interface{})
- func (ts *TestSuite) AssertJSONContains(w *httptest.ResponseRecorder, key string, value interface{})
- func (ts *TestSuite) AssertStatus(w *httptest.ResponseRecorder, status int)
- func (ts *TestSuite) Request(method, path string, body interface{}, headers map[string]string) *httptest.ResponseRecorder
- func (ts *TestSuite) RunTestCase(tc TestCase)
- func (ts *TestSuite) RunTestCases(cases []TestCase)
- func (ts *TestSuite) UploadFile(path, fieldName, filePath string, additionalFields map[string]string) *httptest.ResponseRecorder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertBadRequest ¶
AssertBadRequest 断言HTTP状态码为400 Bad Request
func AssertBodyContains ¶
AssertBodyContains 断言响应体包含特定字符串
func AssertBodyEquals ¶
AssertBodyEquals 断言响应体等于特定字符串
func AssertCreated ¶
AssertCreated 断言HTTP状态码为201 Created
func AssertForbidden ¶
AssertForbidden 断言HTTP状态码为403 Forbidden
func AssertHeader ¶
AssertHeader 断言HTTP头部值
func AssertJSON ¶
AssertJSON 断言JSON响应体
func AssertJSONPath ¶
AssertJSONPath 断言JSON响应体中特定路径的值
func AssertJSONSchema ¶
AssertJSONSchema 断言JSON响应体符合指定的JSON Schema(简化版,仅检查必填字段)
func AssertNoContent ¶
AssertNoContent 断言HTTP状态码为204 No Content
func AssertNotFound ¶
AssertNotFound 断言HTTP状态码为404 Not Found
func AssertStatus ¶
AssertStatus 断言HTTP状态码
func AssertUnauthorized ¶
AssertUnauthorized 断言HTTP状态码为401 Unauthorized
Types ¶
type HTTPClient ¶
HTTPClient 是测试HTTP请求的客户端
func NewHTTPClient ¶
func NewHTTPClient(t *testing.T, engine *flow.Engine) *HTTPClient
NewHTTPClient 创建一个新的HTTP测试客户端
func (*HTTPClient) DELETE ¶
func (c *HTTPClient) DELETE(path string, headers map[string]string) *Response
DELETE 发送DELETE请求
func (*HTTPClient) PATCH ¶
func (c *HTTPClient) PATCH(path string, body interface{}, headers map[string]string) *Response
PATCH 发送PATCH请求
func (*HTTPClient) POST ¶
func (c *HTTPClient) POST(path string, body interface{}, headers map[string]string) *Response
POST 发送POST请求
func (*HTTPClient) PUT ¶
func (c *HTTPClient) PUT(path string, body interface{}, headers map[string]string) *Response
PUT 发送PUT请求
func (*HTTPClient) WithBaseURL ¶
func (c *HTTPClient) WithBaseURL(baseURL string) *HTTPClient
WithBaseURL 设置基础URL
type Request ¶
type Request struct {
Method string
Path string
Headers map[string]string
Body interface{}
Query url.Values
}
Request 定义HTTP请求结构
type Response ¶
type Response struct {
StatusCode int
Header http.Header
Body []byte
Result interface{}
Raw *httptest.ResponseRecorder
}
Response 定义HTTP响应结构
type TestCase ¶
type TestCase struct {
Name string
Method string
Path string
Headers map[string]string
Body interface{}
Query url.Values
ExpectedStatus int
ExpectedBody interface{}
Setup func(t *testing.T)
Teardown func(t *testing.T)
Handler flow.HandlerFunc
Middleware []flow.HandlerFunc
}
TestCase 定义测试用例结构
type TestSuite ¶
TestSuite 定义测试套件结构
func (*TestSuite) AssertHeader ¶
func (ts *TestSuite) AssertHeader(w *httptest.ResponseRecorder, key, value string)
AssertHeader 断言Header等于指定值
func (*TestSuite) AssertHeaderContains ¶
func (ts *TestSuite) AssertHeaderContains(w *httptest.ResponseRecorder, key, value string)
AssertHeaderContains 断言Header包含指定值
func (*TestSuite) AssertJSON ¶
func (ts *TestSuite) AssertJSON(w *httptest.ResponseRecorder, expected interface{})
AssertJSON 断言JSON响应
func (*TestSuite) AssertJSONContains ¶
func (ts *TestSuite) AssertJSONContains(w *httptest.ResponseRecorder, key string, value interface{})
AssertJSONContains 断言JSON响应中包含指定字段
func (*TestSuite) AssertStatus ¶
func (ts *TestSuite) AssertStatus(w *httptest.ResponseRecorder, status int)
AssertStatus 断言HTTP状态码
func (*TestSuite) Request ¶
func (ts *TestSuite) Request(method, path string, body interface{}, headers map[string]string) *httptest.ResponseRecorder
Request 执行HTTP请求
func (*TestSuite) RunTestCases ¶
RunTestCases 运行多个测试用例
func (*TestSuite) UploadFile ¶
func (ts *TestSuite) UploadFile(path, fieldName, filePath string, additionalFields map[string]string) *httptest.ResponseRecorder
UploadFile 上传文件测试辅助函数