MCPcopy Create free account
hub / github.com/DATA-DOG/go-sqlmock / TestQuerySingleRow

Function TestQuerySingleRow

rows_test.go:285–311  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

283}
284
285func TestQuerySingleRow(t *testing.T) {
286 t.Parallel()
287 db, mock, err := New()
288 if err != nil {
289 t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
290 }
291 defer db.Close()
292
293 rows := NewRows([]string{"id"}).
294 AddRow(1).
295 AddRow(2)
296 mock.ExpectQuery("SELECT").WillReturnRows(rows)
297
298 var id int
299 if err := db.QueryRow("SELECT").Scan(&id); err != nil {
300 t.Fatalf("unexpected error: %s", err)
301 }
302
303 mock.ExpectQuery("SELECT").WillReturnRows(NewRows([]string{"id"}))
304 if err := db.QueryRow("SELECT").Scan(&id); err != sql.ErrNoRows {
305 t.Fatal("expected sql no rows error")
306 }
307
308 if err := mock.ExpectationsWereMet(); err != nil {
309 t.Fatal(err)
310 }
311}
312
313func TestQueryRowBytesInvalidatedByNext_bytesIntoRawBytes(t *testing.T) {
314 t.Parallel()

Callers

nothing calls this directly

Calls 8

NewFunction · 0.85
NewRowsFunction · 0.85
AddRowMethod · 0.80
ExpectQueryMethod · 0.65
ExpectationsWereMetMethod · 0.65
CloseMethod · 0.45
WillReturnRowsMethod · 0.45
ScanMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…