Skip to content

Commit

Permalink
Fix condition and adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jen-huang committed Sep 30, 2020
1 parent 4b578eb commit 676ce45
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ describe('test agent checkin new action services', () => {
expect(
await createAgentActionFromPolicyAction(
mockSavedObjectsClient,
{ ...mockAgent, local_metadata: { elastic: { agent: { version: '7.10.1-SNAPSHOT' } } } },
{ ...mockAgent, local_metadata: { elastic: { agent: { version: '7.10.0-SNAPSHOT' } } } },
mockPolicyAction
)
).toEqual(expectedResult);

expect(
await createAgentActionFromPolicyAction(
mockSavedObjectsClient,
{ ...mockAgent, local_metadata: { elastic: { agent: { version: '7.10.2' } } } },
mockPolicyAction
)
).toEqual(expectedResult);
Expand Down Expand Up @@ -131,15 +139,15 @@ describe('test agent checkin new action services', () => {
expect(
await createAgentActionFromPolicyAction(
mockSavedObjectsClient,
{ ...mockAgent, local_metadata: { elastic: { agent: { version: '7.9.1-SNAPSHOT' } } } },
{ ...mockAgent, local_metadata: { elastic: { agent: { version: '7.9.3' } } } },
mockPolicyAction
)
).toEqual(expectedResult);

expect(
await createAgentActionFromPolicyAction(
mockSavedObjectsClient,
{ ...mockAgent, local_metadata: { elastic: { agent: { version: '7.9.3' } } } },
{ ...mockAgent, local_metadata: { elastic: { agent: { version: '7.9.1-SNAPSHOT' } } } },
mockPolicyAction
)
).toEqual(expectedResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,21 @@ export async function createAgentActionFromPolicyAction(
agent: Agent,
policyAction: AgentPolicyAction
) {
// Transform the policy action for agent version <= 7.9 for BWC
// Transform the policy action for agent version <= 7.9.x for BWC
const agentVersion = semver.parse((agent.local_metadata?.elastic as any)?.agent?.version);
const agentPolicyAction: AgentPolicyAction | AgentPolicyActionV7_9 =
agentVersion && semver.lt(agentVersion, '7.10.0')
agentVersion &&
semver.lt(
agentVersion,
// A prerelease tag is added here so that agent versions with prerelease tags can be compared
// correctly using `semvar`
'7.10.0-SNAPSHOT',
// `@types/semvar` is out of date with the version of `semvar` we use and doesn't have a
// corresponding release version we can update the typing to :( so, the typing error is
// suppressed here even though it is supported by `semvar`
// @ts-expect-error
{ includePrerelease: true }
)
? {
...policyAction,
type: 'CONFIG_CHANGE',
Expand Down

0 comments on commit 676ce45

Please sign in to comment.