added select plan by id
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:
@@ -47,6 +47,45 @@ func TestSelectPlans(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectPlanByID(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
currentTime := time.Now()
|
||||
idToUse := 1
|
||||
|
||||
str, mock := getDbMock(t)
|
||||
|
||||
rows := sqlmock.NewRows([]string{"plan_id", "plan_date"}).AddRow(idToUse, currentTime)
|
||||
mock.ExpectQuery("^SELECT plan_id, plan_date FROM plans WHERE plan_id = \\$1$").WithArgs(idToUse).WillReturnRows(rows)
|
||||
|
||||
plan, err := str.SelectPlanByID(idToUse)
|
||||
assert.Nil(err)
|
||||
assert.EqualValues(idToUse, plan.PlanID)
|
||||
assert.Equal(currentTime, plan.PlanDate)
|
||||
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("unfulfilled expectations: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestErrPlanByID(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
idToUse := 1
|
||||
|
||||
str, mock := getDbMock(t)
|
||||
|
||||
mock.ExpectQuery("^SELECT plan_id, plan_date FROM plans WHERE plan_id = \\$1$").WithArgs(idToUse).WillReturnError(fmt.Errorf("example error"))
|
||||
|
||||
plan, err := str.SelectPlanByID(idToUse)
|
||||
assert.NotNil(err)
|
||||
assert.Nil(plan)
|
||||
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("unfulfilled expectations: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectActions(t *testing.T) {
|
||||
// set up test
|
||||
assert := assert.New(t)
|
||||
|
||||
Reference in New Issue
Block a user