Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
4 changes: 3 additions & 1 deletion .buildkite/ftr_security_serverless_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ enabled:
- x-pack/solutions/security/test/security_solution_api_integration/test_suites/detections_response/rules_management/rule_update/basic_license_essentials_tier/configs/serverless.config.ts
- x-pack/solutions/security/test/security_solution_api_integration/test_suites/detections_response/rules_management/prebuilt_rules/common/configs/serverless_essentials_tier.config.ts
- x-pack/solutions/security/test/security_solution_api_integration/test_suites/detections_response/rules_management/prebuilt_rules/customization_disabled/configs/serverless_essentials_tier.config.ts
- x-pack/solutions/security/test/security_solution_api_integration/test_suites/detections_response/rules_management/prebuilt_rules/customization_enabled/configs/serverless.config.ts
- x-pack/solutions/security/test/security_solution_api_integration/test_suites/detections_response/rules_management/prebuilt_rules/customization_enabled/customization/configs/serverless.config.ts
- x-pack/solutions/security/test/security_solution_api_integration/test_suites/detections_response/rules_management/prebuilt_rules/customization_enabled/upgrade_prebuilt_rules/configs/serverless.config.ts
- x-pack/solutions/security/test/security_solution_api_integration/test_suites/detections_response/rules_management/prebuilt_rules/customization_enabled/upgrade_notifications/configs/serverless.config.ts
- x-pack/solutions/security/test/security_solution_api_integration/test_suites/detections_response/rules_management/prebuilt_rules/customization_enabled/upgrade_prebuilt_rules/diffable_rule_fields/common_fields/configs/serverless.config.ts
- x-pack/solutions/security/test/security_solution_api_integration/test_suites/detections_response/rules_management/prebuilt_rules/customization_enabled/upgrade_prebuilt_rules/diffable_rule_fields/type_specific_fields/configs/serverless.config.ts
- x-pack/solutions/security/test/security_solution_api_integration/test_suites/detections_response/rules_management/prebuilt_rules/ml_disabled/configs/serverless_essentials_tier.config.ts
Expand Down
4 changes: 3 additions & 1 deletion .buildkite/ftr_security_stateful_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ enabled:
- x-pack/solutions/security/test/security_solution_api_integration/test_suites/detections_response/rules_management/prebuilt_rules/common/configs/edge_cases/ess_air_gapped_with_bundled_large_package.config.ts
- x-pack/solutions/security/test/security_solution_api_integration/test_suites/detections_response/rules_management/prebuilt_rules/customization_disabled/configs/ess_basic_license.config.ts
- x-pack/solutions/security/test/security_solution_api_integration/test_suites/detections_response/rules_management/prebuilt_rules/common/configs/edge_cases/ess_trial_license.config.ts
- x-pack/solutions/security/test/security_solution_api_integration/test_suites/detections_response/rules_management/prebuilt_rules/customization_enabled/configs/ess.config.ts
- x-pack/solutions/security/test/security_solution_api_integration/test_suites/detections_response/rules_management/prebuilt_rules/customization_enabled/customization/configs/ess.config.ts
- x-pack/solutions/security/test/security_solution_api_integration/test_suites/detections_response/rules_management/prebuilt_rules/customization_enabled/upgrade_prebuilt_rules/configs/ess.config.ts
- x-pack/solutions/security/test/security_solution_api_integration/test_suites/detections_response/rules_management/prebuilt_rules/customization_enabled/upgrade_notifications/configs/ess.config.ts
- x-pack/solutions/security/test/security_solution_api_integration/test_suites/detections_response/rules_management/prebuilt_rules/customization_enabled/upgrade_prebuilt_rules/diffable_rule_fields/common_fields/configs/ess.config.ts
- x-pack/solutions/security/test/security_solution_api_integration/test_suites/detections_response/rules_management/prebuilt_rules/customization_enabled/upgrade_prebuilt_rules/diffable_rule_fields/type_specific_fields/configs/ess.config.ts
- x-pack/solutions/security/test/security_solution_api_integration/test_suites/detections_response/rules_management/prebuilt_rules/ml_disabled/configs/ess_basic_license.config.ts
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

/* eslint-disable import/no-nodejs-modules */
import fs from 'fs';
import path from 'path';

const fieldsDir = __dirname;

// Discover all test files in the fields directory
const allTestFiles = fs
.readdirSync(fieldsDir)
.filter((f) => f.endsWith('.test.ts'))
.sort();

// Count config_* directories to determine total groups
const totalGroups = fs.readdirSync(fieldsDir).filter((dir) => {
const fullPath = path.join(fieldsDir, dir);
return fs.statSync(fullPath).isDirectory() && dir.startsWith('config_');
}).length;

/**
* Discovers all field test files and distributes them using round-robin
* across the available configs.
*/
function getTestsForConfig(configNumber) {
const groupIndex = configNumber - 1;
const configTestFiles = allTestFiles.filter((file, index) => index % totalGroups === groupIndex);
Copy link
Contributor

Choose a reason for hiding this comment

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

The implementation could be simplified by using Lodash's chunk utility. A test group may pick a chunk by number. It should work the same way as the current implementation but it's gonna be shorter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried doing it with chunk, but I think it turned out even a bit more complicated.

const configTestFiles = chunk(testFiles, Math.ceil(testFiles.length / totalGroups))[groupIndex];

Also one minor downside of the chunk approach is that if we later add more groups, it won't balance them nicely without writing additional code.
Like, let's say if you have 13 files and 4 groups, it'll distribute them like: [4, 4, 4, 1] and not [4, 3, 3, 3].


console.log(
`Rule Upgrade - Fields integration tests. config_${configNumber}: Running ${configTestFiles.length} test files:`,
configTestFiles
);

return configTestFiles;
}

/**
* Base Jest configuration shared by all field test configs
*/
export function createFieldTestingConfig(configNumber) {
const testFiles = getTestsForConfig(configNumber);

return {
preset: '@kbn/test/jest_integration',
rootDir: '../../../../../../../../../../../../../../..',
roots: [
'<rootDir>/x-pack/solutions/security/plugins/security_solution/public/detection_engine/rule_management_ui/pages/rule_management',
],
testMatch: testFiles.map((file) => `**/fields/${file}`),
openHandlesTimeout: 0,
forceExit: true,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { createFieldTestingConfig } from '../base.jest.integration.config';

export default createFieldTestingConfig(1);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { createFieldTestingConfig } from '../base.jest.integration.config';

export default createFieldTestingConfig(2);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { createFieldTestingConfig } from '../base.jest.integration.config';

export default createFieldTestingConfig(3);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { createFieldTestingConfig } from '../base.jest.integration.config';

export default createFieldTestingConfig(4);

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import type { FtrConfigProviderContext } from '@kbn/test';

export default async function ({ readConfigFile }: FtrConfigProviderContext) {
const functionalConfig = await readConfigFile(
require.resolve('../../../configs/ess/rules_management.trial.config')
require.resolve('../../../../configs/ess/rules_management.trial.config')
);

const testConfig = {
...functionalConfig.getAll(),
testFiles: [require.resolve('..')],
junit: {
reportName:
'Rules Management - Prebuilt Rules (Customization Enabled) Integration Tests - ESS Env',
'Rules Management - Prebuilt Rules Customization (Customization Enabled) - ESS Env',
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
* 2.0.
*/

import { createCompleteTierTestConfig } from '../../../configs/serverless/rules_management.complete.config';
import { createCompleteTierTestConfig } from '../../../../configs/serverless/rules_management.complete.config';

export default createCompleteTierTestConfig({
testFiles: [require.resolve('..')],
junit: {
reportName:
'Rules Management - Prebuilt Rules (Customization Enabled) Integration Tests - Serverless Env',
'Rules Management - Prebuilt Rules Customization (Customization Enabled) - Serverless Env',
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import type { FtrProviderContext } from '../../../../../../ftr_provider_context';

export default ({ loadTestFile }: FtrProviderContext): void => {
loadTestFile(require.resolve('./detect_customization_with_base_version'));
loadTestFile(require.resolve('./detect_customization_without_base_version'));
loadTestFile(require.resolve('./customize_via_bulk_editing'));
loadTestFile(require.resolve('./unaffected_fields'));
describe('Rules Management - Prebuilt Rules Customization (Customization Enabled)', function () {
loadTestFile(require.resolve('./detect_customization_with_base_version'));
loadTestFile(require.resolve('./detect_customization_without_base_version'));
loadTestFile(require.resolve('./customize_via_bulk_editing'));
loadTestFile(require.resolve('./unaffected_fields'));
});
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { FtrConfigProviderContext } from '@kbn/test';

export default async function ({ readConfigFile }: FtrConfigProviderContext) {
const functionalConfig = await readConfigFile(
require.resolve('../../../../configs/ess/rules_management.trial.config')
);

const testConfig = {
...functionalConfig.getAll(),
testFiles: [require.resolve('..')],
junit: {
reportName:
'Rules Management - Prebuilt Rules Upgrade Notifications (Customization Enabled) - ESS Env',
},
};

return testConfig;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { createCompleteTierTestConfig } from '../../../../configs/serverless/rules_management.complete.config';

export default createCompleteTierTestConfig({
testFiles: [require.resolve('..')],
junit: {
reportName:
'Rules Management - Prebuilt Rules Upgrade Notifications (Customization Enabled) - Serverless Env',
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
import type { FtrProviderContext } from '../../../../../../ftr_provider_context';

export default ({ loadTestFile }: FtrProviderContext): void => {
loadTestFile(require.resolve('./get_prebuilt_rules_status'));
describe('Rules Management - Prebuilt Rules Upgrade Notifications (Customization Enabled)', function () {
loadTestFile(require.resolve('./get_prebuilt_rules_status'));
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { FtrConfigProviderContext } from '@kbn/test';

export default async function ({ readConfigFile }: FtrConfigProviderContext) {
const functionalConfig = await readConfigFile(
require.resolve('../../../../configs/ess/rules_management.trial.config')
);

const testConfig = {
...functionalConfig.getAll(),
testFiles: [require.resolve('..')],
junit: {
reportName: 'Rules Management - Prebuilt Rules Upgrade (Customization Enabled) - ESS Env',
},
};

return testConfig;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { createCompleteTierTestConfig } from '../../../../configs/serverless/rules_management.complete.config';

export default createCompleteTierTestConfig({
testFiles: [require.resolve('..')],
junit: {
reportName:
'Rules Management - Prebuilt Rules Upgrade (Customization Enabled) - Serverless Env',
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import type { FtrProviderContext } from '../../../../../../ftr_provider_context';

export default ({ loadTestFile }: FtrProviderContext): void => {
describe('Upgrade prebuilt rules', function () {
describe('Rules Management - Prebuilt Rules Upgrade (Customization Enabled)', function () {
loadTestFile(require.resolve('./review_prebuilt_rules_upgrade'));
loadTestFile(require.resolve('./bulk_upgrade_all_prebuilt_rules'));
loadTestFile(require.resolve('./bulk_upgrade_selected_prebuilt_rules'));
Expand Down