[ftr] validate that suites are not in multiple ciGroups (#99398)

* [ftr] validate that suites are not in multiple ciGroups

* remove unused import

* include filename in error message

* remove redundant ciGroup tags

* fix more duplicate ciGroups

Co-authored-by: spalger <spalger@users.noreply.github.com>
This commit is contained in:
Spencer 2021-05-05 14:50:07 -07:00 committed by GitHub
parent b46a90e8de
commit 61eb3f0685
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 80 additions and 28 deletions

View file

@ -13,6 +13,7 @@ import { REPO_ROOT } from '@kbn/utils';
import { loadTestFiles } from './load_test_files';
import { filterSuitesByTags } from './filter_suites_by_tags';
import { MochaReporterProvider } from './reporter';
import { validateCiGroupTags } from './validate_ci_group_tags';
/**
* Instantiate mocha and load testfiles into it
@ -45,6 +46,9 @@ export async function setupMocha(lifecycle, log, config, providers) {
updateSnapshots: config.get('updateSnapshots'),
});
// valiate that there aren't any tests in multiple ciGroups
validateCiGroupTags(log, mocha);
// Each suite has a tag that is the path relative to the root of the repo
// So we just need to take input paths, make them relative to the root, and use them as tags
// Also, this is a separate filterSuitesByTags() call so that the test suites will be filtered first by

View file

@ -0,0 +1,75 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import Path from 'path';
import { REPO_ROOT } from '@kbn/dev-utils';
/**
* Traverse the suites configured and ensure that each suite has no more than one ciGroup assigned
*
* @param {ToolingLog} log
* @param {Mocha} mocha
*/
export function validateCiGroupTags(log, mocha) {
const tagCache = new Map();
const getTags = (suite) => {
const cached = tagCache.get(suite);
if (cached) {
return cached;
}
const allTags = [
...new Set([...(suite.parent ? getTags(suite.parent) : []), ...(suite._tags ?? [])]),
];
tagCache.set(suite, allTags);
return allTags;
};
const getCiGroups = (suite) => {
return getTags(suite).filter((t) => t.startsWith('ciGroup'));
};
const getTitles = (suite) => {
const all = suite.parent ? getTitles(suite.parent) : [];
if (suite.title) {
all.push(suite.title.trim());
}
return all;
};
const suitesWithMultipleCiGroups = [];
const queue = [mocha.suite];
while (queue.length) {
const suite = queue.shift();
if (getCiGroups(suite).length > 1) {
suitesWithMultipleCiGroups.push(suite);
} else {
queue.push(...(suite.suites ?? []));
}
}
if (suitesWithMultipleCiGroups.length) {
const list = suitesWithMultipleCiGroups
.map((s) => {
const groups = getCiGroups(s).join(', ');
const title = getTitles(s).join(' > ') || '';
const from = s.file ? ` (from: ${Path.relative(REPO_ROOT, s.file)})` : '';
return ` - ${groups}: ${title}${from}`;
})
.join('\n');
log.error(
`${suitesWithMultipleCiGroups.length} suites found which are assigned to multiple ciGroups:\n${list}`
);
throw new Error('some suites have mutliple ciGroup tags');
}
}

View file

@ -9,8 +9,6 @@ import { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ loadTestFile }: FtrProviderContext) {
describe('feature controls', function () {
this.tags(['ciGroup8']);
loadTestFile(require.resolve('./api_keys_security'));
});
}

View file

@ -9,8 +9,6 @@ import { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ loadTestFile }: FtrProviderContext) {
describe('feature controls', function () {
this.tags(['ciGroup8']);
loadTestFile(require.resolve('./ccr_security'));
});
}

View file

@ -9,8 +9,6 @@ import { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ loadTestFile }: FtrProviderContext) {
describe('feature controls', function () {
this.tags(['ciGroup2']);
loadTestFile(require.resolve('./ilm_security'));
});
}

View file

@ -9,8 +9,6 @@ import { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ loadTestFile }: FtrProviderContext) {
describe('feature controls', function () {
this.tags(['ciGroup2']);
loadTestFile(require.resolve('./index_management_security'));
});
}

View file

@ -9,8 +9,6 @@ import { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ loadTestFile }: FtrProviderContext) {
describe('feature controls', function () {
this.tags(['ciGroup2']);
loadTestFile(require.resolve('./ingest_pipelines_security'));
});
}

View file

@ -9,8 +9,6 @@ import { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ loadTestFile }: FtrProviderContext) {
describe('feature controls', function () {
this.tags(['ciGroup2']);
loadTestFile(require.resolve('./license_management_security'));
});
}

View file

@ -9,8 +9,6 @@ import { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ loadTestFile }: FtrProviderContext) {
describe('feature controls', function () {
this.tags(['ciGroup2']);
loadTestFile(require.resolve('./remote_clusters_security'));
});
}

View file

@ -9,8 +9,6 @@ import { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ loadTestFile }: FtrProviderContext) {
describe('feature controls', function () {
this.tags(['ciGroup2']);
loadTestFile(require.resolve('./transform_security'));
});
}

View file

@ -9,8 +9,6 @@ import { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ loadTestFile }: FtrProviderContext) {
describe('feature controls', function () {
this.tags(['ciGroup2']);
loadTestFile(require.resolve('./upgrade_assistant_security'));
});
}

View file

@ -9,8 +9,6 @@ import { FtrProviderContext } from '../ftr_provider_context';
export default function ({ loadTestFile }: FtrProviderContext) {
describe('apps', function () {
this.tags('ciGroup2');
loadTestFile(require.resolve('./ml'));
loadTestFile(require.resolve('./transform'));
});

View file

@ -12,7 +12,7 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) {
const ml = getService('ml');
describe('machine learning basic license', function () {
this.tags(['skipFirefox', 'mlqa']);
this.tags(['ciGroup2', 'skipFirefox', 'mlqa']);
before(async () => {
await ml.securityCommon.createMlRoles();

View file

@ -66,7 +66,6 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
];
describe('endpoint list', function () {
this.tags('ciGroup7');
const sleep = (ms = 100) => new Promise((resolve) => setTimeout(resolve, ms));
describe('when initially navigating to page', () => {

View file

@ -13,8 +13,6 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
describe('When in the Fleet application', function () {
this.tags(['ciGroup7']);
describe('and on the Endpoint Integration details page', () => {
beforeEach(async () => {
await fleetIntegrations.navigateToIntegrationDetails(

View file

@ -22,8 +22,6 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
const policyTestResources = getService('policyTestResources');
describe('When on the Endpoint Policy Details Page', function () {
this.tags(['ciGroup7']);
describe('with an invalid policy id', () => {
it('should display an error', async () => {
await pageObjects.policy.navigateToPolicyDetails('invalid-id');

View file

@ -13,8 +13,6 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
const testSubjects = getService('testSubjects');
describe('When on the Trusted Apps list', function () {
this.tags('ciGroup7');
before(async () => {
await pageObjects.trustedApps.navigateToTrustedAppsList();
});