From aa76b9dac70628f3bb0a17aab1eb03b37a217317 Mon Sep 17 00:00:00 2001 From: Julien Erard Date: Thu, 8 Apr 2021 09:36:56 -0700 Subject: [PATCH] chore(install): refactor to use InstallComplete with optional error --- internal/install/execution/install_status.go | 24 ++++++++----------- .../install/execution/install_status_test.go | 4 ++-- internal/install/recipe_installer.go | 2 +- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/internal/install/execution/install_status.go b/internal/install/execution/install_status.go index f5bfd52c4..379789788 100644 --- a/internal/install/execution/install_status.go +++ b/internal/install/execution/install_status.go @@ -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 { @@ -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") diff --git a/internal/install/execution/install_status_test.go b/internal/install/execution/install_status_test.go index cbefb11be..005e5f9fc 100644 --- a/internal/install/execution/install_status_test.go +++ b/internal/install/execution/install_status_test.go @@ -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) } @@ -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) } diff --git a/internal/install/recipe_installer.go b/internal/install/recipe_installer.go index 24b2927d4..0d8c0d1f6 100644 --- a/internal/install/recipe_installer.go +++ b/internal/install/recipe_installer.go @@ -115,7 +115,7 @@ func (i *RecipeInstaller) Install() error { return err } - i.status.InstallError(err) + i.status.InstallComplete(err) return err }