diff --git a/pkg/control/v2/server/server_test.go b/pkg/control/v2/server/server_test.go index 642124bd27d..36177c3be26 100644 --- a/pkg/control/v2/server/server_test.go +++ b/pkg/control/v2/server/server_test.go @@ -14,6 +14,7 @@ import ( "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator" "github.com/elastic/elastic-agent/internal/pkg/agent/application/info" + "github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/details" "github.com/elastic/elastic-agent/pkg/component" "github.com/elastic/elastic-agent/pkg/component/runtime" "github.com/elastic/elastic-agent/pkg/control/v2/cproto" @@ -22,11 +23,12 @@ import ( func TestStateMapping(t *testing.T) { testcases := []struct { - name string - agentState cproto.State - agentMessage string - fleetState cproto.State - fleetMessage string + name string + agentState cproto.State + agentMessage string + fleetState cproto.State + fleetMessage string + upgradeDetails *details.Details }{ { name: "waiting first checkin response", @@ -49,6 +51,21 @@ func TestStateMapping(t *testing.T) { fleetState: cproto.State_FAILED, fleetMessage: "", }, + { + name: "with upgrade details", + agentState: cproto.State_UPGRADING, + agentMessage: "Upgrading to version 8.13.0", + fleetState: cproto.State_STOPPED, + fleetMessage: "Not enrolled into Fleet", + upgradeDetails: &details.Details{ + TargetVersion: "8.13.0", + State: details.StateDownloading, + ActionID: "", + Metadata: details.DetailsMetadata{ + DownloadPercent: 1.7, + }, + }, + }, } for _, tc := range testcases { @@ -101,6 +118,15 @@ func TestStateMapping(t *testing.T) { }, } + if tc.upgradeDetails != nil { + inputState.UpgradeDetails = &details.Details{ + TargetVersion: tc.upgradeDetails.TargetVersion, + State: tc.upgradeDetails.State, + ActionID: tc.upgradeDetails.ActionID, + Metadata: tc.upgradeDetails.Metadata, + } + } + agentInfo := new(info.AgentInfo) stateResponse, err := stateToProto(inputState, agentInfo) @@ -134,7 +160,18 @@ func TestStateMapping(t *testing.T) { assert.Equal(t, expectedCompState, stateResponse.Components[0]) } + if tc.upgradeDetails != nil { + expectedMetadata := &cproto.UpgradeDetailsMetadata{ + ScheduledAt: tc.upgradeDetails.Metadata.ScheduledAt, + DownloadPercent: float32(tc.upgradeDetails.Metadata.DownloadPercent), + FailedState: string(tc.upgradeDetails.Metadata.FailedState), + ErrorMsg: tc.upgradeDetails.Metadata.ErrorMsg, + } + assert.Equal(t, string(tc.upgradeDetails.State), stateResponse.UpgradeDetails.State) + assert.Equal(t, tc.upgradeDetails.TargetVersion, stateResponse.UpgradeDetails.TargetVersion) + assert.Equal(t, tc.upgradeDetails.ActionID, stateResponse.UpgradeDetails.ActionId) + assert.Equal(t, expectedMetadata, stateResponse.UpgradeDetails.Metadata) + } }) } - }