You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func (r*Repository) Index() ([]Mystruct, error) {
rows, _:=r.database.Query("SELECT * FROM table WHERE start_at >= NOW()")
forrows.Next() {} // never enter the loop because the result is empty
}
The text was updated successfully, but these errors were encountered:
@rmulley i overwrite the database when i create a New Repository, here's the code from NewRepository
typeRepositorystruct {
database*sql.DB
}
funcNewRepository(db*sql.DB) Repository {
returnRepository{database: db}
}
func (rRepository) Index() ([]Mystruct, error) {
rows, _:=r.database.Query("SELECT * FROM table WHERE start_at >= NOW()")
forrows.Next() {} // never enter the loop because the result is empty
}
So when i Setup the test:
func (suite*RepositoryTestSuit) SetupSuite() {
db, mock, _:=sqlmock.New()
suite.mock=mocksuite.database=dbsuite.repository=NewRepository(db) // <- passes the database to the repository
}
It is possible to filter a row within the mocked rows? When i try to perform a query the result is always empty.
The repository:
The text was updated successfully, but these errors were encountered: