Skip to content

Commit

Permalink
fix api test
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Dec 8, 2020
1 parent 292d57b commit cec2f84
Show file tree
Hide file tree
Showing 10 changed files with 3,245 additions and 38 deletions.
27 changes: 24 additions & 3 deletions x-pack/test/apm_api_integration/basic/tests/feature_controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,42 @@ export default function featureControlsTests({ getService }: FtrProviderContext)
},
{
req: {
url: `/api/apm/services/foo/transactions/charts?start=${start}&end=${end}&transactionType=bar&uiFilters=%7B%22environment%22%3A%22testing%22%7D`,
url: `/api/apm/services/foo/transactions/charts/latency?start=${start}&end=${end}&transactionType=bar&uiFilters=%7B%22environment%22%3A%22testing%22%7D`,
},
expectForbidden: expect403,
expectResponse: expect200,
},
{
req: {
url: `/api/apm/services/foo/transactions/charts?start=${start}&end=${end}&uiFilters=%7B%22environment%22%3A%22testing%22%7D`,
url: `/api/apm/services/foo/transactions/charts/latency?start=${start}&end=${end}&uiFilters=%7B%22environment%22%3A%22testing%22%7D`,
},
expectForbidden: expect403,
expectResponse: expect200,
},
{
req: {
url: `/api/apm/services/foo/transactions/charts?start=${start}&end=${end}&transactionType=bar&transactionName=baz&uiFilters=%7B%22environment%22%3A%22testing%22%7D`,
url: `/api/apm/services/foo/transactions/charts/latency?start=${start}&end=${end}&transactionType=bar&transactionName=baz&uiFilters=%7B%22environment%22%3A%22testing%22%7D`,
},
expectForbidden: expect403,
expectResponse: expect200,
},
{
req: {
url: `/api/apm/services/foo/transactions/charts/throughput?start=${start}&end=${end}&transactionType=bar&uiFilters=%7B%22environment%22%3A%22testing%22%7D`,
},
expectForbidden: expect403,
expectResponse: expect200,
},
{
req: {
url: `/api/apm/services/foo/transactions/charts/throughput?start=${start}&end=${end}&uiFilters=%7B%22environment%22%3A%22testing%22%7D`,
},
expectForbidden: expect403,
expectResponse: expect200,
},
{
req: {
url: `/api/apm/services/foo/transactions/charts/throughput?start=${start}&end=${end}&transactionType=bar&transactionName=baz&uiFilters=%7B%22environment%22%3A%22testing%22%7D`,
},
expectForbidden: expect403,
expectResponse: expect200,
Expand Down
3 changes: 2 additions & 1 deletion x-pack/test/apm_api_integration/basic/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export default function apmApiIntegrationTests({ loadTestFile }: FtrProviderCont

describe('Transactions', function () {
loadTestFile(require.resolve('./transactions/top_transaction_groups'));
loadTestFile(require.resolve('./transactions/transaction_charts'));
loadTestFile(require.resolve('./transactions/latency'));
loadTestFile(require.resolve('./transactions/throughput'));
loadTestFile(require.resolve('./transactions/error_rate'));
loadTestFile(require.resolve('./transactions/breakdown'));
loadTestFile(require.resolve('./transactions/distribution'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,19 @@ export default function ApiTest({ getService }: FtrProviderContext) {
const end = encodeURIComponent(metadata.end);
const uiFilters = encodeURIComponent(JSON.stringify({ environment: 'testing' }));

describe('Transaction charts', () => {
describe('Latency', () => {
describe('when data is not loaded ', () => {
it('handles the empty state', async () => {
const response = await supertest.get(
`/api/apm/services/opbeans-node/transactions/charts?start=${start}&end=${end}&uiFilters=${uiFilters}`
`/api/apm/services/opbeans-node/transactions/charts/latency?start=${start}&end=${end}&uiFilters=${uiFilters}`
);

expect(response.status).to.be(200);

expect(response.body.apmTimeseries.overallAvgDuration).to.be(null);
expect(response.body.apmTimeseries.responseTimes.avg.length).to.be(0);
expect(response.body.apmTimeseries.responseTimes.p95.length).to.be(0);
expect(response.body.apmTimeseries.responseTimes.p99.length).to.be(0);
expect(response.body.apmTimeseries.tpmBuckets.length).to.be(0);
expect(response.body.overallAvgDuration).to.be(null);
expect(response.body.latency.avg.length).to.be(0);
expect(response.body.latency.p95.length).to.be(0);
expect(response.body.latency.p99.length).to.be(0);
});
});

Expand All @@ -45,28 +44,17 @@ export default function ApiTest({ getService }: FtrProviderContext) {

before(async () => {
response = await supertest.get(
`/api/apm/services/opbeans-node/transactions/charts?start=${start}&end=${end}&uiFilters=${uiFilters}`
`/api/apm/services/opbeans-node/transactions/charts/latency?start=${start}&end=${end}&uiFilters=${uiFilters}`
);
});

it('returns some data', async () => {
it('returns average duration and timeseries', async () => {
expect(response.status).to.be(200);

expect(response.body.apmTimeseries.overallAvgDuration).not.to.be(null);
expect(response.body.apmTimeseries.responseTimes.avg.length).to.be.greaterThan(0);
expect(response.body.apmTimeseries.responseTimes.p95.length).to.be.greaterThan(0);
expect(response.body.apmTimeseries.responseTimes.p99.length).to.be.greaterThan(0);
expect(response.body.apmTimeseries.tpmBuckets.length).to.be.greaterThan(0);
});

it('returns the correct data', () => {
expectSnapshot(response.body.apmTimeseries.overallAvgDuration).toMatchInline(
`600888.274678112`
);
expectSnapshot(response.body.apmTimeseries.responseTimes.avg.length).toMatchInline(`61`);
expectSnapshot(response.body.apmTimeseries.tpmBuckets.length).toMatchInline(`3`);

expectSnapshot(response.body).toMatch();
expect(response.body.overallAvgDuration).not.to.be(null);
expect(response.body.latency.avg.length).to.be.greaterThan(0);
expect(response.body.latency.p95.length).to.be.greaterThan(0);
expect(response.body.latency.p99.length).to.be.greaterThan(0);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import expect from '@kbn/expect';
import archives_metadata from '../../../common/archives_metadata';
import { PromiseReturnType } from '../../../../../plugins/observability/typings/common';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

export default function ApiTest({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');

const archiveName = 'apm_8.0.0';
const metadata = archives_metadata[archiveName];

// url parameters
const start = encodeURIComponent(metadata.start);
const end = encodeURIComponent(metadata.end);
const uiFilters = encodeURIComponent(JSON.stringify({ environment: 'testing' }));

describe('Throughput', () => {
describe('when data is not loaded ', () => {
it('handles the empty state', async () => {
const response = await supertest.get(
`/api/apm/services/opbeans-node/transactions/charts/throughput?start=${start}&end=${end}&uiFilters=${uiFilters}`
);

expect(response.status).to.be(200);

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

describe('when data is loaded', () => {
before(() => esArchiver.load(archiveName));
after(() => esArchiver.unload(archiveName));

let response: PromiseReturnType<typeof supertest.get>;

before(async () => {
response = await supertest.get(
`/api/apm/services/opbeans-node/transactions/charts/throughput?start=${start}&end=${end}&uiFilters=${uiFilters}`
);
});

it('returns throughput timeseries', async () => {
expect(response.status).to.be(200);

expect(response.body.throughput.length).to.be.greaterThan(0);
});
});
});
}
Loading

0 comments on commit cec2f84

Please sign in to comment.