Help us shape the future of Go! Take the 2026 Go Developer Survey

testhelper

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertQueryRuns

func AssertQueryRuns(connection *dbconn.DBConn, query string)

func CreateAndConnectMockDB

func CreateAndConnectMockDB(numConns int) (*dbconn.DBConn, sqlmock.Sqlmock)

func CreateMockDB

func CreateMockDB() (*sqlx.DB, sqlmock.Sqlmock)

func CreateMockDBConn

func CreateMockDBConn(errs ...error) (*dbconn.DBConn, sqlmock.Sqlmock)

func ExpectRegexp

func ExpectRegexp(buffer *gbytes.Buffer, testStr string)

func ExpectVersionQuery

func ExpectVersionQuery(mock sqlmock.Sqlmock, versionStr string)

func MockFileContents

func MockFileContents(contents string)

* This function call should be followed by a call to InitializeSystemFunctions * in a defer statement or AfterEach block.

func NotExpectRegexp

func NotExpectRegexp(buffer *gbytes.Buffer, testStr string)

func SetDBVersion

func SetDBVersion(connection *dbconn.DBConn, versionStr string)

* While this function is technically redundant with dbconn.NewVersion, it's * here to allow `defer`ing version changes easily, instead of needing e.g. * "defer func() { connection.Version = dbconn.NewVersion(versionStr) }()" or * something similarly ugly.

func SetupTestEnvironment

func SetupTestEnvironment() (*dbconn.DBConn, sqlmock.Sqlmock, *gbytes.Buffer, *gbytes.Buffer, *gbytes.Buffer)

func SetupTestLogger

func SetupTestLogger() (*gbytes.Buffer, *gbytes.Buffer, *gbytes.Buffer)

func ShouldPanicWithMessage

func ShouldPanicWithMessage(message string)

Types

type TestDriver

type TestDriver struct {
	ErrToReturn  error
	ErrsToReturn []error
	DB           *sqlx.DB
	DBName       string
	User         string
	CallNumber   int
}

func (*TestDriver) Connect

func (driver *TestDriver) Connect(driverName string, dataSourceName string) (*sqlx.DB, error)

type TestExecutor

type TestExecutor struct {
	LocalOutput   string
	LocalOutputs  []string
	LocalError    error
	LocalErrors   []error
	LocalCommands []string

	ClusterOutput   *cluster.RemoteOutput
	ClusterOutputs  []*cluster.RemoteOutput
	ClusterCommands [][]cluster.ShellCommand

	ErrorOnExecNum       int // Return LocalError after this many calls of ExecuteLocalCommand (0 means always return error); has no effect for ExecuteClusterCommand
	NumExecutions        int // Total of NumLocalExecutions and NumClusterExecutions, for convenience and backwards compatibility
	NumLocalExecutions   int
	NumClusterExecutions int
	UseLastOutput        bool // If we run out of LocalOutputs/LocalErrors or ClusterOutputs, default to the final items in those arrays
	UseDefaultOutput     bool // If we run out of LocalOutputs/LocalErrors or ClusterOutputs, default to LocalOutput/LocalError or ClusterOutput
}

* Each output or error type has both a plural form and a singular form. If the plural form is set, it overrides the singular. * The singular form returns the same output and error on each call; the plural form returns one output per call (first element on the first call, etc.) * If more calls are made than there are outputs provided a Fatal error is raised, unless UseDefaultOutput or UseLastOutput is set. * * The LocalOutputs and LocalErrors arrays are "paired" in that the struct doesn't know how "normal" calls and "error" calls will be interleaved, so if * N calls are expected then at least N outputs and N errors must be provided; even if UseLastOutput or UseDefaultOutput is set in order to define its * behavior when more than N calls are made and it runs out of outputs and errors to return, the two array lengths must still be identical.

func (*TestExecutor) ExecuteClusterCommand

func (executor *TestExecutor) ExecuteClusterCommand(scope cluster.Scope, commandList []cluster.ShellCommand) *cluster.RemoteOutput

func (*TestExecutor) ExecuteLocalCommand

func (executor *TestExecutor) ExecuteLocalCommand(commandStr string) (string, error)

type TestResult

type TestResult struct {
	Rows int64
}

func (TestResult) LastInsertId

func (result TestResult) LastInsertId() (int64, error)

func (TestResult) RowsAffected

func (result TestResult) RowsAffected() (int64, error)

Jump to

Keyboard shortcuts

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