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))
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))