Skip to content

Commit

Permalink
FTR: enable ESLint mocha rules for api integration tests (elastic#191267
Browse files Browse the repository at this point in the history
)

## Summary

Follow-up to elastic#190690

Most of API integration tests does not match the path pattern set in the
original PR (thanks @pheyos for catching it) and where not updated.
This PR updates `.eslintrc.js` with explicit patterns to lint
api_integration tests. Hopefully it is final change, but I rely on code
owners to double check it.

Most of the changes are trivial adjustments:
- duplicated before/after hooks `mocha/no-sibling-hooks`
- duplicated test titles `mocha/no-identical-title`
- async function in describe() `mocha/no-async-describe`

---------

Co-authored-by: Ash <[email protected]>
  • Loading branch information
dmlemeshko and ashokaditya authored Aug 30, 2024
1 parent 22d23ff commit 8436f45
Show file tree
Hide file tree
Showing 164 changed files with 509 additions and 613 deletions.
6 changes: 4 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1371,8 +1371,10 @@ module.exports = {
},
{
files: [
'test/{accessibility,*functional*,*api_integration*}/apps/**/*.{js,ts}',
'x-pack/test/{accessibility,*functional*,*api_integration*}/apps/**/*.{js,ts}',
'test/{accessibility,*functional*}/apps/**/*.{js,ts}',
'test/*api_integration*/**/*.{js,ts}',
'x-pack/test/{accessibility,*functional*}/apps/**/*.{js,ts}',
'x-pack/test/*api_integration*/**/*.{js,ts}',
'x-pack/test_serverless/{functional,api_integration}/test_suites/**/*.{js,ts}',
],
extends: ['plugin:mocha/recommended'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export default function ({ getService }: FtrProviderContext) {
expect(response.body[config.serviceKey].fieldFormats.foo.params).to.eql({});
});

it('can specify optional fieldFormats attribute when creating an index pattern', async () => {
it('can specify optional fieldFormats attributes count and customLabel when creating an index pattern', async () => {
const title = `foo-${Date.now()}-${Math.random()}*`;
const response = await supertest.post(config.path).send({
[config.serviceKey]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ export default function ({ getService }: FtrProviderContext) {
);
});

it('returns 404 error on non-existing scripted field', async () => {
const response1 = await supertest.get(
`/api/index_patterns/index_pattern/${indexPattern.id}/scripted_field/test`
);
expect(response1.status).to.be(404);
});

it('returns error when attempting to fetch a field which is not a scripted field', async () => {
const response2 = await supertest.get(
`/api/index_patterns/index_pattern/${indexPattern.id}/scripted_field/foo`
Expand Down
8 changes: 4 additions & 4 deletions x-pack/test/alerting_api_integration/common/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { ToolingLog } from '@kbn/tooling-log';
* Example usage:
* ```ts
const fleetResponse = await retry<InstallPackageResponse>({
test: async () => {
testFn: async () => {
const testResponse = await supertest
.post(`/api/fleet/epm/packages/security_detection_engine`)
.set('kbn-xsrf', 'xxxx')
Expand All @@ -45,15 +45,15 @@ import type { ToolingLog } from '@kbn/tooling-log';
* @returns The response from the test
*/
export const retry = async <T>({
test,
testFn,
retryService,
utilityName,
retries = 3,
timeout = 30000,
retryDelay = 200,
logger,
}: {
test: () => Promise<T>;
testFn: () => Promise<T>;
utilityName: string;
retryService: RetryService;
retries?: number;
Expand All @@ -77,7 +77,7 @@ export const retry = async <T>({

retryAttempt = retryAttempt + 1;

return await test();
return await testFn();
},
undefined,
retryDelay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function waitForRuleStatus({
logger: ToolingLog;
}): Promise<Record<string, any>> {
const ruleResponse = await retry<Record<string, any>>({
test: async () => {
testFn: async () => {
const response = await supertest.get(`/api/alerting/rule/${id}`);
const { execution_status: executionStatus } = response.body || {};
const { status } = executionStatus || {};
Expand Down Expand Up @@ -74,7 +74,7 @@ export async function waitForDocumentInIndex<T>({
retryDelay?: number;
}): Promise<SearchResponse<T, Record<string, AggregationsAggregate>>> {
return await retry<SearchResponse<T, Record<string, AggregationsAggregate>>>({
test: async () => {
testFn: async () => {
const response = await esClient.search<T>({
index: indexName,
rest_total_hits_as_int: true,
Expand Down Expand Up @@ -112,7 +112,7 @@ export async function waitForAlertInIndex<T>({
logger: ToolingLog;
}): Promise<SearchResponse<T, Record<string, AggregationsAggregate>>> {
return await retry<SearchResponse<T, Record<string, AggregationsAggregate>>>({
test: async () => {
testFn: async () => {
const response = await esClient.search<T>({
index: indexName,
body: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function bulkUntrackByQueryTests({ getService }: FtrProviderConte
});

for (const scenario of UserAtSpaceScenarios) {
describe(scenario.id, async () => {
describe(scenario.id, () => {
it('should bulk mark alerts as untracked by query', async () => {
const { body: createdRule1 } = await supertest
.post(`${getUrlPrefix(scenario.space.id)}/api/alerting/rule`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { FtrProviderContext } from '../../../../common/ftr_provider_context';
// eslint-disable-next-line import/no-default-export
export default function alertingApiIntegrationTests({ loadTestFile }: FtrProviderContext) {
describe('alerting api integration security and spaces enabled', function () {
describe('', function () {
loadTestFile(require.resolve('./alerting'));
});
loadTestFile(require.resolve('./alerting'));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export default function opsgenieTest({ getService }: FtrProviderContext) {
});
});

describe('optional parameters', async () => {
describe('optional parameters', () => {
describe('responders', () => {
it('should fail to create an alert when the responders is an invalid type', async () => {
const { body } = await supertest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function createAlertTests({ getService }: FtrProviderContext) {
const es = getService('es');
const supertestWithoutAuth = getService('supertestWithoutAuth');

describe('clone', async () => {
describe('clone', () => {
const objectRemover = new ObjectRemover(supertest);
const space1 = Spaces[0].id;
const space2 = Spaces[1].id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { FtrProviderContext } from '../../../../common/ftr_provider_context';
export default function getRuleFieldsTests({ getService }: FtrProviderContext) {
const supertestWithoutAuth = getService('supertestWithoutAuth');

describe('fields rule', async () => {
describe('fields rule', () => {
for (const scenario of UserAtSpaceScenarios) {
const { user, space } = scenario;
describe(scenario.id, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { FtrProviderContext } from '../../../../common/ftr_provider_context';
export default function createRuleSuggestionValuesTests({ getService }: FtrProviderContext) {
const space1 = Spaces[0].id;

describe('alerts/suggestions/values', async () => {
describe('alerts/suggestions/values', () => {
const esArchiver = getService('esArchiver');
const supertest = getService('supertest');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function createRuleSuggestionValuesTests({ getService }: FtrProvi
const supertest = getService('supertest');
const supertestWithoutAuth = getService('supertestWithoutAuth');

describe('rules/suggestions/values', async () => {
describe('rules/suggestions/values', () => {
const objectRemover = new ObjectRemover(supertest);
const space1 = Spaces[0].id;
const space2 = Spaces[1].id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default function alertTests({ getService }: FtrProviderContext) {
const esTestIndexTool = new ESTestIndexTool(es, retry);
const esTestIndexToolOutput = new ESTestIndexTool(es, retry, ES_TEST_OUTPUT_INDEX_NAME);

describe('alert', async () => {
describe('alert', () => {
const objectRemover = new ObjectRemover(supertest);
let actionId: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
`.internal.alerts-transform.health.alerts-default-000001`
);

describe('rule', async () => {
describe('rule', () => {
const objectRemover = new ObjectRemover(supertest);
let connectorId: string;
const transformId = 'test_transform_01';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
getAllAADDocs,
} = getRuleServices(getService);

describe('rule', async () => {
describe('rule', () => {
let endDate: string;
let connectorId: string;
const objectRemover = new ObjectRemover(supertest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
const { es, esTestIndexTool, esTestIndexToolOutput, createEsDocumentsInGroups, waitForDocs } =
getRuleServices(getService);

describe('rule', async () => {
describe('rule', () => {
let endDate: string;
let connectorId: string;
const objectRemover = new ObjectRemover(supertest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
{ label: 'host.name', searchPath: 'host.name' },
];

describe('rule', async () => {
describe('rule', () => {
let endDate: string;
let connectorId: string;
const objectRemover = new ObjectRemover(supertest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
`.internal.alerts-${STACK_AAD_INDEX_NAME}.alerts-default-000001`
);

describe('rule', async () => {
describe('rule', () => {
let endDate: string;
let connectorId: string;
const objectRemover = new ObjectRemover(supertest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function ruleTests({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const retry = getService('retry');

describe('long running rule', async () => {
describe('long running rule', () => {
const objectRemover = new ObjectRemover(supertest);

afterEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function createGetTests({ getService }: FtrProviderContext) {
await esArchiver.unload('x-pack/test/functional/es_archives/alerting/8_2_0');
});

describe('rule with null snoozeEndTime value', async () => {
describe('rule with null snoozeEndTime value', () => {
it('has snoozeEndTime removed', async () => {
const response = await es.get<{ alert: RawRule & { snoozeEndTime?: string } }>(
{
Expand Down Expand Up @@ -60,7 +60,7 @@ export default function createGetTests({ getService }: FtrProviderContext) {
});
});

describe('rules with snoozeEndTime value', async () => {
describe('rules with snoozeEndTime value', () => {
it('has snoozeEndTime migrated to snoozeSchedule', async () => {
const response = await es.get<{ alert: RawRule & { snoozeEndTime?: string } }>(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function ({ getService }: FtrProviderContext) {
const es = getService('es');
const esDeleteAllIndices = getService('esDeleteAllIndices');

describe('create index', async () => {
describe('create index', () => {
const testIndices = ['my-test-index-001', 'my-test-index-002'];
before(async () => {
await esDeleteAllIndices(testIndices);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function ({ getService }: FtrProviderContext) {
const testIndex = '.test_index';
const testAlias = 'test_alias';
const testIlmPolicy = 'test_policy';
describe('GET indices with data enrichers', async () => {
describe('GET indices with data enrichers', () => {
before(async () => {
await createIndex(testIndex);
await createIlmPolicy('test_policy');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function ({ getService }: FtrProviderContext) {
};

const testIndex = 'test_index';
describe('GET indices without data enrichers', async () => {
describe('GET indices without data enrichers', () => {
before(async () => {
await createIndex(testIndex);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function ({ getService }: FtrProviderContext) {
};

const testIndex = 'test_index';
describe('index details', async () => {
describe('index details', () => {
before(async () => {
await createIndex(testIndex);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ export default function ({ getService }: FtrProviderContext) {
},
};

after(async () => await deleteAllIndices());

before(async () => {
log.debug('Creating index');
try {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/api_integration/apis/maps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function ({ loadTestFile, getService }) {
);
});

describe('', () => {
describe('apis', () => {
loadTestFile(require.resolve('./maps_telemetry'));
loadTestFile(require.resolve('./get_indexes_matching_pattern'));
loadTestFile(require.resolve('./create_doc_source'));
Expand Down
12 changes: 8 additions & 4 deletions x-pack/test/api_integration/apis/metrics_ui/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ export default function ({ getService }: FtrProviderContext) {
const kibanaServer = getService('kibanaServer');

describe('sources', () => {
before(() => esArchiver.load('x-pack/test/functional/es_archives/infra/metrics_and_logs'));
after(() => esArchiver.unload('x-pack/test/functional/es_archives/infra/metrics_and_logs'));
before(() => kibanaServer.savedObjects.cleanStandardList());
after(() => kibanaServer.savedObjects.cleanStandardList());
before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/infra/metrics_and_logs');
await kibanaServer.savedObjects.cleanStandardList();
});
after(async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/infra/metrics_and_logs');
await kibanaServer.savedObjects.cleanStandardList();
});

const patchRequest = async (
body: PartialMetricsSourceConfigurationProperties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export default ({ getService }: FtrProviderContext) => {
});

testJobConfigs.forEach((testConfig) => {
describe(`EvaluateDataFrameAnalytics ${testConfig.jobType}`, async () => {
describe(`EvaluateDataFrameAnalytics ${testConfig.jobType}`, () => {
it(`should evaluate ${testConfig.jobType} analytics job`, async () => {
const { body, status } = await supertest
.post(`/internal/ml/data_frame/_evaluate`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default ({ getService }: FtrProviderContext) => {
});

testJobConfigs.forEach((testConfig) => {
describe(`ExplainDataFrameAnalytics ${testConfig.jobType}`, async () => {
describe(`ExplainDataFrameAnalytics ${testConfig.jobType}`, () => {
it(`should explain ${testConfig.jobType} analytics job`, async () => {
const { body, status } = await supertest
.post(`/internal/ml/data_frame/analytics/_explain`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default ({ getService }: FtrProviderContext) => {
expect(body).to.eql({ [jobIdSpace1]: { exists: true, isGroup: false } });
});

it('should find single job from same space', async () => {
it('should find single group from same space', async () => {
const body = await runRequest(idSpace1, 200, [groupSpace1]);
expect(body).to.eql({ [groupSpace1]: { exists: true, isGroup: true } });
});
Expand Down
3 changes: 0 additions & 3 deletions x-pack/test/api_integration/apis/osquery/packs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ export default function ({ getService }: FtrProviderContext) {
await getService('esArchiver').unload(
'x-pack/test/functional/es_archives/fleet/empty_fleet_server'
);
});

after(async function () {
await supertest
.post(`/api/fleet/agent_policies/delete`)
.set('kbn-xsrf', 'xxxx')
Expand Down
4 changes: 2 additions & 2 deletions x-pack/test/api_integration/apis/uptime/rest/certs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function ({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');

describe('certs api', () => {
describe('empty index', async () => {
describe('empty index', () => {
it('returns empty array for no data', async () => {
const apiResponse = await supertest
.post(`/internal/search/ese`)
Expand All @@ -41,7 +41,7 @@ export default function ({ getService }: FtrProviderContext) {
});
});

describe('when data is present', async () => {
describe('when data is present', () => {
const now = moment();
const cnva = now.add(6, 'months').toISOString();
const cnvb = now.subtract(23, 'weeks').toISOString();
Expand Down
Loading

0 comments on commit 8436f45

Please sign in to comment.