3

I am using sqlmock to mock a Snowflake query execution. This may look strange, but for the following query:

rows, err = db.Query(sqlQuery)

I need the mock to return nil for both rows and err. Notice I want nil for rows not an empty set. Here is my function. I tried the statements in comments as well.

func mockSnowflake(t *testing.T, sqlQuery string) (*sql.DB, sqlmock.Sqlmock) {
    db, mock, err := sqlmock.New()
    // 5 is because I'll be calling db.Query() 5 times
    for i := 1; i <= 5; i++ {
        //mock.ExpectQuery(sqlQuery).WillReturnRows(sqlmock.NewRows(nil))
        //mock.ExpectQuery(sqlQuery).WillReturnRows(sqlmock.NewRows([]string {"Test Column"}).AddRow(nil))
        mock.ExpectQuery(sqlQuery).WillReturnRows(nil)
    }
    return db, mock
}

How should I change the function?

BlameMe
  • 61
  • 7
Goosal Tapal
  • 205
  • 1
  • 2
  • 5

0 Answers0