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

FTR: enable ESLint mocha rules for api integration tests #191267

Merged
merged 21 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6ee0020
add more test paths and fix errors in test/
dmlemeshko Aug 23, 2024
b806b14
fix errors in x-pack/test/
dmlemeshko Aug 26, 2024
2bed553
Merge remote-tracking branch 'upstream/main' into ftr/eslint-in-api-t…
dmlemeshko Aug 26, 2024
3b98c57
rename arg in retry service to testFn
dmlemeshko Aug 26, 2024
ffe6cf4
Merge branch 'main' into ftr/eslint-in-api-tests
dmlemeshko Aug 26, 2024
32066d3
git revert changes in x-pack/test/fleet_api_integration/apis/outputs/…
dmlemeshko Aug 26, 2024
6e23c4c
fix errors in x-pack/test/apm_api_integration
dmlemeshko Aug 26, 2024
cfb1f0b
fix errors
dmlemeshko Aug 26, 2024
3705654
Merge remote-tracking branch 'upstream/main' into ftr/eslint-in-api-t…
dmlemeshko Aug 28, 2024
5096866
Merge branch 'main' into ftr/eslint-in-api-tests
dmlemeshko Aug 28, 2024
3ba8d41
add missing await
dmlemeshko Aug 28, 2024
01e0a6c
Merge branch 'ftr/eslint-in-api-tests' of github.com:dmlemeshko/kiban…
dmlemeshko Aug 28, 2024
4f802ed
Merge branch 'main' into ftr/eslint-in-api-tests
dmlemeshko Aug 28, 2024
3533eb2
Update x-pack/test/security_solution_api_integration/test_suites/edr_…
dmlemeshko Aug 29, 2024
696e9e6
Merge branch 'main' into ftr/eslint-in-api-tests
dmlemeshko Aug 29, 2024
4a06190
Merge branch 'main' into ftr/eslint-in-api-tests
dmlemeshko Aug 29, 2024
c7889ab
Merge remote-tracking branch 'upstream/main' into ftr/eslint-in-api-t…
dmlemeshko Aug 30, 2024
40d8908
fix spaces FTR service
dmlemeshko Aug 30, 2024
19510e2
call service in before hook
dmlemeshko Aug 30, 2024
835d737
Merge remote-tracking branch 'upstream/main' into ftr/eslint-in-api-t…
dmlemeshko Aug 30, 2024
3faef29
Merge remote-tracking branch 'upstream/main' into ftr/eslint-in-api-t…
dmlemeshko Aug 30, 2024
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
6 changes: 4 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1367,8 +1367,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);
});

Comment on lines -71 to -77
Copy link
Member Author

@dmlemeshko dmlemeshko Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Complete duplicate of

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

in the same file

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,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test is reserved by Mocha, renaming for convenience.

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 @@ -236,7 +236,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());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate hook:

after(async () => {
try {
await deleteAllIndices();
} catch (err) {
log.debug('[Cleanup error] Error deleting index');
throw err;
}
});


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();
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error Unexpected use of duplicate Mocha before hook mocha/no-sibling-hooks

Duplicating hooks is not recommended because it can lead to confusion about the order of execution and potential issues in test maintenance.


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