diff --git a/store/postgres_test.go b/store/postgres_test.go index 161eb1a..16e798e 100644 --- a/store/postgres_test.go +++ b/store/postgres_test.go @@ -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)