Skip to content

Commit

Permalink
Update latest_agent_versions test
Browse files Browse the repository at this point in the history
  • Loading branch information
crespocarlos committed Nov 4, 2024
1 parent 87fca74 commit 2393507
Showing 1 changed file with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,44 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import expect from '@kbn/expect';
import { ElasticApmAgentLatestVersion } from '@kbn/apm-plugin/common/agent_explorer';
import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context';

export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) {
const registry = getService('registry');
const apmApiClient = getService('apmApiClient');
const apmApi = getService('apmApi');

const nodeAgentName = 'nodejs';
const unlistedAgentName = 'unlistedAgent';

async function callApi() {
const apmApiClient = await apmApi.createApmApiClient();
return await apmApiClient.readUser({
endpoint: 'GET /internal/apm/get_latest_agent_versions',
});
}

registry.when(
'Agent latest versions when configuration is defined',
{ config: 'basic', archives: [] },
() => {
it('returns a version when agent is listed in the file', async () => {
const { status, body } = await callApi();
expect(status).to.be(200);
registry.when('Agent latest versions when configuration is defined', () => {
it('returns a version when agent is listed in the file', async () => {
const { status, body } = await callApi();
expect(status).to.be(200);

const agents = body.data;
const agents = body.data;

const nodeAgent = agents[nodeAgentName] as ElasticApmAgentLatestVersion;
expect(nodeAgent?.latest_version).not.to.be(undefined);
});
const nodeAgent = agents[nodeAgentName] as ElasticApmAgentLatestVersion;
expect(nodeAgent?.latest_version).not.to.be(undefined);
});

it('returns undefined when agent is not listed in the file', async () => {
const { status, body } = await callApi();
expect(status).to.be(200);
it('returns undefined when agent is not listed in the file', async () => {
const { status, body } = await callApi();
expect(status).to.be(200);

const agents = body.data;
const agents = body.data;

// @ts-ignore
const unlistedAgent = agents[unlistedAgentName] as ElasticApmAgentLatestVersion;
expect(unlistedAgent?.latest_version).to.be(undefined);
});
}
);
// @ts-ignore
const unlistedAgent = agents[unlistedAgentName] as ElasticApmAgentLatestVersion;
expect(unlistedAgent?.latest_version).to.be(undefined);
});
});
}

0 comments on commit 2393507

Please sign in to comment.