Documentation ¶
Index ¶
- Constants
- func CreateTable(tb testing.TB, sqlDB *gosql.DB, tableName, schema string, numRows int, ...)
- func CreateTableDebug(tb testing.TB, sqlDB *gosql.DB, tableName, schema string, numRows int, ...)
- func CreateTableInterleaved(tb testing.TB, sqlDB *gosql.DB, tableName, schema, interleaveSchema string, ...)
- func CreateTableInterleavedDebug(tb testing.TB, sqlDB *gosql.DB, tableName, schema, interleaveSchema string, ...)
- func CreateTestInterleavedHierarchy(t *testing.T, sqlDB *gosql.DB)
- func DeleteZoneConfig(t testing.TB, sqlDB *SQLRunner, target string)
- func IntToEnglish(val int) string
- func MatrixToStr(rows [][]string) string
- func PGUrl(t testing.TB, servingAddr, prefix string, user *url.Userinfo) (url.URL, func())
- func PGUrlWithOptionalClientCerts(t testing.TB, servingAddr, prefix string, user *url.Userinfo, ...) (url.URL, func())
- func QueryDatabaseID(t testing.TB, sqlDB DBHandle, dbName string) uint32
- func QueryTableID(t testing.TB, sqlDB DBHandle, dbName, schemaName string, tableName string) uint32
- func RemoveAllZoneConfigs(t testing.TB, sqlDB *SQLRunner)
- func RowEnglishFn(row int) ast.Datum
- func RowIdxFn(row int) ast.Datum
- func RowsToStrMatrix(rows *gosql.Rows) ([][]string, error)
- func RunResolveColumnItemTest(t *testing.T, ct ColumnItemResolverTester)
- func RunResolveQualifiedStarTest(t *testing.T, ct ColumnItemResolverTester)
- func RunScrub(sqlDB *gosql.DB, database string, table string) error
- func RunScrubWithOptions(sqlDB *gosql.DB, database string, table string, options string) error
- func SetZoneConfig(t testing.TB, sqlDB *SQLRunner, target string, config string)
- func TxnSetZoneConfig(t testing.TB, sqlDB *SQLRunner, txn *gosql.Tx, target string, config string)
- func VerifyAllZoneConfigs(t testing.TB, sqlDB *SQLRunner, rows ...ZoneRow)
- func VerifyStatementPrettyRoundtrip(t *testing.T, sql string)
- func VerifyZoneConfigForTarget(t testing.TB, sqlDB *SQLRunner, target string, row ZoneRow)
- func ZoneConfigExists(t testing.TB, sqlDB *SQLRunner, name string) bool
- type ColumnItemResolverTester
- type DBHandle
- type GenRowFn
- type GenValueFn
- type RoundRobinDBHandle
- func (rr *RoundRobinDBHandle) ExecContext(ctx context.Context, query string, args ...interface{}) (gosql.Result, error)
- func (rr *RoundRobinDBHandle) QueryContext(ctx context.Context, query string, args ...interface{}) (*gosql.Rows, error)
- func (rr *RoundRobinDBHandle) QueryRowContext(ctx context.Context, query string, args ...interface{}) *gosql.Row
- type Row
- type SQLRunner
- func (sr *SQLRunner) CheckQueryResults(t testing.TB, query string, expected [][]string)
- func (sr *SQLRunner) CheckQueryResultsRetry(t testing.TB, query string, expected [][]string)
- func (sr *SQLRunner) Exec(t testing.TB, query string, args ...interface{}) gosql.Result
- func (sr *SQLRunner) ExecRowsAffected(t testing.TB, expRowsAffected int, query string, args ...interface{})
- func (sr *SQLRunner) ExecSucceedsSoon(t testing.TB, query string, args ...interface{})
- func (sr *SQLRunner) ExpectErr(t testing.TB, errRE string, query string, args ...interface{})
- func (sr *SQLRunner) ExpectErrSucceedsSoon(t testing.TB, errRE string, query string, args ...interface{})
- func (sr *SQLRunner) Query(t testing.TB, query string, args ...interface{}) *gosql.Rows
- func (sr *SQLRunner) QueryRow(t testing.TB, query string, args ...interface{}) *Row
- func (sr *SQLRunner) QueryStr(t testing.TB, query string, args ...interface{}) [][]string
- type ScrubResult
- type ZoneRow
Constants ¶
const TestDB = "test"
TestDB is the name of the database created for test tables.
Variables ¶
This section is empty.
Functions ¶
func CreateTable ¶
func CreateTable( tb testing.TB, sqlDB *gosql.DB, tableName, schema string, numRows int, fn GenRowFn, )
CreateTable creates a table in the "test" database with the given number of rows and using the given row generation function.
func CreateTableDebug ¶
func CreateTableDebug( tb testing.TB, sqlDB *gosql.DB, tableName, schema string, numRows int, fn GenRowFn, shouldPrint bool, )
CreateTableDebug is identical to debug, but allows for the added option of printing the table and its contents upon creation.
func CreateTableInterleaved ¶
func CreateTableInterleaved( tb testing.TB, sqlDB *gosql.DB, tableName, schema, interleaveSchema string, numRows int, fn GenRowFn, )
CreateTableInterleaved is identical to CreateTable with the added option of specifying an interleave schema for interleaving the table.
func CreateTableInterleavedDebug ¶
func CreateTableInterleavedDebug( tb testing.TB, sqlDB *gosql.DB, tableName, schema, interleaveSchema string, numRows int, fn GenRowFn, shouldPrint bool, )
CreateTableInterleavedDebug is identical to CreateTableInterleaved with the option of printing the table being created.
func CreateTestInterleavedHierarchy ¶
CreateTestInterleavedHierarchy generates the following interleaved hierarchy for testing:
<table> <primary index/interleave prefix> <nrows> parent1 (pid1) 100 child1 (pid1, cid1, cid2) 250 grandchild1 (pid1, cid1, cid2, gcid1) 1000 child2 (pid1, cid3, cid4) 50 parent2 (pid1) 20
func DeleteZoneConfig ¶
DeleteZoneConfig deletes the specified zone config through the SQL interface.
func IntToEnglish ¶
IntToEnglish returns an English (pilot style) string for the given integer, for example:
IntToEnglish(135) = "one-three-five"
func MatrixToStr ¶
MatrixToStr converts a set of rows into a single string where each row is on a separate line and the columns with a row are comma separated.
func PGUrl ¶
PGUrl returns a postgres connection url which connects to this server with the given user, and a cleanup function which must be called after all connections created using the connection url have been closed.
In order to connect securely using postgres, this method will create temporary on-disk copies of certain embedded security certificates. The certificates will be created in a new temporary directory. The returned cleanup function will delete this temporary directory. Note that two calls to this function for the same `user` will generate different copies of the certificates, so the cleanup function must always be called.
Args:
prefix: A prefix to be prepended to the temp file names generated, for debugging.
func PGUrlWithOptionalClientCerts ¶
func PGUrlWithOptionalClientCerts( t testing.TB, servingAddr, prefix string, user *url.Userinfo, withClientCerts bool, ) (url.URL, func())
PGUrlWithOptionalClientCerts is like PGUrl but the caller can customize whether the client certificates are loaded on-disk and in the URL.
func QueryDatabaseID ¶
QueryDatabaseID returns the database ID of the specified database using the system.namespace table.
func QueryTableID ¶
func QueryTableID( t testing.TB, sqlDB DBHandle, dbName, schemaName string, tableName string, ) uint32
QueryTableID returns the table ID of the specified database.table using the system.namespace table.
func RemoveAllZoneConfigs ¶
RemoveAllZoneConfigs removes all installed zone configs.
func RowEnglishFn ¶
RowEnglishFn is a GenValueFn which returns an English representation of the row number, as a DString
func RowsToStrMatrix ¶
RowsToStrMatrix converts the given result rows to a string matrix; nulls are represented as "NULL". Empty results are represented by an empty (but non-nil) slice.
func RunResolveColumnItemTest ¶
func RunResolveColumnItemTest(t *testing.T, ct ColumnItemResolverTester)
RunResolveColumnItemTest tests that the given ColumnItemResolverTester correctly resolves column names.
func RunResolveQualifiedStarTest ¶
func RunResolveQualifiedStarTest(t *testing.T, ct ColumnItemResolverTester)
RunResolveQualifiedStarTest tests that the given ColumnItemResolverTester correctly resolves names of the form "<tableName>.*".
func RunScrubWithOptions ¶
RunScrubWithOptions will run a SCRUB check for a table with the specified options string.
func SetZoneConfig ¶
SetZoneConfig updates the specified zone config through the SQL interface.
func TxnSetZoneConfig ¶
TxnSetZoneConfig updates the specified zone config through the SQL interface using the provided transaction.
func VerifyAllZoneConfigs ¶
VerifyAllZoneConfigs verifies that the specified ZoneRows exactly match the list of active zone configs.
func VerifyStatementPrettyRoundtrip ¶
VerifyStatementPrettyRoundtrip verifies that the SQL statements in s correctly round trip through the pretty printer.
func VerifyZoneConfigForTarget ¶
VerifyZoneConfigForTarget verifies that the specified zone matches the specified ZoneRow.
Types ¶
type ColumnItemResolverTester ¶
type ColumnItemResolverTester interface { // GetColumnItemResolver returns the ast.ColumnItemResolver. Since any // struct implementing ColumnItemResolverTester should also implement // ast.ColumnItemResolver, this is basically an identity function. GetColumnItemResolver() ast.ColumnItemResolver // AddTable adds a table with the given column names to the // ast.ColumnItemResolver. AddTable(tabName ast.TableName, colNames []ast.Name) // ResolveQualifiedStarTestResults returns the results of running // RunResolveQualifiedStarTest on the ast.ColumnItemResolver. ResolveQualifiedStarTestResults( srcName *ast.TableName, srcMeta ast.ColumnSourceMeta, ) (string, string, error) // ResolveColumnItemTestResults returns the results of running // RunResolveColumnItemTest on the ast.ColumnItemResolver. ResolveColumnItemTestResults(colRes ast.ColumnResolutionResult) (string, error) }
ColumnItemResolverTester is an interface that should be implemented by any struct that also implements ast.ColumnItemResolver. It is used to test that the implementation of ast.ColumnItemResolver is correct.
type DBHandle ¶
type DBHandle interface { ExecContext(ctx context.Context, query string, args ...interface{}) (gosql.Result, error) QueryContext(ctx context.Context, query string, args ...interface{}) (*gosql.Rows, error) QueryRowContext(ctx context.Context, query string, args ...interface{}) *gosql.Row }
DBHandle is an interface that applies to *gosql.DB, *gosql.Conn, and *gosql.Tx, as well as *RoundRobinDBHandle.
type GenRowFn ¶
GenRowFn is a function that takes a (1-based) row index and returns a row of Datums that will be converted to strings to form part of an INSERT statement.
func ToRowFn ¶
func ToRowFn(fn ...GenValueFn) GenRowFn
ToRowFn creates a GenRowFn that returns rows of values generated by the given GenValueFns (one per column).
type GenValueFn ¶
GenValueFn is a function that takes a (1-based) row index and returns a Datum which will be converted to a string to form part of an INSERT statement.
func RowModuloFn ¶
func RowModuloFn(modulo int) GenValueFn
RowModuloFn creates a GenValueFn that returns the row number modulo a given value as a DInt
func RowModuloShiftedFn ¶
func RowModuloShiftedFn(modulo ...int) GenValueFn
RowModuloShiftedFn creates a GenValueFn that uses the following recursive function definition F(row, modulo), where modulo is []int
F(row, []) = row F(row, modulo) = F((row - 1) % modulo[0] + 1, modulo[1:])
and returns the result as a DInt.
type RoundRobinDBHandle ¶
type RoundRobinDBHandle struct {
// contains filtered or unexported fields
}
RoundRobinDBHandle aggregates multiple DBHandles into a single one; each time a query is issued, a handle is selected in round-robin fashion.
func MakeRoundRobinDBHandle ¶
func MakeRoundRobinDBHandle(handles ...DBHandle) *RoundRobinDBHandle
MakeRoundRobinDBHandle creates a RoundRobinDBHandle.
func (*RoundRobinDBHandle) ExecContext ¶
func (rr *RoundRobinDBHandle) ExecContext( ctx context.Context, query string, args ...interface{}, ) (gosql.Result, error)
ExecContext is part of the DBHandle interface.
func (*RoundRobinDBHandle) QueryContext ¶
func (rr *RoundRobinDBHandle) QueryContext( ctx context.Context, query string, args ...interface{}, ) (*gosql.Rows, error)
QueryContext is part of the DBHandle interface.
func (*RoundRobinDBHandle) QueryRowContext ¶
func (rr *RoundRobinDBHandle) QueryRowContext( ctx context.Context, query string, args ...interface{}, ) *gosql.Row
QueryRowContext is part of the DBHandle interface.
type SQLRunner ¶
type SQLRunner struct {
DB DBHandle
}
SQLRunner wraps a testing.TB and *gosql.DB connection and provides convenience functions to run SQL statements and fail the test on any errors.
func MakeRoundRobinSQLRunner ¶
MakeRoundRobinSQLRunner returns a SQLRunner that uses a set of database connections, in a round-robin fashion.
func MakeSQLRunner ¶
MakeSQLRunner returns a SQLRunner for the given database connection. The argument can be a *gosql.DB, *gosql.Conn, or *gosql.Tx object.
func (*SQLRunner) CheckQueryResults ¶
CheckQueryResults checks that the rows returned by a query match the expected response.
func (*SQLRunner) CheckQueryResultsRetry ¶
CheckQueryResultsRetry checks that the rows returned by a query match the expected response. If the results don't match right away, it will retry using testutils.SucceedsSoon.
func (*SQLRunner) ExecRowsAffected ¶
func (sr *SQLRunner) ExecRowsAffected( t testing.TB, expRowsAffected int, query string, args ...interface{}, )
ExecRowsAffected executes the statement and verifies that RowsAffected() matches the expected value. It kills the test on errors.
func (*SQLRunner) ExecSucceedsSoon ¶
ExecSucceedsSoon is a wrapper around gosql.Exec that wraps the exec in a succeeds soon.
func (*SQLRunner) ExpectErr ¶
ExpectErr runs the given statement and verifies that it returns an error matching the given regex.
func (*SQLRunner) ExpectErrSucceedsSoon ¶
func (sr *SQLRunner) ExpectErrSucceedsSoon( t testing.TB, errRE string, query string, args ...interface{}, )
ExpectErrSucceedsSoon wraps ExpectErr with a SucceedsSoon.
type ScrubResult ¶
type ScrubResult struct { ErrorType string Database string Table string PrimaryKey string Timestamp time.Time Repaired bool Details string }
ScrubResult is the go struct for the row results for an EXPERIMENTAL SCRUB query.
func GetScrubResultRows ¶
func GetScrubResultRows(rows *gosql.Rows) (results []ScrubResult, err error)
GetScrubResultRows will scan and unmarshal ScrubResults from a Rows iterator. The Rows iterate must from an EXPERIMENTAL SCRUB query.
type ZoneRow ¶
type ZoneRow struct { ID uint32 Config zonepb.ZoneConfig }
ZoneRow represents a row returned by SHOW ZONE CONFIGURATION.