Skip to content

Commit 8a898fe

Browse files
authored
[APM] API Snapshot Testing (#77229)
1 parent 4126ef6 commit 8a898fe

31 files changed

+10550
-12263
lines changed

x-pack/test/apm_api_integration/basic/tests/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66
import { FtrProviderContext } from '../../common/ftr_provider_context';
7+
import { registerMochaHooksForSnapshots } from '../../common/match_snapshot';
78

89
export default function apmApiIntegrationTests({ loadTestFile }: FtrProviderContext) {
910
describe('APM specs (basic)', function () {
11+
registerMochaHooksForSnapshots();
12+
1013
this.tags('ciGroup1');
1114

1215
loadTestFile(require.resolve('./feature_controls'));

x-pack/test/apm_api_integration/basic/tests/observability_overview/observability_overview.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66
import expect from '@kbn/expect';
7+
import { expectSnapshot } from '../../../common/match_snapshot';
78
import { FtrProviderContext } from '../../../common/ftr_provider_context';
89

910
export default function ApiTest({ getService }: FtrProviderContext) {
@@ -22,7 +23,12 @@ export default function ApiTest({ getService }: FtrProviderContext) {
2223
`/api/apm/observability_overview?start=${start}&end=${end}&bucketSize=${bucketSize}`
2324
);
2425
expect(response.status).to.be(200);
25-
expect(response.body).to.eql({ serviceCount: 0, transactionCoordinates: [] });
26+
expectSnapshot(response.body).toMatchInline(`
27+
Object {
28+
"serviceCount": 0,
29+
"transactionCoordinates": Array [],
30+
}
31+
`);
2632
});
2733
});
2834
describe('when data is loaded', () => {
@@ -34,13 +40,21 @@ export default function ApiTest({ getService }: FtrProviderContext) {
3440
`/api/apm/observability_overview?start=${start}&end=${end}&bucketSize=${bucketSize}`
3541
);
3642
expect(response.status).to.be(200);
37-
expect(response.body).to.eql({
38-
serviceCount: 3,
39-
transactionCoordinates: [
40-
{ x: 1593413220000, y: 0.016666666666666666 },
41-
{ x: 1593413280000, y: 1.0458333333333334 },
42-
],
43-
});
43+
expectSnapshot(response.body).toMatchInline(`
44+
Object {
45+
"serviceCount": 3,
46+
"transactionCoordinates": Array [
47+
Object {
48+
"x": 1593413220000,
49+
"y": 0.016666666666666666,
50+
},
51+
Object {
52+
"x": 1593413280000,
53+
"y": 1.0458333333333334,
54+
},
55+
],
56+
}
57+
`);
4458
});
4559
});
4660
});

x-pack/test/apm_api_integration/basic/tests/services/top_services.ts

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import { sortBy } from 'lodash';
88
import expect from '@kbn/expect';
9+
import { expectSnapshot } from '../../../common/match_snapshot';
910
import { FtrProviderContext } from '../../../common/ftr_provider_context';
1011

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

4344
expect(response.status).to.be(200);
44-
expect(services).to.eql([
45-
{
46-
serviceName: 'client',
47-
agentName: 'rum-js',
48-
transactionsPerMinute: 2,
49-
errorsPerMinute: 2.75,
50-
avgResponseTime: 116375,
51-
environments: [],
52-
},
53-
{
54-
serviceName: 'opbeans-java',
55-
agentName: 'java',
56-
transactionsPerMinute: 30.75,
57-
errorsPerMinute: 4.5,
58-
avgResponseTime: 25636.349593495936,
59-
environments: ['production'],
60-
},
61-
{
62-
serviceName: 'opbeans-node',
63-
agentName: 'nodejs',
64-
transactionsPerMinute: 31,
65-
errorsPerMinute: 3.75,
66-
avgResponseTime: 38682.52419354839,
67-
environments: ['production'],
68-
},
69-
]);
45+
expectSnapshot(services).toMatchInline(`
46+
Array [
47+
Object {
48+
"agentName": "rum-js",
49+
"avgResponseTime": 116375,
50+
"environments": Array [],
51+
"errorsPerMinute": 2.75,
52+
"serviceName": "client",
53+
"transactionsPerMinute": 2,
54+
},
55+
Object {
56+
"agentName": "java",
57+
"avgResponseTime": 25636.349593495936,
58+
"environments": Array [
59+
"production",
60+
],
61+
"errorsPerMinute": 4.5,
62+
"serviceName": "opbeans-java",
63+
"transactionsPerMinute": 30.75,
64+
},
65+
Object {
66+
"agentName": "nodejs",
67+
"avgResponseTime": 38682.52419354839,
68+
"environments": Array [
69+
"production",
70+
],
71+
"errorsPerMinute": 3.75,
72+
"serviceName": "opbeans-node",
73+
"transactionsPerMinute": 31,
74+
},
75+
]
76+
`);
7077

7178
expect(response.body.hasHistoricalData).to.be(true);
7279
expect(response.body.hasLegacyData).to.be(false);

x-pack/test/apm_api_integration/basic/tests/services/transaction_types.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import expect from '@kbn/expect';
8+
import { expectSnapshot } from '../../../common/match_snapshot';
89
import { FtrProviderContext } from '../../../../common/ftr_provider_context';
910

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

2526
expect(response.status).to.be(200);
26-
expect(response.body).to.eql({ transactionTypes: [] });
27+
28+
expect(response.body.transactionTypes.length).to.be(0);
2729
});
2830
});
2931

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

3941
expect(response.status).to.be(200);
40-
expect(response.body).to.eql({ transactionTypes: ['request', 'Worker'] });
42+
expectSnapshot(response.body).toMatchInline(`
43+
Object {
44+
"transactionTypes": Array [
45+
"request",
46+
"Worker",
47+
],
48+
}
49+
`);
4150
});
4251
});
4352
});

x-pack/test/apm_api_integration/basic/tests/settings/anomaly_detection/no_access_user.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,18 @@ export default function apiTest({ getService }: FtrProviderContext) {
2525
describe('when calling the endpoint for listing jobs', () => {
2626
it('returns an error because the user does not have access', async () => {
2727
const { body } = await getAnomalyDetectionJobs();
28-
expect(body).to.eql({ statusCode: 404, error: 'Not Found', message: 'Not Found' });
28+
29+
expect(body.statusCode).to.be(404);
30+
expect(body.error).to.be('Not Found');
2931
});
3032
});
3133

3234
describe('when calling create endpoint', () => {
3335
it('returns an error because the user does not have access', async () => {
3436
const { body } = await createAnomalyDetectionJobs(['production', 'staging']);
35-
expect(body).to.eql({ statusCode: 404, error: 'Not Found', message: 'Not Found' });
37+
38+
expect(body.statusCode).to.be(404);
39+
expect(body.error).to.be('Not Found');
3640
});
3741
});
3842
});

x-pack/test/apm_api_integration/basic/tests/settings/anomaly_detection/read_user.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import expect from '@kbn/expect';
8+
import { expectSnapshot } from '../../../../common/match_snapshot';
89
import { FtrProviderContext } from '../../../../common/ftr_provider_context';
910

1011
export default function apiTest({ getService }: FtrProviderContext) {
@@ -25,19 +26,21 @@ export default function apiTest({ getService }: FtrProviderContext) {
2526
describe('when calling the endpoint for listing jobs', () => {
2627
it('returns an error because the user is on basic license', async () => {
2728
const { body } = await getAnomalyDetectionJobs();
28-
expect(body).to.eql({
29-
statusCode: 403,
30-
error: 'Forbidden',
31-
message:
32-
"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.",
33-
});
29+
30+
expect(body.statusCode).to.be(403);
31+
expect(body.error).to.be('Forbidden');
32+
33+
expectSnapshot(body.message).toMatchInline(
34+
`"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."`
35+
);
3436
});
3537
});
3638

3739
describe('when calling create endpoint', () => {
3840
it('returns an error because the user does not have access', async () => {
3941
const { body } = await createAnomalyDetectionJobs(['production', 'staging']);
40-
expect(body).to.eql({ statusCode: 404, error: 'Not Found', message: 'Not Found' });
42+
expect(body.statusCode).to.be(404);
43+
expect(body.error).to.be('Not Found');
4144
});
4245
});
4346
});

x-pack/test/apm_api_integration/basic/tests/settings/anomaly_detection/write_user.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import expect from '@kbn/expect';
8+
import { expectSnapshot } from '../../../../common/match_snapshot';
89
import { FtrProviderContext } from '../../../../common/ftr_provider_context';
910

1011
export default function apiTest({ getService }: FtrProviderContext) {
@@ -25,24 +26,25 @@ export default function apiTest({ getService }: FtrProviderContext) {
2526
describe('when calling the endpoint for listing jobs', () => {
2627
it('returns an error because the user is on basic license', async () => {
2728
const { body } = await getAnomalyDetectionJobs();
28-
expect(body).to.eql({
29-
statusCode: 403,
30-
error: 'Forbidden',
31-
message:
32-
"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.",
33-
});
29+
30+
expect(body.statusCode).to.be(403);
31+
expect(body.error).to.be('Forbidden');
32+
expectSnapshot(body.message).toMatchInline(
33+
`"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."`
34+
);
3435
});
3536
});
3637

3738
describe('when calling create endpoint', () => {
3839
it('returns an error because the user is on basic license', async () => {
3940
const { body } = await createAnomalyDetectionJobs(['production', 'staging']);
40-
expect(body).to.eql({
41-
statusCode: 403,
42-
error: 'Forbidden',
43-
message:
44-
"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.",
45-
});
41+
42+
expect(body.statusCode).to.be(403);
43+
expect(body.error).to.be('Forbidden');
44+
45+
expectSnapshot(body.message).toMatchInline(
46+
`"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."`
47+
);
4648
});
4749
});
4850
});

0 commit comments

Comments
 (0)