0

I created mockrows for sql.rows. I referred this document to create mockrows https://github.com/DATA-DOG/go-sqlmock

I need to create mockrow for sql.row (i.e db.QueryRow). I am not able to find any suitable method in sql.mock.
Is there any way to mock QueryRow using sqlmock?

Shoba
  • 632
  • 1
  • 5
  • 11
  • Seems to me that you should use `sqlmock.Rows` with one row added to them when you want to test `QueryRow` (https://github.com/DATA-DOG/go-sqlmock/blob/e64ef33e8bdaf17d91e3ecb35b9c1d0e420b3309/expectations_test.go#L175-L176). Note that this resembles the behaviour of the `database/sql` package since `*sql.DB.QueryRow` delegates to `*sql.DB.Query` to do its job. – mkopriva Nov 20 '19 at 10:59
  • @mkopriva But QueryRow return type is *sql.row ; Query return type is *sql.rows.It throws type exception .. – Shoba Nov 20 '19 at 12:55
  • func mockRowsToSqlRows(mockRows sqlmock.Rows) *sql.Rows { db, mock, _ := sqlmock.New() mock.ExpectQuery("select").WillReturnRows(mockRows) rows, _ := db.Query("select") return rows } – Shoba Nov 20 '19 at 12:58
  • Please update the question and add the code where you're testing the QueryRow and also the code that results in the "type exception". Code in comments is unreadable. – mkopriva Nov 20 '19 at 13:00

0 Answers0