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

Function ExampleRows_expectToBeClosed

rows_test.go:141–162  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

139}
140
141func ExampleRows_expectToBeClosed() {
142 db, mock, err := New()
143 if err != nil {
144 fmt.Println("failed to open sqlmock database:", err)
145 }
146 defer db.Close()
147
148 rows := NewRows([]string{"id", "title"}).AddRow(1, "john")
149 mock.ExpectQuery("SELECT").WillReturnRows(rows).RowsWillBeClosed()
150
151 db.Query("SELECT")
152
153 if err := mock.ExpectationsWereMet(); err != nil {
154 fmt.Println("got error:", err)
155 }
156
157 // Output: got error: expected query rows to be closed, but it was not: ExpectedQuery => expecting Query, QueryContext or QueryRow which:
158 // - matches sql: 'SELECT'
159 // - is without arguments
160 // - should return rows:
161 // row 0 - [1 john]
162}
163
164func ExampleRows_customDriverValue() {
165 db, mock, err := New()

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…