Documentation ¶
Overview ¶
Example ¶
package main import ( "context" "fmt" "io" sqle "github.com/noahkln/go-mysql-server" "github.com/noahkln/go-mysql-server/memory" "github.com/noahkln/go-mysql-server/sql" ) func main() { // Create a test memory database and register it to the default engine. db := createTestDatabase() e := sqle.NewDefault(sql.NewDatabaseProvider(db)) ctx := sql.NewContext(context.Background()).WithCurrentDB("test") _, r, err := e.Query(ctx, `SELECT name, count(*) FROM mytable WHERE name = 'John Doe' GROUP BY name`) checkIfError(err) // Iterate results and print them. for { row, err := r.Next(ctx) if err == io.EOF { break } checkIfError(err) name := row[0] count := row[1] fmt.Println(name, count) } } func checkIfError(err error) { if err != nil { panic(err) } } func createTestDatabase() sql.Database { db := memory.NewDatabase("test") table := memory.NewTable("mytable", sql.NewPrimaryKeySchema(sql.Schema{ {Name: "name", Type: sql.Text, Source: "mytable"}, {Name: "email", Type: sql.Text, Source: "mytable"}, }), db.GetForeignKeyCollection()) db.AddTable("mytable", table) ctx := sql.NewEmptyContext() rows := []sql.Row{ sql.NewRow("John Doe", "john@doe.com"), sql.NewRow("John Doe", "johnalt@doe.com"), sql.NewRow("Jane Doe", "jane@doe.com"), sql.NewRow("Evil Bob", "evilbob@gmail.com"), } for _, row := range rows { table.Insert(ctx, row) } return db }
Output: John Doe 2
Index ¶
- func AddColumn(t *testing.T, ctx *sql.Context, table sql.AlterableTable, column *sql.Column)
- func AssertErr(t *testing.T, e *sqle.Engine, harness Harness, query string, ...)
- func AssertErrWithBindings(t *testing.T, e *sqle.Engine, harness Harness, query string, ...)
- func AssertErrWithCtx(t *testing.T, e *sqle.Engine, harness Harness, ctx *sql.Context, query string, ...)
- func AssertWarningAndTestQuery(t *testing.T, e *sqle.Engine, ctx *sql.Context, harness Harness, query string, ...)
- func CreateIndexes(t *testing.T, harness Harness, engine *sqle.Engine)
- func CreateSpatialSubsetTestData(t *testing.T, harness Harness, includedTables []string) []sql.Database
- func CreateSpatialTestData(t *testing.T, harness Harness) []sql.Database
- func CreateSubsetTestData(t *testing.T, harness Harness, includedTables []string) []sql.Database
- func CreateTestData(t *testing.T, harness Harness) []sql.Database
- func DeleteRows(t *testing.T, ctx *sql.Context, table sql.DeletableTable, rows ...sql.Row)
- func ExtractQueryNode(node sql.Node) sql.Node
- func InsertRows(t *testing.T, ctx *sql.Context, table sql.InsertableTable, rows ...sql.Row)
- func MustQuery(ctx *sql.Context, e *sqle.Engine, q string) (sql.Schema, []sql.Row)
- func MustQueryWithBindings(ctx *sql.Context, e *sqle.Engine, q string, bindings map[string]sql.Expression) (sql.Schema, []sql.Row)
- func MustQueryWithPreBindings(ctx *sql.Context, e *sqle.Engine, q string, bindings map[string]sql.Expression) (sql.Node, sql.Schema, []sql.Row)
- func NewBaseSession() *sql.BaseSession
- func NewColumnDefaultValue(expr sql.Expression, outType sql.Type, ...) *sql.ColumnDefaultValue
- func NewContext(harness Harness) *sql.Context
- func NewContextWithClient(harness ClientHarness, client sql.Client) *sql.Context
- func NewContextWithEngine(harness Harness, engine *sqle.Engine) *sql.Context
- func NewEngine(t *testing.T, harness Harness) *sqle.Engine
- func NewEngineWithDbs(t *testing.T, harness Harness, databases []sql.Database) *sqle.Engine
- func NewEngineWithProvider(_ *testing.T, harness Harness, provider sql.MutableDatabaseProvider) *sqle.Engine
- func NewEngineWithProviderSetup(t *testing.T, harness Harness, pro sql.MutableDatabaseProvider, ...) (*sqle.Engine, error)
- func NewSession(harness Harness) *sql.Context
- func NewSpatialEngine(t *testing.T, harness Harness) *sqle.Engine
- func RunEngineScripts(ctx *sql.Context, e *sqle.Engine, scripts []setup.SetupScript, ...) (*sqle.Engine, error)
- func RunQuery(t *testing.T, e *sqle.Engine, harness Harness, query string)
- func RunQueryTests(t *testing.T, harness Harness, queries []queries.QueryTest)
- func RunQueryWithContext(t *testing.T, e *sqle.Engine, harness Harness, ctx *sql.Context, query string)
- func RunWriteQueryTest(t *testing.T, harness Harness, tt queries.WriteQueryTest)
- func TestAddAutoIncrementColumn(t *testing.T, harness Harness)
- func TestAddColumn(t *testing.T, harness Harness)
- func TestAddDropPks(t *testing.T, harness Harness)
- func TestAlterTable(t *testing.T, harness Harness)
- func TestAmbiguousColumnResolution(t *testing.T, harness Harness)
- func TestBlobs(t *testing.T, h Harness)
- func TestBrokenInsertScripts(t *testing.T, harness Harness)
- func TestBrokenJSONTableScripts(t *testing.T, harness Harness)
- func TestBrokenQueries(t *testing.T, harness Harness)
- func TestCharsetCollationEngine(t *testing.T, harness Harness)
- func TestCharsetCollationWire(t *testing.T, h Harness, sessionBuilder server.SessionBuilder)
- func TestChecksOnInsert(t *testing.T, harness Harness)
- func TestChecksOnUpdate(t *testing.T, harness Harness)
- func TestClearWarnings(t *testing.T, harness Harness)
- func TestColumnAliases(t *testing.T, harness Harness)
- func TestColumnDefaults(t *testing.T, harness Harness)
- func TestComplexIndexQueries(t *testing.T, harness Harness)
- func TestComplexIndexQueriesPrepared(t *testing.T, harness Harness)
- func TestConcurrentTransactions(t *testing.T, harness Harness)
- func TestCreateCheckConstraints(t *testing.T, harness Harness)
- func TestCreateCheckConstraintsScriptsPrepared(t *testing.T, harness Harness)
- func TestCreateDatabase(t *testing.T, harness Harness)
- func TestCreateForeignKeys(t *testing.T, harness Harness)
- func TestCreateTable(t *testing.T, harness Harness)
- func TestCurrentTimestamp(t *testing.T, harness Harness)
- func TestDatabaseCollationWire(t *testing.T, h Harness, sessionBuilder server.SessionBuilder)
- func TestDateParse(t *testing.T, harness Harness)
- func TestDelete(t *testing.T, harness Harness)
- func TestDeleteErrors(t *testing.T, harness Harness)
- func TestDeleteQueriesPrepared(t *testing.T, harness Harness)
- func TestDerivedTableOuterScopeVisibility(t *testing.T, harness Harness)
- func TestDisallowedCheckConstraints(t *testing.T, harness Harness)
- func TestDropCheckConstraints(t *testing.T, harness Harness)
- func TestDropColumn(t *testing.T, harness Harness)
- func TestDropColumnKeylessTables(t *testing.T, harness Harness)
- func TestDropConstraints(t *testing.T, harness Harness)
- func TestDropDatabase(t *testing.T, harness Harness)
- func TestDropForeignKeys(t *testing.T, harness Harness)
- func TestDropTable(t *testing.T, harness Harness)
- func TestForeignKeys(t *testing.T, harness Harness)
- func TestIgnoreIntoWithDuplicateUniqueKeyKeyless(t *testing.T, harness Harness)
- func TestIndexPrefix(t *testing.T, h Harness)
- func TestIndexQueryPlans(t *testing.T, harness Harness)
- func TestIndexes(t *testing.T, h Harness)
- func TestInfoSchema(t *testing.T, h Harness)
- func TestInfoSchemaPrepared(t *testing.T, harness Harness)
- func TestInnerNestedInNaturalJoins(t *testing.T, harness Harness)
- func TestInsertErrorScriptsPrepared(t *testing.T, harness Harness)
- func TestInsertIgnoreInto(t *testing.T, harness Harness)
- func TestInsertIgnoreScriptsPrepared(t *testing.T, harness Harness)
- func TestInsertInto(t *testing.T, harness Harness)
- func TestInsertIntoErrors(t *testing.T, harness Harness)
- func TestInsertQueriesPrepared(t *testing.T, harness Harness)
- func TestInsertScriptsPrepared(t *testing.T, harness Harness)
- func TestIntegrationPlans(t *testing.T, harness Harness)
- func TestJSONTableQueries(t *testing.T, harness Harness)
- func TestJSONTableScripts(t *testing.T, harness Harness)
- func TestJoinQueries(t *testing.T, harness Harness)
- func TestJoinQueriesPrepared(t *testing.T, harness Harness)
- func TestJsonScripts(t *testing.T, harness Harness)
- func TestJsonScriptsPrepared(t *testing.T, harness Harness)
- func TestLoadData(t *testing.T, harness Harness)
- func TestLoadDataErrors(t *testing.T, harness Harness)
- func TestLoadDataFailing(t *testing.T, harness Harness)
- func TestLoadDataPrepared(t *testing.T, harness Harness)
- func TestModifyColumn(t *testing.T, harness Harness)
- func TestNamedWindows(t *testing.T, harness Harness)
- func TestNaturalJoin(t *testing.T, harness Harness)
- func TestNaturalJoinDisjoint(t *testing.T, harness Harness)
- func TestNaturalJoinEqual(t *testing.T, harness Harness)
- func TestNoDatabaseSelected(t *testing.T, harness Harness)
- func TestNullRanges(t *testing.T, harness Harness)
- func TestOrderByGroupBy(t *testing.T, harness Harness)
- func TestPersist(t *testing.T, harness Harness, ...)
- func TestPkOrdinalsDDL(t *testing.T, harness Harness)
- func TestPkOrdinalsDML(t *testing.T, harness Harness)
- func TestPrepared(t *testing.T, harness Harness)
- func TestPreparedInsert(t *testing.T, harness Harness)
- func TestPreparedQuery(t *testing.T, harness Harness, q string, expected []sql.Row, ...)
- func TestPreparedQueryWithContext(t *testing.T, ctx *sql.Context, e *sqle.Engine, h Harness, q string, ...)
- func TestPreparedQueryWithEngine(t *testing.T, harness Harness, e *sqle.Engine, tt queries.QueryTest)
- func TestPreparedStaticIndexQuery(t *testing.T, harness Harness)
- func TestPrivilegePersistence(t *testing.T, h Harness)
- func TestQueries(t *testing.T, harness Harness)
- func TestQueriesPrepared(t *testing.T, harness Harness)
- func TestQuery(t *testing.T, harness Harness, q string, expected []sql.Row, ...)
- func TestQueryErrors(t *testing.T, harness Harness)
- func TestQueryPlan(t *testing.T, harness Harness, e *sqle.Engine, query string, ...)
- func TestQueryPlanWithEngine(t *testing.T, harness Harness, e *sqle.Engine, tt queries.QueryPlanTest)
- func TestQueryPlans(t *testing.T, harness Harness, planTests []queries.QueryPlanTest)
- func TestQueryWithContext(t *testing.T, ctx *sql.Context, e *sqle.Engine, harness Harness, q string, ...)
- func TestQueryWithEngine(t *testing.T, harness Harness, e *sqle.Engine, tt queries.QueryTest)
- func TestReadOnly(t *testing.T, harness Harness)
- func TestReadOnlyDatabases(t *testing.T, harness Harness)
- func TestRecursiveViewDefinition(t *testing.T, harness Harness)
- func TestRenameColumn(t *testing.T, harness Harness)
- func TestRenameTable(t *testing.T, harness Harness)
- func TestReplaceInto(t *testing.T, harness Harness)
- func TestReplaceIntoErrors(t *testing.T, harness Harness)
- func TestReplaceQueriesPrepared(t *testing.T, harness Harness)
- func TestRollbackTriggers(t *testing.T, harness Harness)
- func TestScript(t *testing.T, harness Harness, script queries.ScriptTest)
- func TestScriptPrepared(t *testing.T, harness Harness, script queries.ScriptTest) bool
- func TestScriptWithEngine(t *testing.T, e *sqle.Engine, harness Harness, script queries.ScriptTest)
- func TestScriptWithEnginePrepared(t *testing.T, e *sqle.Engine, harness Harness, script queries.ScriptTest)
- func TestScripts(t *testing.T, harness Harness)
- func TestScriptsPrepared(t *testing.T, harness Harness)
- func TestSessionSelectLimit(t *testing.T, harness Harness)
- func TestShowTableStatus(t *testing.T, harness Harness)
- func TestShowTableStatusPrepared(t *testing.T, harness Harness)
- func TestShowTriggers(t *testing.T, harness Harness)
- func TestSpatialDelete(t *testing.T, harness Harness)
- func TestSpatialInsertInto(t *testing.T, harness Harness)
- func TestSpatialQueries(t *testing.T, harness Harness)
- func TestSpatialQueriesPrepared(t *testing.T, harness Harness)
- func TestSpatialScripts(t *testing.T, harness Harness)
- func TestSpatialUpdate(t *testing.T, harness Harness)
- func TestStatistics(t *testing.T, harness Harness)
- func TestStatisticsPrepared(t *testing.T, harness Harness)
- func TestStoredProcedures(t *testing.T, harness Harness)
- func TestTracing(t *testing.T, harness Harness)
- func TestTransactionScript(t *testing.T, harness Harness, script queries.TransactionTest) bool
- func TestTransactionScriptWithEngine(t *testing.T, e *sqle.Engine, harness Harness, script queries.TransactionTest)
- func TestTransactionScripts(t *testing.T, harness Harness)
- func TestTriggerErrors(t *testing.T, harness Harness)
- func TestTriggers(t *testing.T, harness Harness)
- func TestTruncate(t *testing.T, harness Harness)
- func TestTypesOverWire(t *testing.T, h Harness, sessionBuilder server.SessionBuilder)
- func TestUpdate(t *testing.T, harness Harness)
- func TestUpdateErrors(t *testing.T, harness Harness)
- func TestUpdateIgnore(t *testing.T, harness Harness)
- func TestUpdateQueriesPrepared(t *testing.T, harness Harness)
- func TestUse(t *testing.T, harness Harness)
- func TestUserAuthentication(t *testing.T, h Harness)
- func TestUserPrivileges(t *testing.T, h Harness)
- func TestValidateSession(t *testing.T, harness Harness, ...)
- func TestVariableErrors(t *testing.T, harness Harness)
- func TestVariables(t *testing.T, harness Harness)
- func TestVersionedQueries(t *testing.T, harness Harness)
- func TestVersionedQueriesPrepared(t *testing.T, harness Harness)
- func TestVersionedViews(t *testing.T, harness Harness)
- func TestVersionedViewsPrepared(t *testing.T, harness Harness)
- func TestViews(t *testing.T, harness Harness)
- func TestViewsPrepared(t *testing.T, harness Harness)
- func TestWarnings(t *testing.T, harness Harness)
- func TestWindowFunctions(t *testing.T, harness Harness)
- func TestWindowRangeFrames(t *testing.T, harness Harness)
- func TestWindowRowFrames(t *testing.T, harness Harness)
- func WidenRow(sch sql.Schema, row sql.Row) sql.Row
- func WidenRows(sch sql.Schema, rows []sql.Row) []sql.Row
- type ClientHarness
- type ForeignKeyHarness
- type Harness
- type IndexDriverHarness
- type IndexDriverInitalizer
- type IndexHarness
- type KeylessTableHarness
- type MemoryHarness
- func (m *MemoryHarness) ExternalStoredProcedure(_ *sql.Context, name string, numOfParams int) (*sql.ExternalStoredProcedureDetails, error)
- func (m *MemoryHarness) ExternalStoredProcedures(_ *sql.Context, name string) ([]sql.ExternalStoredProcedureDetails, error)
- func (m *MemoryHarness) IndexDriver(dbs []sql.Database) sql.IndexDriver
- func (m *MemoryHarness) InitializeIndexDriver(dbs []sql.Database)
- func (m *MemoryHarness) NewContext() *sql.Context
- func (m *MemoryHarness) NewContextWithClient(client sql.Client) *sql.Context
- func (m *MemoryHarness) NewDatabase(name string) sql.Database
- func (m *MemoryHarness) NewDatabaseProvider(dbs ...sql.Database) sql.MutableDatabaseProvider
- func (m *MemoryHarness) NewDatabases(names ...string) []sql.Database
- func (m *MemoryHarness) NewEngine(t *testing.T) (*sqle.Engine, error)
- func (m *MemoryHarness) NewReadOnlyDatabases(names ...string) []sql.ReadOnlyDatabase
- func (m *MemoryHarness) NewSession() *sql.Context
- func (m *MemoryHarness) NewTable(db sql.Database, name string, schema sql.PrimaryKeySchema) (sql.Table, error)
- func (m *MemoryHarness) NewTableAsOf(db sql.VersionedDatabase, name string, schema sql.PrimaryKeySchema, ...) sql.Table
- func (m *MemoryHarness) Parallelism() int
- func (m *MemoryHarness) QueriesToSkip(queries ...string)
- func (m *MemoryHarness) Setup(setupData ...[]setup.SetupScript)
- func (m *MemoryHarness) SkipQueryTest(query string) bool
- func (m *MemoryHarness) SnapshotTable(db sql.VersionedDatabase, name string, asOf interface{}) error
- func (m *MemoryHarness) SupportsForeignKeys() bool
- func (m *MemoryHarness) SupportsKeylessTables() bool
- func (m *MemoryHarness) SupportsNativeIndexCreation() bool
- func (m *MemoryHarness) ValidateEngine(ctx *sql.Context, e *sqle.Engine) error
- type ReadOnlyDatabaseHarness
- type SkippingHarness
- type SkippingMemoryHarness
- type TransactionHarness
- type ValidatingHarness
- type VersionedDBHarness
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertErr ¶
func AssertErr(t *testing.T, e *sqle.Engine, harness Harness, query string, expectedErrKind *errors.Kind, errStrs ...string)
AssertErr asserts that the given query returns an error during its execution, optionally specifying a type of error.
func AssertErrWithBindings ¶
func AssertErrWithBindings(t *testing.T, e *sqle.Engine, harness Harness, query string, bindings map[string]sql.Expression, expectedErrKind *errors.Kind, errStrs ...string)
AssertErrWithBindings asserts that the given query returns an error during its execution, optionally specifying a type of error.
func AssertErrWithCtx ¶
func AssertErrWithCtx(t *testing.T, e *sqle.Engine, harness Harness, ctx *sql.Context, query string, expectedErrKind *errors.Kind, errStrs ...string)
AssertErrWithCtx is the same as AssertErr, but uses the context given instead of creating one from a harness
func AssertWarningAndTestQuery ¶
func AssertWarningAndTestQuery( t *testing.T, e *sqle.Engine, ctx *sql.Context, harness Harness, query string, expected []sql.Row, expectedCols []*sql.Column, expectedCode int, expectedWarningsCount int, expectedWarningMessageSubstring string, skipResultsCheck bool, )
AssertWarningAndTestQuery tests the query and asserts an expected warning code. If |ctx| is provided, it will be used. Otherwise the harness will be used to create a fresh context.
func CreateSpatialTestData ¶
CreateSpatialTestData uses the provided harness to create test tables and data for tests involving spatial types.
func CreateSubsetTestData ¶
createSubsetTestData creates test tables and data. Passing a non-nil slice for includedTables will restrict the table creation to just those tables named.
func CreateTestData ¶
CreateTestData uses the provided harness to create test tables and data for many of the other tests.
func DeleteRows ¶
func InsertRows ¶
func MustQueryWithBindings ¶
func NewBaseSession ¶
func NewBaseSession() *sql.BaseSession
NewBaseSession returns a new BaseSession compatible with these tests. Most tests will work with any session implementation, but for full compatibility use a session based on this one.
func NewColumnDefaultValue ¶
func NewColumnDefaultValue(expr sql.Expression, outType sql.Type, representsLiteral, isParenthesized, mayReturnNil bool) *sql.ColumnDefaultValue
func NewContext ¶
func NewContextWithClient ¶
func NewContextWithClient(harness ClientHarness, client sql.Client) *sql.Context
func NewContextWithEngine ¶
func NewEngineWithDbs ¶
NewEngineWithDbs returns a new engine with the databases provided. This is useful if you don't want to implement a full harness but want to run your own tests on DBs you create.
func NewEngineWithProvider ¶
func NewEngineWithProvider(_ *testing.T, harness Harness, provider sql.MutableDatabaseProvider) *sqle.Engine
NewEngineWithProvider returns a new engine with the specified provider. This is useful when you don't want to implement a full harness, but you need more control over the database provider than the default test MemoryProvider.
func NewEngineWithProviderSetup ¶
func NewEngineWithProviderSetup(t *testing.T, harness Harness, pro sql.MutableDatabaseProvider, setupData []setup.SetupScript) (*sqle.Engine, error)
NewEngineWithProviderSetup creates test data and returns an engine using the harness provided.
func NewSession ¶
func NewSpatialEngine ¶
NewSpatialEngine creates test data and returns an engine using the harness provided.
func RunEngineScripts ¶
func RunQueryTests ¶
RunQueryTests runs the query tests given after setting up the engine. Useful for testing out a smaller subset of queries during debugging.
func RunQueryWithContext ¶
func RunQueryWithContext(t *testing.T, e *sqle.Engine, harness Harness, ctx *sql.Context, query string)
RunQueryWithContext runs the query given and asserts that it doesn't result in an error.
func RunWriteQueryTest ¶
func RunWriteQueryTest(t *testing.T, harness Harness, tt queries.WriteQueryTest)
func TestAddColumn ¶
todo(max): convert to WriteQueryTest
func TestAddDropPks ¶
func TestAlterTable ¶
func TestBrokenInsertScripts ¶
func TestBrokenQueries ¶
func TestCharsetCollationWire ¶
func TestCharsetCollationWire(t *testing.T, h Harness, sessionBuilder server.SessionBuilder)
func TestChecksOnInsert ¶
todo(max): rewrite into []ScriptTest
func TestChecksOnUpdate ¶
func TestClearWarnings ¶
func TestColumnAliases ¶
TestColumnAliases exercises the logic for naming and referring to column aliases, and unlike other tests in this file checks that the name of the columns in the result schema is correct.
func TestColumnDefaults ¶
func TestComplexIndexQueries ¶
func TestConcurrentTransactions ¶
TestConcurrentTransactions tests that two concurrent processes/transactions can successfully execute without early cancellation.
func TestCreateCheckConstraints ¶
todo(max): rewrite this using info schema and []QueryTest
func TestCreateDatabase ¶
func TestCreateForeignKeys ¶
func TestCreateTable ¶
func TestCurrentTimestamp ¶
func TestDatabaseCollationWire ¶
func TestDatabaseCollationWire(t *testing.T, h Harness, sessionBuilder server.SessionBuilder)
func TestDateParse ¶
func TestDelete ¶
func TestDeleteErrors ¶
func TestDropCheckConstraints ¶
todo(max): rewrite with []ScriptTest
func TestDropColumn ¶
todo(max): convert to WriteQueryTest
func TestDropConstraints ¶
func TestDropDatabase ¶
func TestDropForeignKeys ¶
func TestDropTable ¶
func TestForeignKeys ¶
func TestIgnoreIntoWithDuplicateUniqueKeyKeyless ¶
todo: merge this into the above test when https://github.com/dolthub/dolt/issues/3836 is fixed
func TestIndexPrefix ¶
func TestIndexQueryPlans ¶
func TestIndexes ¶
func TestInfoSchema ¶
TestInfoSchema runs tests of the information_schema database
func TestInfoSchemaPrepared ¶
TestInfoSchemaPrepared runs tests of the information_schema database
func TestInsertIgnoreInto ¶
func TestInsertInto ¶
func TestInsertIntoErrors ¶
func TestIntegrationPlans ¶
func TestJSONTableQueries ¶
func TestJSONTableScripts ¶
func TestJoinQueries ¶
TestJoinQueries tests join queries against a provided harness.
func TestJoinQueriesPrepared ¶
TestJoinQueriesPrepared tests join queries as prepared statements against a provided harness.
func TestJsonScripts ¶
func TestJsonScriptsPrepared ¶
func TestLoadData ¶
func TestLoadDataErrors ¶
func TestLoadDataFailing ¶
func TestLoadDataPrepared ¶
func TestModifyColumn ¶
todo(max): convert to WriteQueryTest
func TestNamedWindows ¶
func TestNaturalJoin ¶
func TestNaturalJoinDisjoint ¶
func TestNaturalJoinEqual ¶
func TestNoDatabaseSelected ¶
func TestNullRanges ¶
func TestOrderByGroupBy ¶
func TestPersist ¶
func TestPkOrdinalsDDL ¶
func TestPkOrdinalsDML ¶
func TestPrepared ¶
func TestPreparedInsert ¶
func TestPreparedQuery ¶
func TestPreparedQuery(t *testing.T, harness Harness, q string, expected []sql.Row, expectedCols []*sql.Column)
TestPreparedQuery runs a prepared query on the engine given and asserts that results are as expected.
func TestQueries ¶
TestQueries tests a variety of queries against databases and tables provided by the given harness.
func TestQueriesPrepared ¶
func TestQuery ¶
func TestQuery(t *testing.T, harness Harness, q string, expected []sql.Row, expectedCols []*sql.Column, bindings map[string]sql.Expression)
TestQuery runs a query on the engine given and asserts that results are as expected.
func TestQueryErrors ¶
func TestQueryPlan ¶
func TestQueryPlan(t *testing.T, harness Harness, e *sqle.Engine, query string, expectedPlan string)
TestQueryPlan analyzes the query given and asserts that its printed plan matches the expected one.
func TestQueryPlanWithEngine ¶
func TestQueryPlans ¶
func TestQueryPlans(t *testing.T, harness Harness, planTests []queries.QueryPlanTest)
Tests generating the correct query plans for various queries using databases and tables provided by the given harness.
func TestQueryWithContext ¶
func TestQueryWithEngine ¶
func TestReadOnly ¶
func TestReadOnlyDatabases ¶
func TestRenameColumn ¶
func TestRenameTable ¶
func TestReplaceInto ¶
func TestReplaceIntoErrors ¶
func TestRollbackTriggers ¶
func TestScript ¶
func TestScript(t *testing.T, harness Harness, script queries.ScriptTest)
TestScript runs the test script given, making any assertions given
func TestScriptPrepared ¶
TestScriptPrepared substitutes literals for bindvars, runs the test script given, and makes any assertions given
func TestScriptWithEngine ¶
TestScriptWithEngine runs the test script given with the engine provided.
func TestScriptWithEnginePrepared ¶
func TestScriptWithEnginePrepared(t *testing.T, e *sqle.Engine, harness Harness, script queries.ScriptTest)
TestScriptWithEnginePrepared runs the test script with bindvars substituted for literals using the engine provided.
func TestScripts ¶
func TestScriptsPrepared ¶
func TestSessionSelectLimit ¶
func TestShowTableStatus ¶
Runs tests on SHOW TABLE STATUS queries.
func TestShowTableStatusPrepared ¶
Runs tests on SHOW TABLE STATUS queries.
func TestShowTriggers ¶
func TestSpatialDelete ¶
func TestSpatialInsertInto ¶
func TestSpatialQueries ¶
TestSpatialQueries tests a variety of geometry queries against databases and tables provided by the given harness.
func TestSpatialQueriesPrepared ¶
TestSpatialQueriesPrepared tests a variety of geometry queries against databases and tables provided by the given harness.
func TestSpatialScripts ¶
func TestSpatialUpdate ¶
func TestStatistics ¶
TestStatistics tests the statistics from ANALYZE TABLE
func TestStatisticsPrepared ¶
TestStatisticsPrepared tests the statistics from ANALYZE TABLE
func TestStoredProcedures ¶
func TestTracing ¶
func TestTransactionScript ¶
TestTransactionScript runs the test script given, making any assertions given
func TestTransactionScriptWithEngine ¶
func TestTransactionScriptWithEngine(t *testing.T, e *sqle.Engine, harness Harness, script queries.TransactionTest)
TestTransactionScriptWithEngine runs the transaction test script given with the engine provided.
func TestTransactionScripts ¶
func TestTriggerErrors ¶
func TestTriggers ¶
func TestTruncate ¶
func TestTypesOverWire ¶
func TestTypesOverWire(t *testing.T, h Harness, sessionBuilder server.SessionBuilder)
func TestUpdate ¶
func TestUpdateErrors ¶
func TestUpdateIgnore ¶
func TestUserAuthentication ¶
func TestUserPrivileges ¶
func TestValidateSession ¶
func TestVariableErrors ¶
func TestVariables ¶
func TestVersionedQueries ¶
Tests a variety of queries against databases and tables provided by the given harness.
func TestVersionedQueriesPrepared ¶
Tests a variety of queries against databases and tables provided by the given harness.
func TestVersionedViews ¶
func TestViewsPrepared ¶
func TestWarnings ¶
func TestWindowFunctions ¶
func TestWindowRangeFrames ¶
func TestWindowRowFrames ¶
func WidenRows ¶
For a variety of reasons, the widths of various primitive types can vary when passed through different SQL queries (and different database implementations). We may eventually decide that this undefined behavior is a problem, but for now it's mostly just an issue when comparing results in tests. To get around this, we widen every type to its widest value in actual and expected results.
Types ¶
type ClientHarness ¶
type ClientHarness interface { Harness // NewContextWithClient returns a context that will return the given client when requested from the session. NewContextWithClient(client sql.Client) *sql.Context }
ClientHarness allows for integrators to test user privileges, as mock clients are used to test functionality.
type ForeignKeyHarness ¶
type ForeignKeyHarness interface { Harness // SupportsForeignKeys returns whether this harness should accept CREATE FOREIGN KEY statements as part of test // setup. SupportsForeignKeys() bool }
ForeignKeyHarness is an extension to Harness that lets an integrator test their implementation with foreign keys. Integrator tables must implement sql.ForeignKeyTable.
type Harness ¶
type Harness interface { // Parallelism returns how many parallel go routines to use when constructing an engine for test. Parallelism() int // NewDatabase returns a sql.Database to use for a test. This method will always be called before asking for a // context or other information. NewDatabase(name string) sql.Database // NewDatabases returns a set of new databases, for test setup that requires more than one database. NewDatabases(names ...string) []sql.Database // NewDatabaseProvider returns a sql.MutableDatabaseProvider to use for a test. NewDatabaseProvider(dbs ...sql.Database) sql.MutableDatabaseProvider // NewTable takes a database previously created by NewDatabase and returns a table created with the given schema. NewTable(db sql.Database, name string, schema sql.PrimaryKeySchema) (sql.Table, error) // NewContext allows a harness to specify any sessions or context variables necessary for the proper functioning of // their engine implementation. Every harnessed engine test uses the context created by this method, with some // additional information (e.g. current DB) set uniformly. To replicated the behavior of tests during setup, // harnesses should generally dispatch to enginetest.NewContext(harness), rather than calling this method themselves. NewContext() *sql.Context // Setup injects a test suite's setup scripts. The harness is expected to run // these scripts before returning NewEngine Setup(...[]setup.SetupScript) // NewEngine creates a new sqle.Engine. Ready only tests may re-use an // engine. Write tests call NewEngine before every test, expecting the // fresh state provided by Setup. NewEngine(*testing.T) (*sqle.Engine, error) }
Harness provides a way for database integrators to validate their implementation against the standard set of queries used to develop and test the engine itself. See memory_engine_test.go for an example.
type IndexDriverHarness ¶
type IndexDriverHarness interface { Harness // InitializeIndexDriver initializes the index driver for this test run with the databases given InitializeIndexDriver(dbs []sql.Database) }
IndexDriverHarness is an extension to Harness that lets an integrator test their implementation alongside an index driver they provide.
type IndexDriverInitalizer ¶
type IndexDriverInitalizer func([]sql.Database) sql.IndexDriver
type IndexHarness ¶
type IndexHarness interface { Harness // SupportsNativeIndexCreation returns whether this harness should accept CREATE INDEX statements as part of test // setup. SupportsNativeIndexCreation() bool }
IndexHarness is an extension to Harness that lets an integrator test their implementation with native (table-supplied) indexes. Integrator tables must implement sql.IndexAlterableTable.
type KeylessTableHarness ¶
type KeylessTableHarness interface { Harness // SupportsKeylessTables indicates integrator support for keyless tables. SupportsKeylessTables() bool }
KeylessTableHarness is an extension to Harness that lets an integrator test their implementation with keyless tables.
type MemoryHarness ¶
type MemoryHarness struct {
// contains filtered or unexported fields
}
func NewDefaultMemoryHarness ¶
func NewDefaultMemoryHarness() *MemoryHarness
func NewMemoryHarness ¶
func NewMemoryHarness(name string, parallelism int, numTablePartitions int, useNativeIndexes bool, indexDriverInitalizer IndexDriverInitalizer) *MemoryHarness
func (*MemoryHarness) ExternalStoredProcedure ¶
func (m *MemoryHarness) ExternalStoredProcedure(_ *sql.Context, name string, numOfParams int) (*sql.ExternalStoredProcedureDetails, error)
ExternalStoredProcedure implements the sql.ExternalStoredProcedureProvider interface
func (*MemoryHarness) ExternalStoredProcedures ¶
func (m *MemoryHarness) ExternalStoredProcedures(_ *sql.Context, name string) ([]sql.ExternalStoredProcedureDetails, error)
ExternalStoredProcedures implements the sql.ExternalStoredProcedureProvider interface
func (*MemoryHarness) IndexDriver ¶
func (m *MemoryHarness) IndexDriver(dbs []sql.Database) sql.IndexDriver
func (*MemoryHarness) InitializeIndexDriver ¶
func (m *MemoryHarness) InitializeIndexDriver(dbs []sql.Database)
func (*MemoryHarness) NewContext ¶
func (m *MemoryHarness) NewContext() *sql.Context
func (*MemoryHarness) NewContextWithClient ¶
func (m *MemoryHarness) NewContextWithClient(client sql.Client) *sql.Context
func (*MemoryHarness) NewDatabase ¶
func (m *MemoryHarness) NewDatabase(name string) sql.Database
func (*MemoryHarness) NewDatabaseProvider ¶
func (m *MemoryHarness) NewDatabaseProvider(dbs ...sql.Database) sql.MutableDatabaseProvider
func (*MemoryHarness) NewDatabases ¶
func (m *MemoryHarness) NewDatabases(names ...string) []sql.Database
func (*MemoryHarness) NewReadOnlyDatabases ¶
func (m *MemoryHarness) NewReadOnlyDatabases(names ...string) []sql.ReadOnlyDatabase
func (*MemoryHarness) NewSession ¶
func (m *MemoryHarness) NewSession() *sql.Context
func (*MemoryHarness) NewTable ¶
func (m *MemoryHarness) NewTable(db sql.Database, name string, schema sql.PrimaryKeySchema) (sql.Table, error)
func (*MemoryHarness) NewTableAsOf ¶
func (m *MemoryHarness) NewTableAsOf(db sql.VersionedDatabase, name string, schema sql.PrimaryKeySchema, asOf interface{}) sql.Table
func (*MemoryHarness) Parallelism ¶
func (m *MemoryHarness) Parallelism() int
func (*MemoryHarness) QueriesToSkip ¶
func (m *MemoryHarness) QueriesToSkip(queries ...string)
func (*MemoryHarness) Setup ¶
func (m *MemoryHarness) Setup(setupData ...[]setup.SetupScript)
func (*MemoryHarness) SkipQueryTest ¶
func (m *MemoryHarness) SkipQueryTest(query string) bool
func (*MemoryHarness) SnapshotTable ¶
func (m *MemoryHarness) SnapshotTable(db sql.VersionedDatabase, name string, asOf interface{}) error
func (*MemoryHarness) SupportsForeignKeys ¶
func (m *MemoryHarness) SupportsForeignKeys() bool
func (*MemoryHarness) SupportsKeylessTables ¶
func (m *MemoryHarness) SupportsKeylessTables() bool
func (*MemoryHarness) SupportsNativeIndexCreation ¶
func (m *MemoryHarness) SupportsNativeIndexCreation() bool
func (*MemoryHarness) ValidateEngine ¶
type ReadOnlyDatabaseHarness ¶
type ReadOnlyDatabaseHarness interface { Harness // NewReadOnlyDatabases returns a sql.ReadOnlyDatabase to use for a test. NewReadOnlyDatabases(...string) []sql.ReadOnlyDatabase }
type SkippingHarness ¶
type SkippingHarness interface { // SkipQueryTest returns whether to skip a test of the provided query string. SkipQueryTest(query string) bool }
SkippingHarness provides a way for integrators to skip tests that are known to be broken. E.g., integrators that can't handle every possible SQL type.
type SkippingMemoryHarness ¶
type SkippingMemoryHarness struct {
MemoryHarness
}
func NewSkippingMemoryHarness ¶
func NewSkippingMemoryHarness() *SkippingMemoryHarness
func (SkippingMemoryHarness) SkipQueryTest ¶
func (s SkippingMemoryHarness) SkipQueryTest(query string) bool
type TransactionHarness ¶
type ValidatingHarness ¶
type VersionedDBHarness ¶
type VersionedDBHarness interface { Harness // NewTableAsOf creates a new table with the given name and schema, optionally handling snapshotting with the asOf // identifier. NewTableAsOf must ignore tables that already exist in the database. Tables returned by this method do // not need to have any previously created data in them, but they can. This behavior is implementation specific, and // the harness works either way. NewTableAsOf(db sql.VersionedDatabase, name string, schema sql.PrimaryKeySchema, asOf interface{}) sql.Table // SnapshotTable creates a snapshot of the table named with the given asOf label. Depending on the implementation, // NewTableAsOf might do all the necessary work to create such snapshots, so this could be a no-op. SnapshotTable(db sql.VersionedDatabase, name string, asOf interface{}) error }
VersionedDBHarness is an extension to Harness that lets an integrator test their implementation of versioned (AS OF) queries. Integrators must implement sql.VersionedDatabase. For each table version being created, there will be a call to NewTableAsOf, some number of Delete and Insert operations, and then a call to SnapshotTable.