Documentation
¶
Index ¶
- func Begin(t testing.TB, db *sql.DB) *sql.Tx
- func DB(conninfo ...string) (*sql.DB, error)
- func DSN(conninfo string) string
- func ErrorContains(have error, want string) bool
- func Exec(t testing.TB, db interface{ ... }, q string, args ...any)
- func ForceBinaryParameters() bool
- func InvalidCertificate(err error) bool
- func MustDB(t testing.TB, conninfo ...string) *sql.DB
- func NormalizeIndent(in string) string
- func Pgbouncer() bool
- func Pgpool() bool
- func Prepare(t testing.TB, db interface{ ... }, q string) *sql.Stmt
- func Ptr[T any](t T) *T
- func Query[T any](t testing.TB, db interface{ ... }, q string, args ...any) []map[string]T
- func Read(t *testing.T, paths ...string) []byte
- func SkipPgbouncer(t testing.TB)
- func SkipPgpool(t testing.TB)
- func TempFile(t *testing.T, name, data string) string
- type Fake
- func (f Fake) Close()
- func (f Fake) DSN() string
- func (f Fake) Host() string
- func (f Fake) Port() string
- func (f Fake) ReadMsg(cn net.Conn) (proto.RequestCode, []byte, bool)
- func (f Fake) ReadStartup(cn net.Conn) (map[string]string, bool)
- func (f Fake) SimpleQuery(cn net.Conn, tag string, values ...any)
- func (f Fake) Startup(cn net.Conn, params map[string]string)
- func (f Fake) WriteMsg(cn net.Conn, code proto.ResponseCode, msg string)
- func (f Fake) WriteStartup(cn net.Conn, params map[string]string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorContains ¶
ErrorContains checks if the error message in have contains the text in want.
This is safe when have is nil. Use an empty string for want if you want to test that err is nil.
func Exec ¶
func Exec(t testing.TB, db interface { Exec(string, ...any) (sql.Result, error) }, q string, args ...any)
Exec calls db.Exec(), calling t.Fatal if this fails.
func ForceBinaryParameters ¶
func ForceBinaryParameters() bool
func InvalidCertificate ¶
InvalidCertificate reports if this error is an "invalid certificate" error.
func MustDB ¶
MustDB connects to the test database, calling t.Fatal() if this fails. The connection is closed in t.Cleanup().
func NormalizeIndent ¶
NormalizeIndent removes tab indentation from every line.
This is useful for "inline" multiline strings:
cases := []struct {
string in
}{
`
Hello,
world!
`,
}
This is nice and readable, but the downside is that every line will now have two extra tabs. This will remove those two tabs from every line.
The amount of tabs to remove is based only on the first line, any further tabs will be preserved.
func Ptr ¶ added in v1.11.1
func Ptr[T any](t T) *T
Ptr gets a pointer to any value.
TODO: replace with new(..) once pq requires Go 1.26.
func Query ¶
func Query[T any](t testing.TB, db interface { Query(string, ...any) (*sql.Rows, error) }, q string, args ...any) []map[string]T
Query calls db.Query(), calling t.Fatal if this fails.
The resulting rows are scanned to the type T.
func SkipPgbouncer ¶
func SkipPgpool ¶
Types ¶
type Fake ¶
type Fake struct {
// contains filtered or unexported fields
}
func NewFake ¶
NewFake creates a new "fake" PostgreSQL server. You need to accept connections with [Fake.Accept].
This can also be tested against libpq with something like:
f := pqtest.NewFake(t)
f.Accept(..)
fmt.Println("\n" + f.DSN())
time.Sleep(9 * time.Minute)
func (Fake) ReadStartup ¶
ReadStartup reads the startup message.
func (Fake) SimpleQuery ¶
SimpleQuery responds to a simpleQuery workflow; values are as a col, value pair:
f.SimpleQuery(cn, "SELECT", "colname", "val", "int", 2)
Currently only supports string, int, and bool for values
func (Fake) Startup ¶
Startup reads the startup message from the server with [f.ReadStartup] and sends proto.AuthenticationRequest and proto.ReadyForQuery.