sqltest

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: Apache-2.0 Imports: 25 Imported by: 2

Documentation

Overview

sqltest is a scenario testing framework for evaluating MySQL compatibility.

Index

Constants

View Source
const (
	ProgramName        = "go-sqltest"
	TestRunDescription = ProgramName + "(" + Version + ")"
)
View Source
const (
	TestDBNamePrefix          = "sqltest"
	SuiteDefaultTestDirectory = "./test"
)
View Source
const (
	QueryResponseRowsKey = "rows"
)
View Source
const (
	ScenarioFileExt = "qst"
)
View Source
const (
	Version = "v1.4.3"
)

Variables

This section is empty.

Functions

func RunEmbedSuites added in v0.9.5

func RunEmbedSuites(t *testing.T, client Client, regexes ...string) error

RunEmbedSuites runs the embedded test suites with the specified regular expressions.

func RunScenarioFiles added in v1.4.3

func RunScenarioFiles(t *testing.T, testFilenames []string)

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 ...interface{}) (*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

func (config *Config) SetDatabase(db string)

SetDatabase sets a host database.

func (*Config) SetHost added in v0.9.1

func (config *Config) SetHost(host string)

SetHost sets a host address.

func (*Config) SetPort added in v0.9.1

func (config *Config) SetPort(port int)

SetPort sets a listen port.

type Line

type Line = string

Line represents a line of a scenario test file.

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) Query added in v0.9.1

func (client *MySQLClient) Query(query string, args ...interface{}) (*sql.Rows, error)

Query executes a query that returns rows.

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) Close added in v1.2.3

func (client *PgxClient) Close() error

Close closes the opened database.

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

func (client *PgxClient) CreateDatabase(name string) error

CreateDatabase creates a specified database.

func (*PgxClient) DropDatabase added in v1.2.3

func (client *PgxClient) DropDatabase(name string) error

DropDatabase dtops a specified database.

func (*PgxClient) Open added in v1.2.3

func (client *PgxClient) Open() error

Open opens a database specified by the client.

func (*PgxClient) Ping added in v1.3.2

func (client *PgxClient) Ping() error

Ping pings the opened database.

func (*PgxClient) Query added in v1.2.3

func (client *PgxClient) Query(query string, args ...interface{}) (pgx.Rows, error)

Query executes a query that returns rows.

func (*PgxClient) Use added in v1.2.3

func (client *PgxClient) Use(name string) error

Use sets a target 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

func (client *PqClient) Close() error

Close closes opens a database specified by the internal configuration.

func (*PqClient) CreateDatabase added in v1.2.3

func (client *PqClient) CreateDatabase(name string) error

CreateDatabase creates a specified database.

func (*PqClient) DB added in v1.2.3

func (client *PqClient) DB() *sql.DB

DB returns a connected database instance.

func (*PqClient) DropDatabase added in v1.2.3

func (client *PqClient) DropDatabase(name string) error

DropDatabase dtops a specified database.

func (*PqClient) Open added in v1.2.3

func (client *PqClient) Open() error

Open opens a database specified by the internal configuration.

func (*PqClient) Ping added in v1.3.2

func (client *PqClient) Ping() error

Ping pings the opened database.

func (*PqClient) Query added in v1.2.3

func (client *PqClient) Query(query string, args ...interface{}) (*sql.Rows, error)

Query executes a query that returns rows.

func (*PqClient) Use added in v1.2.3

func (client *PqClient) Use(name string) error

Use sets a target database.

type QueryResponse added in v0.9.3

type QueryResponse struct {
	Data QueryResponseData
}

QueryResponse represents a response of a query.

func NewQueryResponse added in v0.9.3

func NewQueryResponse() *QueryResponse

NewQueryResponse returns a response instance.

func NewQueryResponseWithString added in v0.9.3

func NewQueryResponseWithString(json string) (*QueryResponse, error)

NewQueryResponseWithString returns a response instance of the specified JSON response.

func (*QueryResponse) HasRow added in v0.9.3

func (res *QueryResponse) HasRow(row interface{}) error

HasRow returns true when the response has a specified row, otherwise false. nolint: gocyclo

func (*QueryResponse) ParseString added in v0.9.3

func (res *QueryResponse) ParseString(jsonStr string) error

ParseString parses a specified string response as a JSON data.

func (*QueryResponse) Rows added in v0.9.3

func (res *QueryResponse) Rows() (QueryResponseRows, error)

Rows returns response rows with true when the response has any rows, otherwise nil and false.

func (*QueryResponse) String added in v0.9.3

func (res *QueryResponse) String() string

String returns the string representation.

type QueryResponseData added in v0.9.3

type QueryResponseData = map[string]interface{}

QueryResponseData defines a JSON response data type.

type QueryResponseRow added in v0.9.3

type QueryResponseRow = map[string]interface{}

QueryResponseRow defines a JSON response row type.

type QueryResponseRows added in v0.9.3

type QueryResponseRows = []interface{}

QueryResponseRows defines a JSON response rows type.

type Scenario added in v0.9.3

type Scenario struct {
	Filename  string
	Queries   []string
	Expecteds []*QueryResponse
}

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

func NewScenarioWithBytes(name string, b []byte) (*Scenario, error)

NewScenarioWithBytes return a scenario instance for the specified test scenario bytes.

func NewScenarioWithFile added in v0.9.3

func NewScenarioWithFile(filename string) (*Scenario, error)

NewScenarioWithFile return a scenario instance for the specified test scenario file.

func (*Scenario) IsValid added in v0.9.3

func (scn *Scenario) IsValid() error

IsValid checks whether the loaded scenario is available.

func (*Scenario) LoadFile added in v0.9.3

func (scn *Scenario) LoadFile(filename string) error

LoadFile loads the specified scenario.

func (*Scenario) Name added in v0.9.3

func (scn *Scenario) Name() string

Name returns the loaded scenario file name.

func (*Scenario) ParseBytes added in v0.9.3

func (scn *Scenario) ParseBytes(name string, b []byte) error

ParseBytes parses the specified scenario bytes.

func (*Scenario) ParseLineStrings added in v0.9.3

func (scn *Scenario) ParseLineStrings(lines []string) error

ParseLineStrings parses the specified scenario line strings.

func (*Scenario) String added in v0.9.3

func (scn *Scenario) String() string

String returns the string representation.

type ScenarioOption added in v1.4.3

type ScenarioOption func(*Scenario) error

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 ScenarioRunner added in v1.4.3

type ScenarioRunner struct {
	Scenario *Scenario
	// contains filtered or unexported fields
}

ScenarioRunner represents a scenario runner.

func NewScenarioRunner added in v1.4.3

func NewScenarioRunner() *ScenarioRunner

NewScenarioRunner returns a scenario runner instance.

func NewScenarioRunnerWith added in v1.4.3

func NewScenarioRunnerWith(options ...ScenarioRunnerOption) (*ScenarioRunner, error)

NewScenarioRunnerWith returns a scenario runner instance with the specified options.

func NewScenarioRunnerWithBytes added in v1.4.3

func NewScenarioRunnerWithBytes(name string, b []byte) (*ScenarioRunner, error)

NewScenarioRunnerWithBytes return a scenario test instance for the specified test scenario bytes.

func NewScenarioRunnerWithFile added in v1.4.3

func NewScenarioRunnerWithFile(filename string) (*ScenarioRunner, error)

NewScenarioRunnerWithFile return a scenario test instance for the specified test scenario file.

func (*ScenarioRunner) LoadFile added in v1.4.3

func (runner *ScenarioRunner) LoadFile(filename string) error

LoadFile loads a specified scenario test file.

func (*ScenarioRunner) LoadFileWithBasename added in v1.4.3

func (runner *ScenarioRunner) LoadFileWithBasename(basename string) error

LoadFileWithBasename loads a scenario test file which has specified basename.

func (*ScenarioRunner) Name added in v1.4.3

func (runner *ScenarioRunner) Name() string

Name returns the loaded senario name.

func (*ScenarioRunner) ParseBytes added in v1.4.3

func (runner *ScenarioRunner) ParseBytes(name string, b []byte) error

ParseBytes loads a specified scenario test bytes.

func (*ScenarioRunner) Run added in v1.4.3

func (runner *ScenarioRunner) Run() error

Run runs a loaded scenario test.

func (*ScenarioRunner) SetClient added in v1.4.3

func (runner *ScenarioRunner) SetClient(c Client)

SetClient sets a client for testing.

func (*ScenarioRunner) SetStepHandler added in v1.4.3

func (runner *ScenarioRunner) SetStepHandler(handler ScenarioStepHandler)

SetStepHandler sets a step handler for testing.

type ScenarioRunnerOption added in v1.4.3

type ScenarioRunnerOption func(*ScenarioRunner) error

ScenarioRunnerOption represents an option function for a scenario runner.

func WithScenarioRunnerBytes added in v1.4.3

func WithScenarioRunnerBytes(name string, b []byte) ScenarioRunnerOption

WithScenarioRunnerBytes returns a scenario runner option to set a client.

func WithScenarioRunnerClient added in v1.4.3

func WithScenarioRunnerClient(client Client) ScenarioRunnerOption

WithScenarioRunnerClient returns a scenario runner option to set a client.

func WithScenarioRunnerFile added in v1.4.3

func WithScenarioRunnerFile(filename string) ScenarioRunnerOption

WithScenarioRunnerClient returns a scenario runner option to set a client.

func WithScenarioRunnerStepHandler added in v1.4.3

func WithScenarioRunnerStepHandler(handler ScenarioStepHandler) ScenarioRunnerOption

WithScenarioRunnerStepHandler returns a scenario runner option to set a step handler.

type ScenarioStepHandler added in v1.4.3

type ScenarioStepHandler func(*Scenario, int, string, error)

ScenarioStepHandler represents a scenario 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

func NewSuiteWithDirectory(dirs ...string) (*Suite, error)

NewSuiteWithDirectory returns a scenario test suite instance which loads under the specified directory.

func NeweEmbedSuite added in v0.9.3

func NeweEmbedSuite(tests ...map[string][]byte) (*Suite, error)

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) ([]*ScenarioRunner, error)

func (*Suite) ExtractScenarioTests added in v1.0.0

func (suite *Suite) ExtractScenarioTests(regexpNames ...string) ([]*ScenarioRunner, error)

ExtractScenarioTests returns scenario tests with the specified names.

func (*Suite) LoadDirectorySenarios added in v1.4.3

func (suite *Suite) LoadDirectorySenarios(dirs ...string) error

LoadDirectorySenarios loads scenario tests from the specified directories.

func (*Suite) LoadEmbedSenarios added in v1.4.3

func (suite *Suite) LoadEmbedSenarios(testMaps ...map[string][]byte) error

LoadEmbedSenarios loads scenario tests from the specified bytes.

func (*Suite) Run added in v0.9.3

func (suite *Suite) Run() error

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) ScenarioTests added in v1.0.0

func (suite *Suite) ScenarioTests() []*ScenarioRunner

ScenarioTests returns all loaded scenario tests.

func (*Suite) SetClient added in v0.9.3

func (suite *Suite) SetClient(c Client)

SetClient sets a client for testing.

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

func (suite *Suite) Test(t *testing.T) error

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 *ScenarioRunner) error

RunScenarioTest runs the specified test.

type SuiteErrorHandler added in v1.4.3

type SuiteErrorHandler func(*Suite, *ScenarioRunner, error)

SuiteErrorHandler is a function type used to handle errors in a Suite.

type SuiteOption added in v1.4.3

type SuiteOption func(*Suite) error

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

type TLSConfig struct {
	ClientCertFile string
	ClientKeyFile  string
	RootCertFile   string
}

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

func (config *TLSConfig) SetClientCertFile(file string)

SetClientCertFile sets a SSL client certificate file.

func (*TLSConfig) SetClientKeyFile added in v1.4.0

func (config *TLSConfig) SetClientKeyFile(file string)

SetClientKeyFile sets a SSL client key file.

func (*TLSConfig) SetRootCertFile added in v1.4.0

func (config *TLSConfig) SetRootCertFile(file string)

SetRootCertFile sets a SSL root certificate file.

func (*TLSConfig) TLSEnabled added in v1.4.0

func (config *TLSConfig) TLSEnabled() bool

TLSEnabled returns true if TLS is enabled.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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