testutil

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LeakOptions = []goleak.Option{
	goleak.IgnoreTopFunction("github.com/syndtr/goleveldb/leveldb.(*DB).mpoolDrain"),
	goleak.IgnoreTopFunction("google.golang.org/grpc.(*ccBalancerWrapper).watcher"),
	goleak.IgnoreTopFunction("google.golang.org/grpc.(*addrConn).resetTransport"),
	goleak.IgnoreTopFunction("google.golang.org/grpc/internal/grpcsync.(*CallbackSerializer).run"),
	goleak.IgnoreTopFunction("go.etcd.io/etcd/pkg/logutil.(*MergeLogger).outputLoop"),
	goleak.IgnoreTopFunction("sync.runtime_notifyListWait"),

	goleak.IgnoreTopFunction("internal/poll.runtime_pollWait"),
	goleak.IgnoreTopFunction("net/http.(*persistConn).writeLoop"),

	goleak.IgnoreTopFunction("gopkg.in/natefinch/lumberjack%2ev2.(*Logger).millRun"),
}

LeakOptions is used to filter the goroutines.

Functions

func CheckDelete

func CheckDelete(client *http.Client, url string, checkOpts ...func([]byte, int, http.Header)) error

CheckDelete is used to do delete request and do check options.

func CheckGetJSON

func CheckGetJSON(client *http.Client, url string, data []byte, checkOpts ...func([]byte, int, http.Header)) error

CheckGetJSON is used to do get request and do check options.

func CheckGetUntilStatusCode

func CheckGetUntilStatusCode(re *require.Assertions, client *http.Client, url string, code int) error

CheckGetUntilStatusCode is used to do get request and do check options.

func CheckPatchJSON

func CheckPatchJSON(client *http.Client, url string, data []byte, checkOpts ...func([]byte, int, http.Header)) error

CheckPatchJSON is used to do patch request and do check options.

func CheckPostJSON

func CheckPostJSON(client *http.Client, url string, data []byte, checkOpts ...func([]byte, int, http.Header)) error

CheckPostJSON is used to do post request and do check options.

func CleanServer

func CleanServer(dataDir string)

CleanServer is used to clean data directory.

func Eventually

func Eventually(re *require.Assertions, condition func() bool, opts ...WaitOption)

Eventually asserts that given condition will be met in a period of time.

func ExtractJSON

func ExtractJSON(re *require.Assertions, data any) func([]byte, int, http.Header)

ExtractJSON is used to check whether given data can be extracted successfully.

func GenerateTestDataConcurrently

func GenerateTestDataConcurrently(count int, f func(int))

GenerateTestDataConcurrently generates test data concurrently.

func InitTempFileLogger

func InitTempFileLogger(level string) (fname string)

InitTempFileLogger initializes the logger and redirects the log output to a temporary file.

func MustNewGrpcClient

func MustNewGrpcClient(re *require.Assertions, addr string) pdpb.PDClient

MustNewGrpcClient must create a new PD grpc client.

func NewRequestHeader

func NewRequestHeader(clusterID uint64) *pdpb.RequestHeader

NewRequestHeader creates a new request header.

func ReadGetJSON

func ReadGetJSON(re *require.Assertions, client *http.Client, url string, data any, checkOpts ...func([]byte, int, http.Header)) error

ReadGetJSON is used to do get request and check whether given data can be extracted successfully.

func ReadGetJSONWithBody

func ReadGetJSONWithBody(re *require.Assertions, client *http.Client, url string, input []byte, data any, checkOpts ...func([]byte, int, http.Header)) error

ReadGetJSONWithBody is used to do get request with input and check whether given data can be extracted successfully.

func Status

func Status(re *require.Assertions, code int) func([]byte, int, http.Header)

Status is used to check whether http response code is equal given code.

func StatusNotOK

func StatusNotOK(re *require.Assertions) func([]byte, int, http.Header)

StatusNotOK is used to check whether http response code is not equal http.StatusOK.

func StatusOK

func StatusOK(re *require.Assertions) func([]byte, int, http.Header)

StatusOK is used to check whether http response code is equal http.StatusOK.

func StringContain

func StringContain(re *require.Assertions, sub string) func([]byte, int, http.Header)

StringContain is used to check whether response context contains given string.

func StringEqual

func StringEqual(re *require.Assertions, str string) func([]byte, int, http.Header)

StringEqual is used to check whether response context equal given string.

func StringNotContain

func StringNotContain(re *require.Assertions, sub string) func([]byte, int, http.Header)

StringNotContain is used to check whether response context doesn't contain given string.

func WithHeader

func WithHeader(re *require.Assertions, key, value string) func([]byte, int, http.Header)

WithHeader is used to check whether response header contains given key and value.

func WithoutHeader

func WithoutHeader(re *require.Assertions, key string) func([]byte, int, http.Header)

WithoutHeader is used to check whether response header does not contain given key.

Types

type CleanupFunc

type CleanupFunc func()

CleanupFunc closes test pd server(s) and deletes any files left behind.

type WaitOp

type WaitOp struct {
	// contains filtered or unexported fields
}

WaitOp represents available options when execute Eventually.

type WaitOption

type WaitOption func(op *WaitOp)

WaitOption configures WaitOp.

func WithTickInterval

func WithTickInterval(tickInterval time.Duration) WaitOption

WithTickInterval specify the tick interval to check the condition.

func WithWaitFor

func WithWaitFor(waitFor time.Duration) WaitOption

WithWaitFor specify the max wait duration.

Jump to

Keyboard shortcuts

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