Adds insert plan function
All checks were successful
gitea-deepak/gogmagog/pipeline/head This commit looks good

This commit is contained in:
2020-12-29 18:44:37 -06:00
parent 9c56ea56e2
commit 9f5f5413d1
2 changed files with 42 additions and 2 deletions

View File

@@ -68,6 +68,35 @@ func TestSelectPlanByID(t *testing.T) {
}
}
func TestInsertPlan(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(8)
mock.ExpectBegin()
mock.ExpectQuery("^INSERT INTO plans \\(plan_date\\) VALUES \\(\\$1\\) RETURNING plan_id$").
WithArgs(planDate).
WillReturnRows(rows)
mock.ExpectCommit()
// function under test
insertedId, err := str.InsertPlan(plan)
// check results
assert.Nil(err)
assert.EqualValues(idToUse, insertedId)
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("unfulfilled expectations: %s", err)
}
}
func TestErrPlanByID(t *testing.T) {
assert := assert.New(t)