adds test for commit failure check
All checks were successful
gitea-deepak/gogmagog/pipeline/head This commit looks good
All checks were successful
gitea-deepak/gogmagog/pipeline/head This commit looks good
This commit is contained in:
parent
acf793ae41
commit
72e3fbe05b
@ -121,6 +121,34 @@ func TestInsertPlanErr(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInsertPlanCommitErr(t *testing.T) {
|
||||||
|
// setup
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
str, mock := getDbMock(t)
|
||||||
|
planDate, _ := time.Parse("2006-01-02", "2021-01-01")
|
||||||
|
plan := &models.Plan{PlanDate: planDate}
|
||||||
|
|
||||||
|
idToUse := 8
|
||||||
|
|
||||||
|
rows := sqlmock.NewRows([]string{"plan_id"}).AddRow(idToUse)
|
||||||
|
|
||||||
|
mock.ExpectBegin()
|
||||||
|
mock.ExpectQuery("^INSERT INTO plans \\(plan_date\\) VALUES \\(\\$1\\) RETURNING plan_id$").
|
||||||
|
WithArgs(planDate).
|
||||||
|
WillReturnRows(rows)
|
||||||
|
mock.ExpectCommit().WillReturnError(fmt.Errorf("another error example"))
|
||||||
|
|
||||||
|
// function under test
|
||||||
|
_, err := str.InsertPlan(plan)
|
||||||
|
// check results
|
||||||
|
assert.NotNil(err)
|
||||||
|
if err := mock.ExpectationsWereMet(); err != nil {
|
||||||
|
t.Errorf("unfulfilled expectations: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func TestErrPlanByID(t *testing.T) {
|
func TestErrPlanByID(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user