adds test for commit failure check
All checks were successful
gitea-deepak/gogmagog/pipeline/head This commit looks good

This commit is contained in:
Deepak Mallubhotla 2020-12-29 19:16:13 -06:00
parent acf793ae41
commit 72e3fbe05b
Signed by: deepak
GPG Key ID: 64BF53A3369104E7

View File

@ -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) {
assert := assert.New(t)