Do a simple query to ensure the DB is still usable. This is of less use in stdlib as the connection pool should cover broken connections.
(t testing.TB, db *sql.DB)
| 113 | // Do a simple query to ensure the DB is still usable. This is of less use in stdlib as the connection pool should |
| 114 | // cover broken connections. |
| 115 | func ensureDBValid(t testing.TB, db *sql.DB) { |
| 116 | var sum, rowCount int32 |
| 117 | |
| 118 | rows, err := db.Query("select generate_series(1,$1)", 10) |
| 119 | require.NoError(t, err) |
| 120 | defer rows.Close() |
| 121 | |
| 122 | for rows.Next() { |
| 123 | var n int32 |
| 124 | rows.Scan(&n) |
| 125 | sum += n |
| 126 | rowCount++ |
| 127 | } |
| 128 | |
| 129 | require.NoError(t, rows.Err()) |
| 130 | |
| 131 | if rowCount != 10 { |
| 132 | t.Error("Select called onDataRow wrong number of times") |
| 133 | } |
| 134 | if sum != 55 { |
| 135 | t.Error("Wrong values returned") |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | type preparer interface { |
| 140 | Prepare(query string) (*sql.Stmt, error) |
no test coverage detected