adds test for errors in update
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:
parent
bc68115ce1
commit
395231e1bf
@ -534,3 +534,67 @@ func TestUpdateAction(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
func TestUpdateActionErr(t *testing.T) {
|
||||
// setup
|
||||
assert := assert.New(t)
|
||||
|
||||
str, mock := getDbMock(t)
|
||||
completedOn, _ := time.Parse("2006-01-02", "2021-01-01")
|
||||
action := &models.Action{
|
||||
CompletedOn: &completedOn,
|
||||
EstimatedChunks: 3,
|
||||
CompletedChunks: 6,
|
||||
PlanID: 5,
|
||||
ActionDescription: "testing",
|
||||
ActionID: 2,
|
||||
}
|
||||
|
||||
mock.ExpectBegin()
|
||||
mock.ExpectExec("UPDATE actions").
|
||||
WithArgs("testing", 3, 6, completedOn, 5, 2).
|
||||
WillReturnError(fmt.Errorf("example error"))
|
||||
mock.ExpectRollback()
|
||||
|
||||
// function under test
|
||||
err := str.UpdateAction(action)
|
||||
// check results
|
||||
assert.NotNil(err)
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("unfulfilled expectations: %s", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestUpdateActionCommitErr(t *testing.T) {
|
||||
// setup
|
||||
assert := assert.New(t)
|
||||
|
||||
str, mock := getDbMock(t)
|
||||
completedOn, _ := time.Parse("2006-01-02", "2021-01-01")
|
||||
action := &models.Action{
|
||||
CompletedOn: &completedOn,
|
||||
EstimatedChunks: 3,
|
||||
CompletedChunks: 6,
|
||||
PlanID: 5,
|
||||
ActionDescription: "testing",
|
||||
ActionID: 2,
|
||||
}
|
||||
|
||||
|
||||
mock.ExpectBegin()
|
||||
mock.ExpectExec("UPDATE actions").
|
||||
WithArgs("testing", 3, 6, completedOn, 5, 2).
|
||||
WillReturnResult(sqlmock.NewResult(1, 1))
|
||||
mock.ExpectCommit().WillReturnError(fmt.Errorf("another error example"))
|
||||
|
||||
// function under test
|
||||
err := str.UpdateAction(action)
|
||||
// check results
|
||||
assert.NotNil(err)
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("unfulfilled expectations: %s", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user