Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] [APM] API Snapshot Testing (#77229) #77322

Merged
merged 1 commit into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions x-pack/test/apm_api_integration/basic/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { FtrProviderContext } from '../../common/ftr_provider_context';
import { registerMochaHooksForSnapshots } from '../../common/match_snapshot';

export default function apmApiIntegrationTests({ loadTestFile }: FtrProviderContext) {
describe('APM specs (basic)', function () {
registerMochaHooksForSnapshots();

this.tags('ciGroup1');

loadTestFile(require.resolve('./feature_controls'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import expect from '@kbn/expect';
import { expectSnapshot } from '../../../common/match_snapshot';
import { FtrProviderContext } from '../../../common/ftr_provider_context';

export default function ApiTest({ getService }: FtrProviderContext) {
Expand All @@ -22,7 +23,12 @@ export default function ApiTest({ getService }: FtrProviderContext) {
`/api/apm/observability_overview?start=${start}&end=${end}&bucketSize=${bucketSize}`
);
expect(response.status).to.be(200);
expect(response.body).to.eql({ serviceCount: 0, transactionCoordinates: [] });
expectSnapshot(response.body).toMatchInline(`
Object {
"serviceCount": 0,
"transactionCoordinates": Array [],
}
`);
});
});
describe('when data is loaded', () => {
Expand All @@ -34,13 +40,21 @@ export default function ApiTest({ getService }: FtrProviderContext) {
`/api/apm/observability_overview?start=${start}&end=${end}&bucketSize=${bucketSize}`
);
expect(response.status).to.be(200);
expect(response.body).to.eql({
serviceCount: 3,
transactionCoordinates: [
{ x: 1593413220000, y: 0.016666666666666666 },
{ x: 1593413280000, y: 1.0458333333333334 },
],
});
expectSnapshot(response.body).toMatchInline(`
Object {
"serviceCount": 3,
"transactionCoordinates": Array [
Object {
"x": 1593413220000,
"y": 0.016666666666666666,
},
Object {
"x": 1593413280000,
"y": 1.0458333333333334,
},
],
}
`);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { sortBy } from 'lodash';
import expect from '@kbn/expect';
import { expectSnapshot } from '../../../common/match_snapshot';
import { FtrProviderContext } from '../../../common/ftr_provider_context';

export default function ApiTest({ getService }: FtrProviderContext) {
Expand Down Expand Up @@ -41,32 +42,38 @@ export default function ApiTest({ getService }: FtrProviderContext) {
const services = sortBy(response.body.items, ['serviceName']);

expect(response.status).to.be(200);
expect(services).to.eql([
{
serviceName: 'client',
agentName: 'rum-js',
transactionsPerMinute: 2,
errorsPerMinute: 2.75,
avgResponseTime: 116375,
environments: [],
},
{
serviceName: 'opbeans-java',
agentName: 'java',
transactionsPerMinute: 30.75,
errorsPerMinute: 4.5,
avgResponseTime: 25636.349593495936,
environments: ['production'],
},
{
serviceName: 'opbeans-node',
agentName: 'nodejs',
transactionsPerMinute: 31,
errorsPerMinute: 3.75,
avgResponseTime: 38682.52419354839,
environments: ['production'],
},
]);
expectSnapshot(services).toMatchInline(`
Array [
Object {
"agentName": "rum-js",
"avgResponseTime": 116375,
"environments": Array [],
"errorsPerMinute": 2.75,
"serviceName": "client",
"transactionsPerMinute": 2,
},
Object {
"agentName": "java",
"avgResponseTime": 25636.349593495936,
"environments": Array [
"production",
],
"errorsPerMinute": 4.5,
"serviceName": "opbeans-java",
"transactionsPerMinute": 30.75,
},
Object {
"agentName": "nodejs",
"avgResponseTime": 38682.52419354839,
"environments": Array [
"production",
],
"errorsPerMinute": 3.75,
"serviceName": "opbeans-node",
"transactionsPerMinute": 31,
},
]
`);

expect(response.body.hasHistoricalData).to.be(true);
expect(response.body.hasLegacyData).to.be(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import expect from '@kbn/expect';
import { expectSnapshot } from '../../../common/match_snapshot';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

export default function ApiTest({ getService }: FtrProviderContext) {
Expand All @@ -23,7 +24,8 @@ export default function ApiTest({ getService }: FtrProviderContext) {
);

expect(response.status).to.be(200);
expect(response.body).to.eql({ transactionTypes: [] });

expect(response.body.transactionTypes.length).to.be(0);
});
});

Expand All @@ -37,7 +39,14 @@ export default function ApiTest({ getService }: FtrProviderContext) {
);

expect(response.status).to.be(200);
expect(response.body).to.eql({ transactionTypes: ['request', 'Worker'] });
expectSnapshot(response.body).toMatchInline(`
Object {
"transactionTypes": Array [
"request",
"Worker",
],
}
`);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@ export default function apiTest({ getService }: FtrProviderContext) {
describe('when calling the endpoint for listing jobs', () => {
it('returns an error because the user does not have access', async () => {
const { body } = await getAnomalyDetectionJobs();
expect(body).to.eql({ statusCode: 404, error: 'Not Found', message: 'Not Found' });

expect(body.statusCode).to.be(404);
expect(body.error).to.be('Not Found');
});
});

describe('when calling create endpoint', () => {
it('returns an error because the user does not have access', async () => {
const { body } = await createAnomalyDetectionJobs(['production', 'staging']);
expect(body).to.eql({ statusCode: 404, error: 'Not Found', message: 'Not Found' });

expect(body.statusCode).to.be(404);
expect(body.error).to.be('Not Found');
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import expect from '@kbn/expect';
import { expectSnapshot } from '../../../../common/match_snapshot';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

export default function apiTest({ getService }: FtrProviderContext) {
Expand All @@ -25,19 +26,21 @@ export default function apiTest({ getService }: FtrProviderContext) {
describe('when calling the endpoint for listing jobs', () => {
it('returns an error because the user is on basic license', async () => {
const { body } = await getAnomalyDetectionJobs();
expect(body).to.eql({
statusCode: 403,
error: 'Forbidden',
message:
"To use anomaly detection, you must be subscribed to an Elastic Platinum license. With it, you'll be able to monitor your services with the aid of machine learning.",
});

expect(body.statusCode).to.be(403);
expect(body.error).to.be('Forbidden');

expectSnapshot(body.message).toMatchInline(
`"To use anomaly detection, you must be subscribed to an Elastic Platinum license. With it, you'll be able to monitor your services with the aid of machine learning."`
);
});
});

describe('when calling create endpoint', () => {
it('returns an error because the user does not have access', async () => {
const { body } = await createAnomalyDetectionJobs(['production', 'staging']);
expect(body).to.eql({ statusCode: 404, error: 'Not Found', message: 'Not Found' });
expect(body.statusCode).to.be(404);
expect(body.error).to.be('Not Found');
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import expect from '@kbn/expect';
import { expectSnapshot } from '../../../../common/match_snapshot';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

export default function apiTest({ getService }: FtrProviderContext) {
Expand All @@ -25,24 +26,25 @@ export default function apiTest({ getService }: FtrProviderContext) {
describe('when calling the endpoint for listing jobs', () => {
it('returns an error because the user is on basic license', async () => {
const { body } = await getAnomalyDetectionJobs();
expect(body).to.eql({
statusCode: 403,
error: 'Forbidden',
message:
"To use anomaly detection, you must be subscribed to an Elastic Platinum license. With it, you'll be able to monitor your services with the aid of machine learning.",
});

expect(body.statusCode).to.be(403);
expect(body.error).to.be('Forbidden');
expectSnapshot(body.message).toMatchInline(
`"To use anomaly detection, you must be subscribed to an Elastic Platinum license. With it, you'll be able to monitor your services with the aid of machine learning."`
);
});
});

describe('when calling create endpoint', () => {
it('returns an error because the user is on basic license', async () => {
const { body } = await createAnomalyDetectionJobs(['production', 'staging']);
expect(body).to.eql({
statusCode: 403,
error: 'Forbidden',
message:
"To use anomaly detection, you must be subscribed to an Elastic Platinum license. With it, you'll be able to monitor your services with the aid of machine learning.",
});

expect(body.statusCode).to.be(403);
expect(body.error).to.be('Forbidden');

expectSnapshot(body.message).toMatchInline(
`"To use anomaly detection, you must be subscribed to an Elastic Platinum license. With it, you'll be able to monitor your services with the aid of machine learning."`
);
});
});
});
Expand Down
Loading