testkit

package
v0.0.0-...-3903214 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Rows

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

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

Types

type CTestKit

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

CTestKit is a utility to run sql test with concurrent execution support.

func NewCTestKit

func NewCTestKit(c *check.C, store kv.Storage) *CTestKit

NewCTestKit returns a new *CTestKit.

func (*CTestKit) CheckExecResult

func (tk *CTestKit) CheckExecResult(ctx context.Context, affectedRows, insertID int64)

CheckExecResult checks the affected rows and the insert id after executing MustExec.

func (*CTestKit) CloseSession

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

CloseSession closes exists session from ctx.

func (*CTestKit) ConcurrentRun

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

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 (*CTestKit) Exec

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

Exec executes a sql statement.

func (*CTestKit) IgnoreError

func (tk *CTestKit) IgnoreError(_ error)

IgnoreError ignores error and make errcheck tool happy. Deprecated: it's normal to ignore some error in concurrent test, but please don't use this method in other place.

func (*CTestKit) MustExec

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

MustExec executes a sql statement and asserts nil error.

func (*CTestKit) MustQuery

func (tk *CTestKit) 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 (*CTestKit) OpenSession

func (tk *CTestKit) OpenSession(ctx context.Context) context.Context

OpenSession opens new session ctx if no exists one.

func (*CTestKit) OpenSessionWithDB

func (tk *CTestKit) OpenSessionWithDB(ctx context.Context, db string) context.Context

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

func (*CTestKit) PermInt

func (tk *CTestKit) PermInt(n int) []interface{}

PermInt returns, as a slice of n ints, a pseudo-random permutation of the integers [0,n).

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) CheckAt

func (res *Result) CheckAt(cols []int, expected [][]interface{})

CheckAt asserts the result of selected columns 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 {
	Se session.Session
	// contains filtered or unexported fields
}

TestKit is a utility to run sql test.

func NewTestKit

func NewTestKit(c *check.C, store kv.Storage) *TestKit

NewTestKit returns a new *TestKit.

func NewTestKitWithInit

func NewTestKitWithInit(c *check.C, store kv.Storage) *TestKit

NewTestKitWithInit returns a new *TestKit and creates a session.

func (*TestKit) CheckExecResult

func (tk *TestKit) CheckExecResult(affectedRows, insertID int64)

CheckExecResult checks the affected rows and the insert id after executing MustExec.

func (*TestKit) CheckLastMessage

func (tk *TestKit) CheckLastMessage(msg string)

CheckLastMessage checks last message after executing MustExec

func (*TestKit) Exec

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

Exec executes a sql statement.

func (*TestKit) ExecToErr

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

ExecToErr executes a sql statement and discard results.

func (*TestKit) GetTableID

func (tk *TestKit) GetTableID(tableName string) int64

GetTableID gets table ID by name.

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) MustIndexLookup

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

MustIndexLookup checks whether the plan for the sql is IndexLookUp.

func (*TestKit) MustPointGet

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

MustPointGet checks whether the plan for the sql is Point_Get.

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) MustTableDual

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

MustTableDual checks whether the plan for the sql is TableDual.

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) ResultSetToResult

func (tk *TestKit) ResultSetToResult(rs sqlexec.RecordSet, comment check.CommentInterface) *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 check.CommentInterface) *Result

ResultSetToResultWithCtx converts sqlexec.RecordSet to testkit.Result.

Jump to

Keyboard shortcuts

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