Documentation
¶
Overview ¶
Package pgtestproxy provides functionality for triggering specific PostgreSQL errors in tests.
Index ¶
Constants ¶
const CommonRegexp = `(?is)^(?:--[^\n]*\n|/\*.*?\*/|\s*)*(select|insert|update|delete|merge|with)`
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ErrorResponse ¶
type ErrorResponse struct {
// contains filtered or unexported fields
}
func NewErrorResponse ¶
func NewErrorResponse(severity, code, msg string) *ErrorResponse
NewErrorResponse creates custom error response. See Error Message Fields and Error Codes for more info.
Example:
NewErrorResponse("ERROR", "40001", "serialization failure")
func (*ErrorResponse) Reader ¶
func (e *ErrorResponse) Reader() io.Reader
func (*ErrorResponse) String ¶
func (e *ErrorResponse) String() string
type MatchFunc ¶
MatchFunc determines if custom error response should be triggered based on the actual SQL query string (with all leading and trailing white space removed).
func CreateEqualMatch ¶
CreateEqualMatch creates a MatchFunc that will check the match between actual SQL query and expected SQL query. Beware: equality on query with placeholders does not work in Simple Protocol since all query placeholders will be replaced with actual values on the client.
func MustCreateFingerprintMatch ¶
MustCreateFingerprintMatch creates a MatchFunc that will check the match of fingerprints (see pgquery.Fingerprint) between actual SQL query and expected SQL query.
func MustCreateNormalizedRegexpMatch ¶
MustCreateNormalizedRegexpMatch creates a MatchFunc that will check the match of the normalized (see pgquery.Normalize) actual SQL query based on the given regular expression.
type Matcher ¶
type Matcher struct {
MatchFn MatchFunc
ErrResp *ErrorResponse
}
type Options ¶
type Options struct {
PostgresAddr string
ProxyAddr string
Rule *RewriteRule
Exclude []MatchFunc // optional
Log func(args ...any) // optional
}
type RewriteRule ¶
type RewriteRule struct {
// contains filtered or unexported fields
}
RewriteRule is a per-proxy internal data store for user defined rule for rewriting/skipping PostgreSQL wire protocol messages.
func (*RewriteRule) Init ¶
func (r *RewriteRule) Init(data RewriteRuleData) error
Init (re)initializes the RewriteRule with the user defined rule data. It must be called before each consecutive subtest (parallel subtests are not supported).
type RewriteRuleData ¶
RewriteRuleData is a rule for rewriting/skipping PostgreSQL wire protocol messages. When a Matcher matches an actual SQL query, the custom error is triggered, and the Matcher is removed from the slice. By default, with IgnoreOrder == false, SQL queries are only checked for matching the first Matcher in the slice. With IgnoreOrder == true, SQL queries are checked for matching any Matcher in the slice.