Documentation
¶
Overview ¶
internal/testutil/leak.go
internal/testutil/mock.go
Index ¶
- func DefaultLeakOptions() []goleak.Option
- func IgnoreCurrentGoroutines() goleak.Option
- func LeakTestMain(m *testing.M)
- func LeakTestMainWithOptions(m *testing.M, opts ...goleak.Option)
- func VerifyNone(t *testing.T, opts ...goleak.Option)
- func VerifyNoneWithDelay(t *testing.T, _ int, opts ...goleak.Option)
- type MockServer
- func (m *MockServer) Close()
- func (m *MockServer) Handle(path string, handler http.HandlerFunc)
- func (m *MockServer) HandleError(path string, statusCode int, message string)
- func (m *MockServer) HandleJSON(path string, response any)
- func (m *MockServer) HandlePrefix(path string, handler http.HandlerFunc)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultLeakOptions ¶
DefaultLeakOptions returns default goleak options
func IgnoreCurrentGoroutines ¶
IgnoreCurrentGoroutines returns an option to ignore current goroutines
func LeakTestMain ¶
LeakTestMain provides TestMain function with goroutine leak detection Usage:
func TestMain(m *testing.M) {
testutil.LeakTestMain(m)
}
For custom options, use LeakTestMainWithOptions
func LeakTestMainWithOptions ¶
LeakTestMainWithOptions provides TestMain function with custom options
func VerifyNone ¶
VerifyNone detects current goroutine leaks Can be used in tests, for example:
func TestSomething(t *testing.T) {
defer testutil.VerifyNone(t)
// test code
}
Types ¶
type MockServer ¶
MockServer 提供一个用于测试的 HTTP 模拟服务�?
func NewMockServer ¶
func NewMockServer(t *testing.T) *MockServer
NewMockServer 创建一个新�?MockServer 实例
func (*MockServer) Handle ¶
func (m *MockServer) Handle(path string, handler http.HandlerFunc)
Handle 为指定路径注册自定义处理函数
func (*MockServer) HandleError ¶
func (m *MockServer) HandleError(path string, statusCode int, message string)
HandleError 为指定路径注册返回错误响应的处理函数
func (*MockServer) HandleJSON ¶
func (m *MockServer) HandleJSON(path string, response any)
HandleJSON 为指定路径注册返�?JSON 响应的处理函�?
func (*MockServer) HandlePrefix ¶
func (m *MockServer) HandlePrefix(path string, handler http.HandlerFunc)
HandlePrefix 为指定路径前缀注册自定义处理函数 这个方法会匹配所有以指定路径开头的请求(包括查询参数)