Documentation
¶
Overview ¶
sqltest is a scenario testing framework for evaluating MySQL compatibility.
Index ¶
- Constants
- func RunEmbedSuites(t *testing.T, client Client, regexes ...string) error
- func RunScenarioFiles(t *testing.T, testFilenames []string)
- type AuthConfig
- type AuthMethod
- type Client
- type ClientConfig
- type ClientTLSConfig
- type Config
- type Line
- type MySQLClient
- func (client *MySQLClient) Close() error
- func (client *MySQLClient) CreateDatabase(name string) error
- func (client *MySQLClient) DropDatabase(name string) error
- func (client *MySQLClient) Open() error
- func (client *MySQLClient) Ping() error
- func (client *MySQLClient) Query(query string, args ...any) (*sql.Rows, error)
- func (client *MySQLClient) Use(name string) error
- type PgxClient
- func (client *PgxClient) Close() error
- func (client *PgxClient) Conn() *pgx.Conn
- func (client *PgxClient) CreateDatabase(name string) error
- func (client *PgxClient) DropDatabase(name string) error
- func (client *PgxClient) Open() error
- func (client *PgxClient) Ping() error
- func (client *PgxClient) Query(query string, args ...any) (pgx.Rows, error)
- func (client *PgxClient) Use(name string) error
- type PqClient
- func (client *PqClient) Close() error
- func (client *PqClient) CreateDatabase(name string) error
- func (client *PqClient) DB() *sql.DB
- func (client *PqClient) DropDatabase(name string) error
- func (client *PqClient) Open() error
- func (client *PqClient) Ping() error
- func (client *PqClient) Query(query string, args ...any) (*sql.Rows, error)
- func (client *PqClient) Use(name string) error
- type QueryBindings
- type QueryContext
- type QueryContextData
- type QueryResponseRow
- type QueryRows
- type Scenario
- func (scn *Scenario) Bindings() []QueryBindings
- func (scn *Scenario) Cases() []*ScenarioCase
- func (scn *Scenario) ExpectedRows() ([]QueryRows, error)
- func (scn *Scenario) LoadFile(filename string) error
- func (scn *Scenario) Name() string
- func (scn *Scenario) ParseBytes(name string, b []byte) error
- func (scn *Scenario) ParseLineStrings(lines []string) error
- func (scn *Scenario) Queries() []string
- func (scn *Scenario) String() string
- type ScenarioCase
- type ScenarioCaseOption
- type ScenarioOption
- type ScenarioStepHandler
- type ScenarioTester
- func (runner *ScenarioTester) LoadFile(filename string) error
- func (runner *ScenarioTester) LoadFileWithBasename(basename string) error
- func (runner *ScenarioTester) Name() string
- func (runner *ScenarioTester) ParseBytes(name string, b []byte) error
- func (runner *ScenarioTester) Run() error
- func (runner *ScenarioTester) Scenario() *Scenario
- func (runner *ScenarioTester) SetClient(c Client)
- func (runner *ScenarioTester) SetStepHandler(handler ScenarioStepHandler)
- type ScenarioTesterOption
- type Suite
- func (suite *Suite) ExtractScenarioMatchingTests(regexes ...string) ([]*ScenarioTester, error)
- func (suite *Suite) ExtractScenarioTests(regexpNames ...string) ([]*ScenarioTester, error)
- func (suite *Suite) LoadDirectorySenarios(dirs ...string) error
- func (suite *Suite) LoadEmbedSenarios(testMaps ...map[string][]byte) error
- func (suite *Suite) Run() error
- func (suite *Suite) ScenarioTesters() []*ScenarioTester
- func (suite *Suite) ScenarioTests() []*ScenarioTester
- func (suite *Suite) SetClient(c Client)
- func (suite *Suite) SetErrorHandler(handler SuiteErrorHandler)
- func (suite *Suite) Test(t *testing.T) error
- func (suite *Suite) TestScenario(t *testing.T, test *ScenarioTester) error
- type SuiteErrorHandler
- type SuiteOption
- func WithSuiteClient(client Client) SuiteOption
- func WithSuiteDirectories(dirs ...string) SuiteOption
- func WithSuiteEmbeds(tests ...map[string][]byte) SuiteOption
- func WithSuiteErrorHandler(handler SuiteErrorHandler) SuiteOption
- func WithSuiteRegexes(regexes ...string) SuiteOption
- func WithSuiteStepHandler(handler ScenarioStepHandler) SuiteOption
- type TLSConfig
Constants ¶
const ( ProgramName = "go-sqltest" TestRunDescription = ProgramName + "(" + Version + ")" )
const ( QueryContextRowsKey = "rows" QueryContextBindingsKey = "bindings" )
const ( TestDBNamePrefix = "sqltest" SuiteDefaultTestDirectory = "./test" )
const (
ScenarioFileExt = "qst"
)
const (
Version = "v1.5.0"
)
Variables ¶
This section is empty.
Functions ¶
func RunEmbedSuites ¶ added in v0.9.5
RunEmbedSuites runs the embedded test suites with the specified regular expressions.
func RunScenarioFiles ¶ added in v1.4.3
Types ¶
type AuthConfig ¶ added in v1.4.2
type AuthConfig struct { User string Password string Auth AuthMethod }
AuthConfig stores authentication configuration parameters.
func NewAuthConfig ¶ added in v1.4.2
func NewAuthConfig() *AuthConfig
NewAuthConfig returns a default authentication configuration instance.
func (*AuthConfig) SetAuth ¶ added in v1.4.2
func (config *AuthConfig) SetAuth(auth AuthMethod)
SetAuth sets an authentication method.
func (*AuthConfig) SetPassword ¶ added in v1.4.2
func (config *AuthConfig) SetPassword(password string)
SetPassword sets a password.
func (*AuthConfig) SetUser ¶ added in v1.4.2
func (config *AuthConfig) SetUser(user string)
SetUser sets a user name.
type AuthMethod ¶ added in v1.4.2
type AuthMethod int
AuthMethod represents an authentication method.
const ( AuthdNone AuthMethod = iota AuthPlain AuthMD5 AuthSCRAMSHA256 )
type Client ¶ added in v0.9.1
type Client interface { // ClientConfig represents a client configuration interface. ClientConfig // ClientTLSConfig represents a client TLS configuration interface. ClientTLSConfig // Open opens a database specified by the internal configuration. Open() error // Close closes the opened database. Close() error // Use uses a database. Use(name string) error // Ping pings the opened database. Ping() error // CreateDatabase creates a database. CreateDatabase(name string) error // DropDatabase drops a database. DropDatabase(name string) error // Query executes a query. Query(query string, args ...any) (*sql.Rows, error) }
Client represents a client interface for SQL databases.
func NewMySQLClient ¶ added in v0.9.1
func NewMySQLClient() Client
NewMySQLClient returns a client instance.
func NewPostgresClient ¶ added in v0.9.6
func NewPostgresClient() Client
NewPostgresClient returns a new defaultPostgreSQL client.
type ClientConfig ¶ added in v1.4.0
type ClientConfig interface { // SetHost sets a host name. SetHost(host string) // SetPort sets a port number. SetPort(port int) // SetUser sets a user name. SetUser(user string) // SetPassword sets a password. SetPassword(passwd string) // SetDatabase sets a database name. SetDatabase(db string) }
ClientConfig represents a client configuration interface.
type ClientTLSConfig ¶ added in v1.4.0
type ClientTLSConfig interface { // TLSEnabled returns true if TLS is enabled. TLSEnabled() bool // SetClientKeyFile sets a SSL client key file. SetClientKeyFile(file string) // SetClientCertFile sets a SSL client certificate file. SetClientCertFile(file string) // SetRootCertFile sets a SSL root certificate file. SetRootCertFile(file string) }
ClientTLSConfig represents a client TLS configuration interface.
type Config ¶ added in v0.9.1
type Config struct { Host string Port int Database string *AuthConfig *TLSConfig }
Config stores server configuration parammeters.
func NewDefaultConfig ¶ added in v0.9.1
func NewDefaultConfig() *Config
NewDefaultConfig returns a default configuration instance.
func (*Config) SetDatabase ¶ added in v0.9.1
SetDatabase sets a host database.
type MySQLClient ¶ added in v0.9.1
type MySQLClient struct { *Config // contains filtered or unexported fields }
MySQLClient represents a client for MySQL server.
func (*MySQLClient) Close ¶ added in v0.9.1
func (client *MySQLClient) Close() error
Close closes opens a database specified by the internal configuration.
func (*MySQLClient) CreateDatabase ¶ added in v0.9.2
func (client *MySQLClient) CreateDatabase(name string) error
CreateDatabase creates a specified database.
func (*MySQLClient) DropDatabase ¶ added in v0.9.2
func (client *MySQLClient) DropDatabase(name string) error
DropDatabase dtops a specified database.
func (*MySQLClient) Open ¶ added in v0.9.1
func (client *MySQLClient) Open() error
Open opens a database specified by the internal configuration. nolint: gosec, exhaustruct, staticcheck
func (*MySQLClient) Ping ¶ added in v1.3.2
func (client *MySQLClient) Ping() error
Ping pings the opened database.
func (*MySQLClient) Use ¶ added in v0.9.2
func (client *MySQLClient) Use(name string) error
Use sets a target database.
type PgxClient ¶ added in v1.2.3
type PgxClient struct { *Config // contains filtered or unexported fields }
PgxClient represents a client for PostgreSQL server.
func NewPgxClient ¶ added in v1.2.3
func NewPgxClient() *PgxClient
NewPgxClient returns a Pgx client instance.
func (*PgxClient) Conn ¶ added in v1.2.3
func (client *PgxClient) Conn() *pgx.Conn
Conn returns a connected database connection.
func (*PgxClient) CreateDatabase ¶ added in v1.2.3
CreateDatabase creates a specified database.
func (*PgxClient) DropDatabase ¶ added in v1.2.3
DropDatabase dtops a specified database.
type PqClient ¶ added in v1.2.3
type PqClient struct { *Config // contains filtered or unexported fields }
PqClient represents a client for PostgreSQL server.
func NewPqClient ¶ added in v1.2.3
func NewPqClient() *PqClient
NewPqClient returns a new lib/pq client.
func (*PqClient) Close ¶ added in v1.2.3
Close closes opens a database specified by the internal configuration.
func (*PqClient) CreateDatabase ¶ added in v1.2.3
CreateDatabase creates a specified database.
func (*PqClient) DropDatabase ¶ added in v1.2.3
DropDatabase dtops a specified database.
func (*PqClient) Open ¶ added in v1.2.3
Open opens a database specified by the internal configuration.
type QueryBindings ¶ added in v1.4.5
type QueryBindings = []any
QueryBindings defines a JSON response bindings type.
type QueryContext ¶ added in v1.4.5
type QueryContext struct {
Data QueryContextData
}
QueryContext represents a response of a query.
func NewQueryContext ¶ added in v1.4.5
func NewQueryContext() *QueryContext
NewQueryContext returns a response instance.
func NewQueryContextWithString ¶ added in v1.4.5
func NewQueryContextWithString(json string) (*QueryContext, error)
NewQueryContextWithString returns a response instance of the specified JSON response.
func (*QueryContext) Bindings ¶ added in v1.4.5
func (res *QueryContext) Bindings() (QueryBindings, bool)
Bindings returns response bindings.
func (*QueryContext) ParseString ¶ added in v1.4.5
func (res *QueryContext) ParseString(jsonStr string) error
ParseString parses a specified string response as a JSON data.
func (*QueryContext) Rows ¶ added in v1.4.5
func (res *QueryContext) Rows() (QueryRows, bool)
Rows returns response rows with true when the response has any rows, otherwise nil and false.
func (*QueryContext) String ¶ added in v1.4.5
func (res *QueryContext) String() string
String returns the string representation.
type QueryContextData ¶ added in v1.4.5
QueryContextData defines a JSON response data type.
type QueryResponseRow ¶ added in v0.9.3
QueryResponseRow defines a JSON response row type.
type QueryRows ¶ added in v1.4.5
type QueryRows = []any
QueryRows defines a JSON response rows type.
type Scenario ¶ added in v0.9.3
type Scenario struct {
// contains filtered or unexported fields
}
Scenario represents a scenario.
func NewScenario ¶ added in v0.9.3
func NewScenario() *Scenario
NewScenario return a scenario instance.
func NewScenarioWith ¶ added in v1.4.3
func NewScenarioWith(opts ...ScenarioOption) (*Scenario, error)
NewScenarioWith returns a scenario instance with the specified options.
func NewScenarioWithBytes ¶ added in v0.9.3
NewScenarioWithBytes return a scenario instance for the specified test scenario bytes.
func NewScenarioWithFile ¶ added in v0.9.3
NewScenarioWithFile return a scenario instance for the specified test scenario file.
func (*Scenario) Bindings ¶ added in v1.4.5
func (scn *Scenario) Bindings() []QueryBindings
Bindings returns the loaded scenario bindings.
func (*Scenario) Cases ¶ added in v1.4.5
func (scn *Scenario) Cases() []*ScenarioCase
Cases returns the loaded scenario cases.
func (*Scenario) ExpectedRows ¶ added in v1.4.5
ExpectedRows returns the loaded scenario expected rows.
func (*Scenario) ParseBytes ¶ added in v0.9.3
ParseBytes parses the specified scenario bytes.
func (*Scenario) ParseLineStrings ¶ added in v0.9.3
ParseLineStrings parses the specified scenario line strings.
type ScenarioCase ¶ added in v1.4.5
type ScenarioCase struct {
// contains filtered or unexported fields
}
ScenarioCase represents a scenario case.
func NewScenarioCaseWith ¶ added in v1.4.5
func NewScenarioCaseWith(opts ...ScenarioCaseOption) *ScenarioCase
NewScenarioCase returns a scenario case instance.
func (*ScenarioCase) Bindings ¶ added in v1.4.5
func (sc *ScenarioCase) Bindings() []any
Bindings returns bindings of the scenario case.
func (*ScenarioCase) HasRow ¶ added in v1.4.5
func (sc *ScenarioCase) HasRow(row any) error
HasRow returns true when the response has a specified row, otherwise false. nolint: gocyclo
func (*ScenarioCase) Query ¶ added in v1.4.5
func (sc *ScenarioCase) Query() string
Query returns a query of the scenario case.
func (*ScenarioCase) Rows ¶ added in v1.4.5
func (sc *ScenarioCase) Rows() QueryRows
Rows returns rows of the scenario case.
type ScenarioCaseOption ¶ added in v1.4.5
type ScenarioCaseOption func(*ScenarioCase) error
ScenarioCaseOption represents an option function for a scenario case.
func WithScenarioCaseBindings ¶ added in v1.4.5
func WithScenarioCaseBindings(bindings []any) ScenarioCaseOption
WithScenarioCaseBindings returns a scenario case option to set bindings.
func WithScenarioCaseQuery ¶ added in v1.4.5
func WithScenarioCaseQuery(query string) ScenarioCaseOption
WithScenarioCaseQuery returns a scenario case option to set a query.
func WithScenarioCaseRows ¶ added in v1.4.5
func WithScenarioCaseRows(rows QueryRows) ScenarioCaseOption
WithScenarioCaseRows returns a scenario case option to set rows.
type ScenarioOption ¶ added in v1.4.3
ScenarioOption represents an option function for a scenario.
func WithScenarioBytes ¶ added in v1.4.3
func WithScenarioBytes(name string, b []byte) ScenarioOption
WithScenarioBytes returns a scenario option to load the specified scenario bytes.
func WithScenarioFile ¶ added in v1.4.3
func WithScenarioFile(filename string) ScenarioOption
WithScenarioFile returns a scenario option to load the specified scenario file.
type ScenarioStepHandler ¶ added in v1.4.3
ScenarioStepHandler represents a scenario step handler.
type ScenarioTester ¶ added in v1.4.5
type ScenarioTester struct {
// contains filtered or unexported fields
}
ScenarioTester represents a scenario runner.
func NewScenarioTester ¶ added in v1.4.5
func NewScenarioTester() *ScenarioTester
NewScenarioTester returns a scenario tester instance.
func NewScenarioTesterWith ¶ added in v1.4.5
func NewScenarioTesterWith(options ...ScenarioTesterOption) (*ScenarioTester, error)
NewScenarioTesterWith returns a scenario tester instance with the specified options.
func NewScenarioTesterWithBytes ¶ added in v1.4.5
func NewScenarioTesterWithBytes(name string, b []byte) (*ScenarioTester, error)
NewScenarioTesterWithBytes return a scenario test instance for the specified test scenario bytes.
func NewScenarioTesterWithFile ¶ added in v1.4.5
func NewScenarioTesterWithFile(filename string) (*ScenarioTester, error)
NewScenarioTesterWithFile return a scenario test instance for the specified test scenario file.
func (*ScenarioTester) LoadFile ¶ added in v1.4.5
func (runner *ScenarioTester) LoadFile(filename string) error
LoadFile loads a specified scenario test file.
func (*ScenarioTester) LoadFileWithBasename ¶ added in v1.4.5
func (runner *ScenarioTester) LoadFileWithBasename(basename string) error
LoadFileWithBasename loads a scenario test file which has specified basename.
func (*ScenarioTester) Name ¶ added in v1.4.5
func (runner *ScenarioTester) Name() string
Name returns the loaded senario name.
func (*ScenarioTester) ParseBytes ¶ added in v1.4.5
func (runner *ScenarioTester) ParseBytes(name string, b []byte) error
ParseBytes loads a specified scenario test bytes.
func (*ScenarioTester) Run ¶ added in v1.4.5
func (runner *ScenarioTester) Run() error
Run runs a loaded scenario test.
func (*ScenarioTester) Scenario ¶ added in v1.4.5
func (runner *ScenarioTester) Scenario() *Scenario
Scenario returns the loaded scenario.
func (*ScenarioTester) SetClient ¶ added in v1.4.5
func (runner *ScenarioTester) SetClient(c Client)
SetClient sets a client for testing.
func (*ScenarioTester) SetStepHandler ¶ added in v1.4.5
func (runner *ScenarioTester) SetStepHandler(handler ScenarioStepHandler)
SetStepHandler sets a step handler for testing.
type ScenarioTesterOption ¶ added in v1.4.5
type ScenarioTesterOption func(*ScenarioTester) error
ScenarioTesterOption represents an option function for a scenario runner.
func WithScenarioTesterBytes ¶ added in v1.4.5
func WithScenarioTesterBytes(name string, b []byte) ScenarioTesterOption
WithScenarioTesterBytes returns a scenario tester option to set a client.
func WithScenarioTesterClient ¶ added in v1.4.5
func WithScenarioTesterClient(client Client) ScenarioTesterOption
WithScenarioTesterClient returns a scenario tester option to set a client.
func WithScenarioTesterFile ¶ added in v1.4.5
func WithScenarioTesterFile(filename string) ScenarioTesterOption
WithScenarioTesterClient returns a scenario tester option to set a client.
func WithScenarioTesterStepHandler ¶ added in v1.4.5
func WithScenarioTesterStepHandler(handler ScenarioStepHandler) ScenarioTesterOption
WithScenarioTesterStepHandler returns a scenario tester option to set a step handler.
type Suite ¶ added in v0.9.3
type Suite struct {
// contains filtered or unexported fields
}
Suite represents a scenario test suite.
func NewSuite ¶ added in v0.9.3
func NewSuite() *Suite
NewSuite returns a scenario test suite instance.
func NewSuiteWith ¶ added in v1.4.3
func NewSuiteWith(opts ...SuiteOption) (*Suite, error)
NewSuite returns a scenario test suite instance with the specified options.
func NewSuiteWithDirectory ¶ added in v0.9.3
NewSuiteWithDirectory returns a scenario test suite instance which loads under the specified directory.
func NeweEmbedSuite ¶ added in v0.9.3
NeweEmbedSuite returns a scenario test suite instance which loads under the specified directory.
func (*Suite) ExtractScenarioMatchingTests ¶ added in v1.2.1
func (suite *Suite) ExtractScenarioMatchingTests(regexes ...string) ([]*ScenarioTester, error)
func (*Suite) ExtractScenarioTests ¶ added in v1.0.0
func (suite *Suite) ExtractScenarioTests(regexpNames ...string) ([]*ScenarioTester, error)
ExtractScenarioTests returns scenario tests with the specified names.
func (*Suite) LoadDirectorySenarios ¶ added in v1.4.3
LoadDirectorySenarios loads scenario tests from the specified directories.
func (*Suite) LoadEmbedSenarios ¶ added in v1.4.3
LoadEmbedSenarios loads scenario tests from the specified bytes.
func (*Suite) Run ¶ added in v0.9.3
Run runs all loaded scenario tests. The method stops the testing when a scenario test is aborted, and the following tests are not run.
func (*Suite) ScenarioTesters ¶ added in v1.4.5
func (suite *Suite) ScenarioTesters() []*ScenarioTester
ScenarioTesters returns all loaded scenario tests.
func (*Suite) ScenarioTests ¶ added in v1.0.0
func (suite *Suite) ScenarioTests() []*ScenarioTester
ScenarioTests returns all loaded scenario tests.
func (*Suite) SetErrorHandler ¶ added in v1.4.3
func (suite *Suite) SetErrorHandler(handler SuiteErrorHandler)
SetErrorHandler sets a handler for errors in a Suite.
func (*Suite) Test ¶ added in v1.4.3
Test runs all loaded scenario tests with regular expressions for scenarios. The method stops the testing when a scenario test is aborted, and the following tests are not run.
func (*Suite) TestScenario ¶ added in v1.4.3
func (suite *Suite) TestScenario(t *testing.T, test *ScenarioTester) error
RunScenarioTest runs the specified test.
type SuiteErrorHandler ¶ added in v1.4.3
type SuiteErrorHandler func(*Suite, *ScenarioTester, error)
SuiteErrorHandler is a function type used to handle errors in a Suite.
type SuiteOption ¶ added in v1.4.3
SuiteOption is a function type used to configure a Suite.
func WithSuiteClient ¶ added in v1.4.3
func WithSuiteClient(client Client) SuiteOption
WithSuiteClient returns a SuiteOption that sets a client for testing.
func WithSuiteDirectories ¶ added in v1.4.3
func WithSuiteDirectories(dirs ...string) SuiteOption
WithSuiteDirectories returns a SuiteOption that loads scenario tests from the specified directory.
func WithSuiteEmbeds ¶ added in v1.4.3
func WithSuiteEmbeds(tests ...map[string][]byte) SuiteOption
WithSuiteEmbeds returns a SuiteOption that loads scenario tests from the specified bytes.
func WithSuiteErrorHandler ¶ added in v1.4.3
func WithSuiteErrorHandler(handler SuiteErrorHandler) SuiteOption
WithSuiteErrorHandler returns a SuiteOption that sets a handler for errors in a Suite.
func WithSuiteRegexes ¶ added in v1.4.3
func WithSuiteRegexes(regexes ...string) SuiteOption
WithSuiteRegexes returns a SuiteOption that extracts scenario tests with the specified regexes.
func WithSuiteStepHandler ¶ added in v1.4.3
func WithSuiteStepHandler(handler ScenarioStepHandler) SuiteOption
WithSuiteStepHandler returns a SuiteOption that sets a handler for errors in a Suite.
type TLSConfig ¶ added in v1.4.0
TLSConfig represents a TLS configuration.
func NewTLSConfig ¶ added in v1.4.0
func NewTLSConfig() *TLSConfig
NewTLSConfig returns a new TLS configuration. nolint: gosec, exhaustruct
func (*TLSConfig) SetClientCertFile ¶ added in v1.4.0
SetClientCertFile sets a SSL client certificate file.
func (*TLSConfig) SetClientKeyFile ¶ added in v1.4.0
SetClientKeyFile sets a SSL client key file.
func (*TLSConfig) SetRootCertFile ¶ added in v1.4.0
SetRootCertFile sets a SSL root certificate file.
func (*TLSConfig) TLSEnabled ¶ added in v1.4.0
TLSEnabled returns true if TLS is enabled.