Skip to content

Commit

Permalink
When state is set to something other than StateFailed, clear related …
Browse files Browse the repository at this point in the history
…metadata fields (#3690)
  • Loading branch information
ycombinator authored Nov 6, 2023
1 parent dba2166 commit e9be070
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/pkg/agent/application/upgrade/details/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ func (d *Details) SetState(s State) {
defer d.mu.Unlock()

d.State = s

// If State is something other than StateFailed, make sure to clear
// Metadata.FailedState and Metadata.ErrorMsg as those two fields
// should be set when State is set to StateFailed. See the Fail method.
if s != StateFailed {
d.Metadata.ErrorMsg = ""
d.Metadata.FailedState = ""
}

d.notifyObservers()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ func TestDetailsFail(t *testing.T) {
require.Equal(t, StateFailed, det.State)
require.Equal(t, StateRequested, det.Metadata.FailedState)
require.Equal(t, err.Error(), det.Metadata.ErrorMsg)

// Check that resetting state to something other than StateFailed
// clears Metadata.FailedState and Metadata.ErrorMsg
det.SetState(StateDownloading)
require.Equal(t, State(""), det.Metadata.FailedState)
require.Equal(t, "", det.Metadata.ErrorMsg)
}

func TestDetailsObserver(t *testing.T) {
Expand Down

0 comments on commit e9be070

Please sign in to comment.