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
if err != nil {
return err, 0
}
var id int64
err = stmt.Get(&id, payload)
if err != nil {
return err, 0
}
type service struct {
Connection *sqlx.DB
Service
}
--Service interface
type Service interface {
Query(query string) (*sql.Rows, error)
PrepareNamed(query string) (*sqlx.NamedStmt, error)
}
`
Error at PrepareNamed as Nil pointer dereference
Test that I have written . Mock.ExpectBegin() requestRow := sqlmock.NewRows([]string{"id"}) requestRow.AddRow(1) Mock.ExpectPrepare("INSERT INTO sample (.+)").ExpectQuery(). WillReturnRows(requestRow) shared_services.Mock.ExpectExec("INSERT INTO sample (.*)").WithArgs( "TEST", "TEST").WillReturnResult(sqlmock.NewResult(100, 1))
The text was updated successfully, but these errors were encountered:
jayant42
changed the title
Issue with mocking
Issue with mocking PrepareNamed
Apr 10, 2024
How can i mock below.
stmt, err := Service.PrepareNamed(
INSERT INTO sample (right_id,created_by)VALUES (:right_id,:created_by) returning id`)
type service struct {
Connection *sqlx.DB
Service
}
--Service interface
type Service interface {
Query(query string) (*sql.Rows, error)
PrepareNamed(query string) (*sqlx.NamedStmt, error)
}
`
Error at PrepareNamed as Nil pointer dereference
Test that I have written
. Mock.ExpectBegin() requestRow := sqlmock.NewRows([]string{"id"}) requestRow.AddRow(1) Mock.ExpectPrepare("INSERT INTO sample (.+)").ExpectQuery(). WillReturnRows(requestRow) shared_services.Mock.ExpectExec("INSERT INTO sample (.*)").WithArgs( "TEST", "TEST").WillReturnResult(sqlmock.NewResult(100, 1))
The text was updated successfully, but these errors were encountered: