Skip to content

Commit

Permalink
chore(install): refactor to use InstallComplete with optional error
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien4218 committed Apr 8, 2021
1 parent 99899ff commit aa76b9d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
24 changes: 10 additions & 14 deletions internal/install/execution/install_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,8 @@ func (s *InstallStatus) RecipeSkipped(event RecipeStatusEvent) {
}
}

func (s *InstallStatus) InstallError(err error) {
statusError := StatusError{
Message: "unknown error",
}
if err != nil {
statusError.Message = err.Error()
}
s.Error = statusError
s.InstallComplete()
}

func (s *InstallStatus) InstallComplete() {
s.completed()
func (s *InstallStatus) InstallComplete(err error) {
s.completed(err)

for _, r := range s.statusSubscriber {
if err := r.InstallComplete(s); err != nil {
Expand Down Expand Up @@ -355,10 +344,17 @@ func (s *InstallStatus) withRecipeEvent(e RecipeStatusEvent, rs RecipeStatusType
s.Timestamp = utils.GetTimestamp()
}

func (s *InstallStatus) completed() {
func (s *InstallStatus) completed(err error) {
s.Complete = true
s.Timestamp = utils.GetTimestamp()

if err != nil {
statusError := StatusError{
Message: err.Error(),
}
s.Error = statusError
}

log.WithFields(log.Fields{
"timestamp": s.Timestamp,
}).Debug("completed")
Expand Down
4 changes: 2 additions & 2 deletions internal/install/execution/install_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func TestInstallStatus_statusUpdateMethods(t *testing.T) {
require.Equal(t, result.Status, RecipeStatusTypes.SKIPPED)
require.False(t, s.hasFailed())

s.InstallComplete()
s.InstallComplete(nil)
require.True(t, s.Complete)
require.NotNil(t, s.Timestamp)
}
Expand All @@ -159,7 +159,7 @@ func TestInstallStatus_failAvailableOnComplete(t *testing.T) {

s.RecipesAvailable([]types.Recipe{r})

s.InstallComplete()
s.InstallComplete(nil)
require.Equal(t, RecipeStatusTypes.FAILED, s.Statuses[0].Status)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/install/recipe_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (i *RecipeInstaller) Install() error {
return err
}

i.status.InstallError(err)
i.status.InstallComplete(err)

return err
}
Expand Down

0 comments on commit aa76b9d

Please sign in to comment.