cockroach: github.com/cockroachdb/cockroach/pkg/testutils/sqlutils Index | Files

package sqlutils

import "github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"

Index

Package Files

gc.go name_resolution_testutils.go pg_url.go pretty.go scrub.go sql_runner.go table_gen.go table_id.go zone.go

Constants

const TestDB = "test"

TestDB is the name of the database created for test tables.

func CreateTable Uses

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 Uses

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 Uses

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 Uses

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 Uses

func CreateTestInterleavedHierarchy(t *testing.T, sqlDB *gosql.DB)

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 Uses

func DeleteZoneConfig(t testing.TB, sqlDB *SQLRunner, target string)

DeleteZoneConfig deletes the specified zone config through the SQL interface.

func ForceTableGC Uses

func ForceTableGC(
    t testing.TB,
    distSender *kv.DistSender,
    db DBHandle,
    database, table string,
    timestamp hlc.Timestamp,
)

ForceTableGC sends a GCRequest for the ranges corresponding to a table.

func IntToEnglish Uses

func IntToEnglish(val int) string

IntToEnglish returns an English (pilot style) string for the given integer, for example:

IntToEnglish(135) = "one-three-five"

func MatrixToStr Uses

func MatrixToStr(rows [][]string) string

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 Uses

func PGUrl(t testing.TB, servingAddr, prefix string, user *url.Userinfo) (url.URL, func())

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 QueryDatabaseID Uses

func QueryDatabaseID(t testing.TB, sqlDB DBHandle, dbName string) uint32

QueryDatabaseID returns the database ID of the specified database using the system.namespace table.

func QueryTableID Uses

func QueryTableID(t testing.TB, sqlDB DBHandle, dbName, tableName string) uint32

QueryTableID returns the table ID of the specified database.table using the system.namespace table.

func RemoveAllZoneConfigs Uses

func RemoveAllZoneConfigs(t testing.TB, sqlDB *SQLRunner)

RemoveAllZoneConfigs removes all installed zone configs.

func RowEnglishFn Uses

func RowEnglishFn(row int) tree.Datum

RowEnglishFn is a GenValueFn which returns an English representation of the row number, as a DString

func RowIdxFn Uses

func RowIdxFn(row int) tree.Datum

RowIdxFn is a GenValueFn that returns the row number as a DInt

func RowsToStrMatrix Uses

func RowsToStrMatrix(rows *gosql.Rows) ([][]string, error)

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 Uses

func RunResolveColumnItemTest(t *testing.T, ct ColumnItemResolverTester)

RunResolveColumnItemTest tests that the given ColumnItemResolverTester correctly resolves column names.

func RunResolveQualifiedStarTest Uses

func RunResolveQualifiedStarTest(t *testing.T, ct ColumnItemResolverTester)

RunResolveQualifiedStarTest tests that the given ColumnItemResolverTester correctly resolves names of the form "<tableName>.*".

func RunScrub Uses

func RunScrub(sqlDB *gosql.DB, database string, table string) error

RunScrub will run execute an exhaustive scrub check for a table.

func RunScrubWithOptions Uses

func RunScrubWithOptions(sqlDB *gosql.DB, database string, table string, options string) error

RunScrubWithOptions will run a SCRUB check for a table with the specified options string.

func SetZoneConfig Uses

func SetZoneConfig(t testing.TB, sqlDB *SQLRunner, target string, config string)

SetZoneConfig updates the specified zone config through the SQL interface.

func TxnSetZoneConfig Uses

func TxnSetZoneConfig(t testing.TB, sqlDB *SQLRunner, txn *gosql.Tx, target string, config string)

TxnSetZoneConfig updates the specified zone config through the SQL interface using the provided transaction.

func VerifyAllZoneConfigs Uses

func VerifyAllZoneConfigs(t testing.TB, sqlDB *SQLRunner, rows ...ZoneRow)

VerifyAllZoneConfigs verifies that the specified ZoneRows exactly match the list of active zone configs.

func VerifyStatementPrettyRoundtrip Uses

func VerifyStatementPrettyRoundtrip(t *testing.T, sql string)

VerifyStatementPrettyRoundtrip verifies that the SQL statements in s correctly round trip through the pretty printer.

func VerifyZoneConfigForTarget Uses

func VerifyZoneConfigForTarget(t testing.TB, sqlDB *SQLRunner, target string, row ZoneRow)

VerifyZoneConfigForTarget verifies that the specified zone matches the specified ZoneRow.

func ZoneConfigExists Uses

func ZoneConfigExists(t testing.TB, sqlDB *SQLRunner, name string) bool

ZoneConfigExists returns whether a zone config with the provided name exists.

type ColumnItemResolverTester Uses

type ColumnItemResolverTester interface {
    // GetColumnItemResolver returns the tree.ColumnItemResolver. Since any
    // struct implementing ColumnItemResolverTester should also implement
    // tree.ColumnItemResolver, this is basically an identity function.
    GetColumnItemResolver() tree.ColumnItemResolver

    // AddTable adds a table with the given column names to the
    // tree.ColumnItemResolver.
    AddTable(tabName tree.TableName, colNames []tree.Name)

    // ResolveQualifiedStarTestResults returns the results of running
    // RunResolveQualifiedStarTest on the tree.ColumnItemResolver.
    ResolveQualifiedStarTestResults(
        srcName *tree.TableName, srcMeta tree.ColumnSourceMeta,
    ) (string, string, error)

    // ResolveColumnItemTestResults returns the results of running
    // RunResolveColumnItemTest on the tree.ColumnItemResolver.
    ResolveColumnItemTestResults(colRes tree.ColumnResolutionResult) (string, error)
}

ColumnItemResolverTester is an interface that should be implemented by any struct that also implements tree.ColumnItemResolver. It is used to test that the implementation of tree.ColumnItemResolver is correct.

type DBHandle Uses

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.

type GenRowFn Uses

type GenRowFn func(row int) []tree.Datum

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 Uses

func ToRowFn(fn ...GenValueFn) GenRowFn

ToRowFn creates a GenRowFn that returns rows of values generated by the given GenValueFns (one per column).

type GenValueFn Uses

type GenValueFn func(row int) tree.Datum

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 Uses

func RowModuloFn(modulo int) GenValueFn

RowModuloFn creates a GenValueFn that returns the row number modulo a given value as a DInt

func RowModuloShiftedFn Uses

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 Row Uses

type Row struct {
    testing.TB
    // contains filtered or unexported fields
}

Row is a wrapper around gosql.Row that kills the test on error.

func (*Row) Scan Uses

func (r *Row) Scan(dest ...interface{})

Scan is a wrapper around (*gosql.Row).Scan that kills the test on error.

type SQLRunner Uses

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 MakeSQLRunner Uses

func MakeSQLRunner(db DBHandle) *SQLRunner

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 Uses

func (sr *SQLRunner) CheckQueryResults(t testing.TB, query string, expected [][]string)

CheckQueryResults checks that the rows returned by a query match the expected response.

func (*SQLRunner) CheckQueryResultsRetry Uses

func (sr *SQLRunner) CheckQueryResultsRetry(t testing.TB, query string, expected [][]string)

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) Exec Uses

func (sr *SQLRunner) Exec(t testing.TB, query string, args ...interface{}) gosql.Result

Exec is a wrapper around gosql.Exec that kills the test on error.

func (*SQLRunner) ExecRowsAffected Uses

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) ExpectErr Uses

func (sr *SQLRunner) ExpectErr(t testing.TB, errRE string, query string, args ...interface{})

ExpectErr runs the given statement and verifies that it returns an error matching the given regex.

func (*SQLRunner) Query Uses

func (sr *SQLRunner) Query(t testing.TB, query string, args ...interface{}) *gosql.Rows

Query is a wrapper around gosql.Query that kills the test on error.

func (*SQLRunner) QueryRow Uses

func (sr *SQLRunner) QueryRow(t testing.TB, query string, args ...interface{}) *Row

QueryRow is a wrapper around gosql.QueryRow that kills the test on error.

func (*SQLRunner) QueryStr Uses

func (sr *SQLRunner) QueryStr(t testing.TB, query string, args ...interface{}) [][]string

QueryStr runs a Query and converts the result using RowsToStrMatrix. Kills the test on errors.

type ScrubResult Uses

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 Uses

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 Uses

type ZoneRow struct {
    ID     uint32
    Config config.ZoneConfig
}

ZoneRow represents a row returned by SHOW ZONE CONFIGURATION.

Package sqlutils imports 29 packages (graph) and is imported by 11 packages. Updated 2019-09-21. Refresh now. Tools for package owners.