testkit

package
v0.0.0-...-37ba7e9 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateMockStore

func CreateMockStore(t testing.TB, opts ...mockstore.MockTiKVStoreOption) (store kv.Storage, clean func())

CreateMockStore return a new mock kv.Storage.

func CreateMockStoreAndDomain

func CreateMockStoreAndDomain(t testing.TB, opts ...mockstore.MockTiKVStoreOption) (kv.Storage, *domain.Domain, func())

CreateMockStoreAndDomain return a new mock kv.Storage and *domain.Domain.

func CreateMockStoreWithOracle

func CreateMockStoreWithOracle(t testing.TB, oracle oracle.Oracle, opts ...mockstore.MockTiKVStoreOption) (kv.Storage, *domain.Domain, func())

CreateMockStoreWithOracle returns a new mock kv.Storage and *domain.Domain, providing the oracle for the store.

func MustNewCommonHandle

func MustNewCommonHandle(t *testing.T, values ...interface{}) kv.Handle

MustNewCommonHandle create a common handle with given values.

func Rows

func Rows(args ...string) [][]interface{}

Rows is similar to RowsWithSep, use white space as separator string.

func RowsWithSep

func RowsWithSep(sep string, args ...string) [][]interface{}

RowsWithSep is a convenient function to wrap args to a slice of []interface. The arg represents a row, split by sep.

Types

type AsyncTestKit

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

AsyncTestKit is a utility to run sql concurrently.

func NewAsyncTestKit

func NewAsyncTestKit(t *testing.T, store kv.Storage) *AsyncTestKit

NewAsyncTestKit returns a new *AsyncTestKit.

func (*AsyncTestKit) CloseSession

func (tk *AsyncTestKit) CloseSession(ctx context.Context)

CloseSession closes exists session from ctx.

func (*AsyncTestKit) ConcurrentRun

func (tk *AsyncTestKit) ConcurrentRun(
	concurrent int,
	loops int,
	prepareFunc func(ctx context.Context, tk *AsyncTestKit, concurrent int, currentLoop int) [][][]interface{},
	writeFunc func(ctx context.Context, tk *AsyncTestKit, input [][]interface{}),
	checkFunc func(ctx context.Context, tk *AsyncTestKit),
)

ConcurrentRun run test in current. - concurrent: controls the concurrent worker count. - loops: controls run test how much times. - prepareFunc: provide test data and will be called for every loop. - checkFunc: used to do some check after all workers done. works like create table better be put in front of this method calling. see more example at TestBatchInsertWithOnDuplicate

func (*AsyncTestKit) Exec

func (tk *AsyncTestKit) Exec(ctx context.Context, sql string, args ...interface{}) (sqlexec.RecordSet, error)

Exec executes a sql statement.

func (*AsyncTestKit) MustExec

func (tk *AsyncTestKit) MustExec(ctx context.Context, sql string, args ...interface{})

MustExec executes a sql statement and asserts nil error.

func (*AsyncTestKit) MustQuery

func (tk *AsyncTestKit) MustQuery(ctx context.Context, sql string, args ...interface{}) *Result

MustQuery query the statements and returns result rows. If expected result is set it asserts the query result equals expected result.

func (*AsyncTestKit) OpenSession

func (tk *AsyncTestKit) OpenSession(ctx context.Context, db string) context.Context

OpenSession opens new session ctx if no exists one and use db.

type DBTestKit

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

DBTestKit is a utility to run sql with a db connection.

func NewDBTestKit

func NewDBTestKit(t *testing.T, db *sql.DB) *DBTestKit

NewDBTestKit returns a new *DBTestKit.

func (*DBTestKit) MustExec

func (tk *DBTestKit) MustExec(sql string, args ...interface{}) sql.Result

MustExec query the statements and returns the result.

func (*DBTestKit) MustQuery

func (tk *DBTestKit) MustQuery(sql string, args ...interface{}) *sql.Rows

MustQuery query the statements and returns result rows.

type Result

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

Result is the result returned by MustQuery.

func (*Result) Check

func (res *Result) Check(expected [][]interface{})

Check asserts the result equals the expected results.

func (*Result) Rows

func (res *Result) Rows() [][]interface{}

Rows returns the result data.

func (*Result) Sort

func (res *Result) Sort() *Result

Sort sorts and return the result.

type TestKit

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

TestKit is a utility to run sql test.

func NewTestKit

func NewTestKit(t testing.TB, store kv.Storage) *TestKit

NewTestKit returns a new *TestKit.

func (*TestKit) Exec

func (tk *TestKit) Exec(sql string, args ...interface{}) (sqlexec.RecordSet, error)

Exec executes a sql statement using the prepared stmt API

func (*TestKit) ExecToErr

func (tk *TestKit) ExecToErr(sql string, args ...interface{}) error

ExecToErr executes a sql statement and discard results.

func (*TestKit) HasPlan

func (tk *TestKit) HasPlan(sql string, plan string, args ...interface{}) bool

HasPlan checks if the result execution plan contains specific plan.

func (*TestKit) MustExec

func (tk *TestKit) MustExec(sql string, args ...interface{})

MustExec executes a sql statement and asserts nil error.

func (*TestKit) MustGetErrCode

func (tk *TestKit) MustGetErrCode(sql string, errCode int)

MustGetErrCode executes a sql statement and assert it's error code.

func (*TestKit) MustGetErrMsg

func (tk *TestKit) MustGetErrMsg(sql string, errStr string)

MustGetErrMsg executes a sql statement and assert it's error message.

func (*TestKit) MustQuery

func (tk *TestKit) MustQuery(sql string, args ...interface{}) *Result

MustQuery query the statements and returns result rows. If expected result is set it asserts the query result equals expected result.

func (*TestKit) MustUseIndex

func (tk *TestKit) MustUseIndex(sql string, index string, args ...interface{}) bool

MustUseIndex checks if the result execution plan contains specific index(es).

func (*TestKit) QueryToErr

func (tk *TestKit) QueryToErr(sql string, args ...interface{}) error

QueryToErr executes a sql statement and discard results.

func (*TestKit) RefreshConnectionID

func (tk *TestKit) RefreshConnectionID()

RefreshConnectionID refresh the connection ID for session of the testkit

func (*TestKit) RefreshSession

func (tk *TestKit) RefreshSession()

RefreshSession set a new session for the testkit

func (*TestKit) ResultSetToResult

func (tk *TestKit) ResultSetToResult(rs sqlexec.RecordSet, comment string) *Result

ResultSetToResult converts sqlexec.RecordSet to testkit.Result. It is used to check results of execute statement in binary mode.

func (*TestKit) ResultSetToResultWithCtx

func (tk *TestKit) ResultSetToResultWithCtx(ctx context.Context, rs sqlexec.RecordSet, comment string) *Result

ResultSetToResultWithCtx converts sqlexec.RecordSet to testkit.Result.

func (*TestKit) Session

func (tk *TestKit) Session() session.Session

Session return the session associated with the testkit

func (*TestKit) SetSession

func (tk *TestKit) SetSession(session session.Session)

SetSession set the session of testkit

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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