testutil

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

internal/testutil/leak.go

internal/testutil/mock.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultLeakOptions

func DefaultLeakOptions() []goleak.Option

DefaultLeakOptions returns default goleak options

func IgnoreCurrentGoroutines

func IgnoreCurrentGoroutines() goleak.Option

IgnoreCurrentGoroutines returns an option to ignore current goroutines

func LeakTestMain

func LeakTestMain(m *testing.M)

LeakTestMain provides TestMain function with goroutine leak detection Usage:

func TestMain(m *testing.M) {
    testutil.LeakTestMain(m)
}

For custom options, use LeakTestMainWithOptions

func LeakTestMainWithOptions

func LeakTestMainWithOptions(m *testing.M, opts ...goleak.Option)

LeakTestMainWithOptions provides TestMain function with custom options

func VerifyNone

func VerifyNone(t *testing.T, opts ...goleak.Option)

VerifyNone detects current goroutine leaks Can be used in tests, for example:

func TestSomething(t *testing.T) {
    defer testutil.VerifyNone(t)
    // test code
}

func VerifyNoneWithDelay

func VerifyNoneWithDelay(t *testing.T, _ int, opts ...goleak.Option)

VerifyNoneWithDelay detects goroutine leaks with delay

Types

type MockServer

type MockServer struct {
	Server *httptest.Server
	Mux    *http.ServeMux
	URL    string
}

MockServer 提供一个用于测试的 HTTP 模拟服务�?

func NewMockServer

func NewMockServer(t *testing.T) *MockServer

NewMockServer 创建一个新�?MockServer 实例

func (*MockServer) Close

func (m *MockServer) Close()

Close 关闭模拟服务�?

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 为指定路径前缀注册自定义处理函数 这个方法会匹配所有以指定路径开头的请求(包括查询参数)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL