diff --git a/store/postgres_test.go b/store/postgres_test.go index 90de7a7..7c1c5d2 100644 --- a/store/postgres_test.go +++ b/store/postgres_test.go @@ -97,6 +97,30 @@ func TestInsertPlan(t *testing.T) { } +func TestInsertPlanErr(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} + + mock.ExpectBegin() + mock.ExpectQuery("^INSERT INTO plans \\(plan_date\\) VALUES \\(\\$1\\) RETURNING plan_id$"). + WithArgs(planDate). + WillReturnError(fmt.Errorf("example error")) + mock.ExpectRollback() + + // 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)