Skip to content

Commit

Permalink
[ftr] auto assign ciGroupDocker to suites with dockerServers (elastic…
Browse files Browse the repository at this point in the history
…#99393) (elastic#99540)

Co-authored-by: spalger <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>
# Conflicts:
#	x-pack/test/fleet_api_integration/apis/index.js
  • Loading branch information
Spencer authored May 6, 2021
1 parent c8f54ee commit 18a2def
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ import { createAssignmentProxy } from './assignment_proxy';
import { wrapFunction } from './wrap_function';
import { wrapRunnableArgs } from './wrap_runnable_args';

export function decorateMochaUi(lifecycle, context) {
function split(arr, fn) {
const a = [];
const b = [];
for (const i of arr) {
(fn(i) ? a : b).push(i);
}
return [a, b];
}

export function decorateMochaUi(log, lifecycle, context, { isDockerGroup }) {
// incremented at the start of each suite, decremented after
// so that in each non-suite call we can know if we are within
// a suite, or that when a suite is defined it is within a suite
Expand Down Expand Up @@ -52,13 +61,23 @@ export function decorateMochaUi(lifecycle, context) {
await lifecycle.beforeTestSuite.trigger(this);
});

this.tags = (tags) => {
this._tags = [].concat(this._tags || [], tags);
};

const relativeFilePath = relative(REPO_ROOT, this.file);
this.tags(relativeFilePath);
this._tags = isDockerGroup ? ['ciGroupDocker', relativeFilePath] : [relativeFilePath];
this.suiteTag = relativeFilePath; // The tag that uniquely targets this suite/file
this.tags = (tags) => {
const newTags = Array.isArray(tags) ? tags : [tags];
const [tagsToAdd, tagsToIgnore] = split(newTags, (t) =>
!isDockerGroup ? true : !t.startsWith('ciGroup')
);

if (tagsToIgnore.length) {
log.warning(
`ignoring ciGroup tags because test is being run by a config using 'dockerServers', tags: ${tagsToIgnore}`
);
}

this._tags = [...this._tags, ...tagsToAdd];
};

provider.call(this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,24 @@ import { decorateSnapshotUi } from '../snapshots/decorate_snapshot_ui';
*
* @param {Mocha} mocha
* @param {ToolingLog} log
* @param {Config} config
* @param {ProviderCollection} providers
* @param {String} path
* @return {undefined} - mutates mocha, no return value
*/
export const loadTestFiles = ({
mocha,
log,
config,
lifecycle,
providers,
paths,
updateBaselines,
updateSnapshots,
}) => {
const dockerServers = config.get('dockerServers');
const isDockerGroup = dockerServers && Object.keys(dockerServers).length;

decorateSnapshotUi({ lifecycle, updateSnapshots, isCi: !!process.env.CI });

const innerLoadTestFile = (path) => {
Expand All @@ -55,7 +60,9 @@ export const loadTestFiles = ({
loadTracer(provider, `testProvider[${path}]`, () => {
// mocha.suite hocus-pocus comes from: https://git.io/vDnXO

const context = decorateMochaUi(lifecycle, global);
const context = decorateMochaUi(log, lifecycle, global, {
isDockerGroup,
});
mocha.suite.emit('pre-require', context, path, mocha);

const returnVal = provider({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export async function setupMocha(lifecycle, log, config, providers) {
loadTestFiles({
mocha,
log,
config,
lifecycle,
providers,
paths: config.get('testFiles'),
Expand Down
1 change: 0 additions & 1 deletion x-pack/test/fleet_api_integration/apis/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

export default function ({ loadTestFile }) {
describe('Fleet Endpoints', function () {
this.tags('ciGroupDocker');
// Fleet setup
loadTestFile(require.resolve('./fleet_setup'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export default function (providerContext: FtrProviderContext) {
const { loadTestFile, getService } = providerContext;

describe('endpoint', function () {
this.tags('ciGroupDocker');
const ingestManager = getService('ingestManager');
const log = getService('log');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export default function endpointAPIIntegrationTests(providerContext: FtrProvider
describe('Endpoint plugin', function () {
const ingestManager = getService('ingestManager');

this.tags('ciGroupDocker');
const log = getService('log');

if (!isRegistryEnabled()) {
Expand Down

0 comments on commit 18a2def

Please sign in to comment.