Add select by action id

This commit is contained in:
2020-12-29 16:08:31 -06:00
parent 50bbcdc71d
commit ad47895597
5 changed files with 89 additions and 4 deletions

View File

@@ -95,6 +95,55 @@ func TestSelectActions(t *testing.T) {
}
}
func TestSelectActionById(t *testing.T) {
// set up test
assert := assert.New(t)
createTime, _ := time.Parse("2006-01-02", "2020-12-31")
updateTime, _ := time.Parse("2006-01-02", "2021-01-01")
completeTime, _ := time.Parse("2006-01-02", "2021-01-05")
idToUse := 1
estChunks := 5
compChunks := 7
desc := "Howdy, partner."
str, mock := getDbMock(t)
rows := sqlmock.NewRows([]string{
"action_id",
"action_description",
"estimated_chunks",
"completed_chunks",
"completed_on",
"created_at",
"updated_at",
"plan_id"}).
AddRow(idToUse, desc, estChunks, compChunks, completeTime, createTime, updateTime, idToUse)
mock.ExpectQuery("^SELECT action_id, action_description, estimated_chunks, completed_chunks, completed_on, created_at, updated_at, plan_id FROM actions WHERE action_id = \\?").
WithArgs(1).
WillReturnRows(rows)
// function under test
action, err := str.SelectActionByID(1)
// test results
assert.Nil(err)
assert.EqualValues(idToUse, action.ActionID)
assert.Equal(desc, action.ActionDescription)
assert.Equal(estChunks, action.EstimatedChunks)
assert.Equal(compChunks, action.CompletedChunks)
assert.Equal(completeTime, action.CompletedOn)
assert.Equal(createTime, action.CreatedAt)
assert.Equal(updateTime, action.UpdatedAt)
assert.Equal(idToUse, action.PlanID)
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("unfulfilled expectations: %s", err)
}
}
func TestErrPlans(t *testing.T) {
// set up tests
assert := assert.New(t)
@@ -126,3 +175,19 @@ func TestErrActions(t *testing.T) {
t.Errorf("unfulfilled expectations: %s", err)
}
}
func TestErrActionByID(t *testing.T) {
// set up tests
assert := assert.New(t)
str, mock := getDbMock(t)
mock.ExpectQuery("^SELECT action_id, action_description, estimated_chunks, completed_chunks, completed_on, created_at, updated_at, plan_id FROM actions WHERE action_id = \\?").WillReturnError(fmt.Errorf("example error"))
// function under test
action, err := str.SelectActionByID(1)
// test results
assert.Nil(action)
assert.NotNil(err)
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("unfulfilled expectations: %s", err)
}
}