Documentation
¶
Overview ¶
Package querycount counts the statements a test's database sends to the driver. It wraps the database testdb opens for the test on any of the three test dialects, so a count is taken at the same point on each. It is test-only and internal: production code and hosts never see it.
Index ¶
- type Counter
- func (c *Counter) Events() []Event
- func (c *Counter) FailMatching(fragment string, err error)
- func (c *Counter) FailNextRollback(err error)
- func (c *Counter) FailNthMatching(fragment string, n int, err error)
- func (c *Counter) Matching(fragment string) int
- func (c *Counter) Reset()
- func (c *Counter) RunBeforeMatching(fragment string, n int, fn func())
- func (c *Counter) Statements() []string
- type Event
- type Kind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter records each statement that reaches the driver, in order. Statements sent through a transaction count the same as any other.
func Attach ¶
Attach routes the database testdb opens for t through a recording driver and returns the Counter that records it. Statements are recorded from the moment testdb opens the database, so call Reset after any setup the test does not want counted.
func (*Counter) Events ¶
Events returns every statement and transaction boundary recorded so far, in the order the driver saw them. Statements is the statement subset of it.
func (*Counter) FailMatching ¶
FailMatching makes each later statement that contains fragment fail with err before it reaches the driver, and does not record it. It exists so a test can drive an error path that the database would not produce on its own.
func (*Counter) FailNextRollback ¶
FailNextRollback makes the next rollback the database is asked for roll the transaction back in the driver and then return err, so a test can drive the path where a deferred rollback fails. It is armed once.
func (*Counter) FailNthMatching ¶
FailNthMatching makes the nth later statement (1-based) that contains fragment fail with err before it reaches the driver, and lets every other statement through. It exists so a test can fail a later chunk of a read whose earlier chunks must succeed.
func (*Counter) Matching ¶
Matching returns how many recorded statements contain fragment as a literal substring. It does not interpret fragment as a pattern.
func (*Counter) RunBeforeMatching ¶
RunBeforeMatching calls fn once, just before the nth later statement (1-based) that contains fragment reaches the driver. fn runs on the statement's goroutine and may use another connection of the same database to change the data, so a test can commit a write between two statements of one read at a chosen point, without sleeping.
func (*Counter) Statements ¶
Statements returns the SQL text of each recorded statement, in order.
type Event ¶
type Event struct {
Kind Kind
Statement string
Isolation sql.IsolationLevel
ReadOnly bool
}
Event is one entry in the order the driver saw it. A statement event carries its SQL text. A begin event carries the isolation level and the read-only flag the transaction was opened with; the other kinds carry neither.
type Kind ¶
type Kind string
Kind says what an Event records.
const ( // KindStatement is a statement that reached the driver. KindStatement Kind = "statement" // KindBegin is a transaction the driver began. KindBegin Kind = "begin" // KindCommit is a transaction the driver was asked to commit. KindCommit Kind = "commit" // KindRollback is a transaction the driver was asked to roll back. KindRollback Kind = "rollback" )