Skip to content

Commit 944fe30

Browse files
[FR] [DAC] Add Flag to Enable All Prebuilt Tests (#3684)
* Add flag to enable all prebuilt tests * Add additional bypasses * Added format_test_string function
1 parent 57af1bb commit 944fe30

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

detection_rules/custom_rules.py

+29-9
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,43 @@ def create_config_content() -> str:
4343
return yaml.safe_dump(config_content, default_flow_style=False)
4444

4545

46-
def create_test_config_content() -> str:
46+
def create_test_config_content(enable_prebuilt_tests: bool) -> str:
4747
"""Generate the content for the test_config.yaml with special content and references."""
48+
49+
def format_test_string(test_string: str, comment_char: str) -> str:
50+
"""Generate a yaml formatted string with a comment character."""
51+
return f"{comment_char} - {test_string}"
52+
53+
comment_char = "#" if enable_prebuilt_tests else ""
4854
example_test_config_path = DEFAULT_CONFIG_PATH.parent.joinpath("example_test_config.yaml")
49-
content = f"# For more details, refer to the example configuration:\n# {example_test_config_path}\n" \
50-
"# Define tests to explicitly bypass, with all others being run.\n" \
51-
"# To run all tests, set bypass to empty or leave this file commented out.\n\n" \
52-
"unit_tests:\n bypass:\n# - tests.test_all_rules.TestValidRules.test_schema_and_dupes\n" \
53-
"# - tests.test_packages.TestRegistryPackage.test_registry_package_config\n"
5455

55-
return content
56+
lines = [
57+
"# For more details, refer to the example configuration:",
58+
f"# {example_test_config_path}",
59+
"# Define tests to explicitly bypass, with all others being run.",
60+
"# To run all tests, set bypass to empty or leave this file commented out.",
61+
"",
62+
"unit_tests:",
63+
" bypass:",
64+
format_test_string("tests.test_gh_workflows.TestWorkflows.test_matrix_to_lock_version_defaults", comment_char),
65+
format_test_string(
66+
"tests.test_schemas.TestVersionLockSchema.test_version_lock_has_nested_previous", comment_char
67+
),
68+
format_test_string("tests.test_packages.TestRegistryPackage.test_registry_package_config", comment_char),
69+
format_test_string("tests.test_all_rules.TestValidRules.test_schema_and_dupes", comment_char),
70+
]
71+
72+
return "\n".join(lines)
5673

5774

5875
@custom_rules.command('setup-config')
5976
@click.argument('directory', type=Path)
6077
@click.argument('kibana-version', type=str, default=load_etc_dump('packages.yaml')['package']['name'])
6178
@click.option('--overwrite', is_flag=True, help="Overwrite the existing _config.yaml file.")
62-
def setup_config(directory: Path, kibana_version: str, overwrite: bool):
79+
@click.option(
80+
"--enable-prebuilt-tests", "-e", is_flag=True, help="Enable all prebuilt tests instead of default subset."
81+
)
82+
def setup_config(directory: Path, kibana_version: str, overwrite: bool, enable_prebuilt_tests: bool):
6383
"""Setup the custom rules configuration directory and files with defaults."""
6484

6585
config = directory / '_config.yaml'
@@ -111,7 +131,7 @@ def setup_config(directory: Path, kibana_version: str, overwrite: bool):
111131
package_config.write_text(yaml.safe_dump(package_content, default_flow_style=False))
112132

113133
# Create and configure test_config.yaml
114-
test_config.write_text(create_test_config_content())
134+
test_config.write_text(create_test_config_content(enable_prebuilt_tests))
115135

116136
# Create and configure _config.yaml
117137
config.write_text(create_config_content())

0 commit comments

Comments
 (0)