Documentation
¶
Overview ¶
Package pgstandin gives the tests of this module a PostgreSQL database that has no server: a real *dalgo2postgres.Database whose connection pool lost its server, so that every call that needs a connection fails the way a read fails when the server was restarted, the password was changed or the connection limit was reached: with the adapter's own connection error, a fixed sentence that holds nothing of the configuration (dalgo2postgres v0.6.0 and later; before it the call failed with the text pgx writes, which names the user). A test of a command, a route or a chat puts it behind the opener of PostgreSQL databases and looks for a marker in the user name and the password in everything the code under test printed, answered or logged.
Nothing is dialled: the one connection the database is opened with runs over an in-memory pipe against a few lines of the protocol, and every later dial fails. Test code only: nothing in this module's binaries imports it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Unreachable ¶
func Unreachable(tb testing.TB, user, password string, keyedTables ...string) *dalgo2postgres.Database
Unreachable opens a *dalgo2postgres.Database as the user, with the password, against an in-memory server that answers the one connection the adapter verifies the source with, and then goes away for good. It uses the exact identifier mode, as BackendRef does, and declares no recordset, as BackendRef does; a test of a call that reads or writes a record by its key names the tables it needs declared (each keyed by a column "id"), because without a declaration those calls fail before they reach a connection. The database is closed when the test ends.
Types ¶
type Recorder ¶ added in v0.60.0
type Recorder struct {
// contains filtered or unexported fields
}
Recorder keeps the text of every statement that the in-memory servers of one Recording were sent, in the order they arrived. The statement the driver verifies a connection with is not one of them.
func Recording ¶ added in v0.60.0
func Recording(tb testing.TB, accept bool, keyedTables ...string) (*dalgo2postgres.Database, *Recorder)
Recording opens a *dalgo2postgres.Database as BackendRef does (the exact identifier mode), against in-memory servers that record each statement they are sent. A server answers a statement with success when accept is true, and with an error of the server's own kind (SQLSTATE XX000, so not a connection failure) when it is false: the second is a handle that fails on any statement, and a call that returns another error did not reach one. Only the simple protocol is spoken; a statement sent in the extended protocol, which a call with parameters does, is answered with an error and not recorded. The database is closed when the test ends. keyedTables are declared as in Unreachable.
Nothing is dialled: every connection of the pool is an in-memory pipe, and the pool makes as many as it needs.
func (*Recorder) Statements ¶ added in v0.60.0
Statements returns the statements recorded so far, a copy.