Skip to content

Commit 6e3ebbc

Browse files
committed
fixup! WIP - Add Upgrader unit tests
1 parent 9a1b42b commit 6e3ebbc

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

internal/pkg/agent/application/upgrade/upgrade.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ var (
6161
ErrUpgradeSameVersion = errors.New("upgrade did not occur because it is the same version")
6262
ErrNonFipsToFips = errors.New("cannot switch to fips mode when upgrading")
6363
ErrFipsToNonFips = errors.New("cannot switch to non-fips mode when upgrading")
64+
ErrNilUpdateMarker = errors.New("loaded a nil update marker")
6465
)
6566

6667
func init() {
@@ -443,6 +444,11 @@ func (u *Upgrader) PersistManualRollback(ctx context.Context, topDir string) err
443444
if err != nil {
444445
return fmt.Errorf("loading marker: %w", err)
445446
}
447+
448+
if updateMarker == nil {
449+
return ErrNilUpdateMarker
450+
}
451+
446452
updateMarker.DesiredOutcome = OUTCOME_ROLLBACK
447453
err = SaveMarker(paths.Data(), updateMarker, true)
448454
if err != nil {

internal/pkg/agent/application/upgrade/upgrade_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/elastic/elastic-agent/pkg/core/logger"
3434
"github.com/elastic/elastic-agent/pkg/core/logger/loggertest"
3535
infomocks "github.com/elastic/elastic-agent/testing/mocks/internal_/pkg/agent/application/info"
36+
upgrademocks "github.com/elastic/elastic-agent/testing/mocks/internal_/pkg/agent/application/upgrade"
3637
ackermocks "github.com/elastic/elastic-agent/testing/mocks/internal_/pkg/fleetapi/acker"
3738
clientmocks "github.com/elastic/elastic-agent/testing/mocks/pkg/control/v2/client"
3839
)
@@ -1035,7 +1036,7 @@ func TestIsSameReleaseVersion(t *testing.T) {
10351036
func TestManualRollback(t *testing.T) {
10361037
log, _ := loggertest.New(t.Name())
10371038
mockAgentInfo := infomocks.NewAgent(t)
1038-
upgrader, err := NewUpgrader(log, &artifact.Config{}, &configuration.UpgradeConfig{}, mockAgentInfo, new(AgentWatcherHelper))
1039+
upgrader, err := NewUpgrader(log, &artifact.Config{}, &configuration.UpgradeConfig{}, mockAgentInfo, upgrademocks.NewWatcherHelper(t))
10391040
require.NoError(t, err, "error creating upgrader")
10401041

10411042
upgrader.Upgrade(t.Context(), "", true, "", nil, nil, true, false)

0 commit comments

Comments
 (0)