Fix condition and adjust tests (#78898)

(cherry picked from commit 676ce45993)
This commit is contained in:
Jen Huang 2020-09-30 01:30:32 -07:00 committed by GitHub
parent a31dd64778
commit f6be7dc2f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 5 deletions

View file

@ -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);
@ -131,7 +139,7 @@ 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);
@ -139,7 +147,7 @@ describe('test agent checkin new action services', () => {
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);

View file

@ -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',