From 0f40e85185c4ec1173985b9c7bdb4b8a959ebff2 Mon Sep 17 00:00:00 2001 From: Andrew Matthews Date: Tue, 7 Jan 2025 18:12:28 -0500 Subject: [PATCH] [CICD-761] Add additional cases for generated exclude from rules Tests how different REMOTE_PATHS affect the generated exclude rule output. --- .../excludes/exclude_from_mu_plugins.txt | 34 +++++++++++++ ...exclude_from.txt => exclude_from_root.txt} | 0 .../exclude_from_safe_directories.txt | 21 ++++++++ .../excludes/exclude_from_wp_content.txt | 48 +++++++++++++++++++ tests/test_generate_path_excludes.sh | 38 ++++++++++----- 5 files changed, 128 insertions(+), 13 deletions(-) create mode 100644 tests/fixtures/excludes/exclude_from_mu_plugins.txt rename tests/fixtures/excludes/{exclude_from.txt => exclude_from_root.txt} (100%) create mode 100644 tests/fixtures/excludes/exclude_from_safe_directories.txt create mode 100644 tests/fixtures/excludes/exclude_from_wp_content.txt diff --git a/tests/fixtures/excludes/exclude_from_mu_plugins.txt b/tests/fixtures/excludes/exclude_from_mu_plugins.txt new file mode 100644 index 0000000..3900655 --- /dev/null +++ b/tests/fixtures/excludes/exclude_from_mu_plugins.txt @@ -0,0 +1,34 @@ +# Version Control +*~ +.git +.github +.gitignore +.DS_Store +.svn +.cvs +*.bak +*.swp +Thumbs.db + +# WordPress specific files +wp-config.php + +# WP Engine specific files and directories +.smushit-status +.gitattributes +.wpe-devkit/ +.wpengine-conf/ +_wpeprivate + +### Dynamic mu-plugin file and directory exclusions +/mu-plugin.php +/slt-force-strong-passwords.php +/wpengine-security-auditor.php +/stop-long-comments.php +/force-strong-passwords* +/wpengine-common* +/wpe-wp-sign-on-plugin* +/wpe-elasticpress-autosuggest-logger* +/wpe-cache-plugin* +/wp-cache-memcached* +/local-by-flywheel-live-link-helper.php diff --git a/tests/fixtures/excludes/exclude_from.txt b/tests/fixtures/excludes/exclude_from_root.txt similarity index 100% rename from tests/fixtures/excludes/exclude_from.txt rename to tests/fixtures/excludes/exclude_from_root.txt diff --git a/tests/fixtures/excludes/exclude_from_safe_directories.txt b/tests/fixtures/excludes/exclude_from_safe_directories.txt new file mode 100644 index 0000000..4a73205 --- /dev/null +++ b/tests/fixtures/excludes/exclude_from_safe_directories.txt @@ -0,0 +1,21 @@ +# Version Control +*~ +.git +.github +.gitignore +.DS_Store +.svn +.cvs +*.bak +*.swp +Thumbs.db + +# WordPress specific files +wp-config.php + +# WP Engine specific files and directories +.smushit-status +.gitattributes +.wpe-devkit/ +.wpengine-conf/ +_wpeprivate diff --git a/tests/fixtures/excludes/exclude_from_wp_content.txt b/tests/fixtures/excludes/exclude_from_wp_content.txt new file mode 100644 index 0000000..4f5d899 --- /dev/null +++ b/tests/fixtures/excludes/exclude_from_wp_content.txt @@ -0,0 +1,48 @@ +# Version Control +*~ +.git +.github +.gitignore +.DS_Store +.svn +.cvs +*.bak +*.swp +Thumbs.db + +# WordPress specific files +wp-config.php + +# WP Engine specific files and directories +.smushit-status +.gitattributes +.wpe-devkit/ +.wpengine-conf/ +_wpeprivate + +### Dynamic file and directory exclusions +/uploads/ +/blogs.dir/ +/upgrade/* +/backup-db/* +/advanced-cache.php +/wp-cache-config.php +/cache/* +/cache/supercache/* +/object-cache.php +/drop-ins/ +/drop-ins/wp-cache-memcached* +/mysql.sql + +### Dynamic mu-plugin file and directory exclusions +/mu-plugins/mu-plugin.php +/mu-plugins/slt-force-strong-passwords.php +/mu-plugins/wpengine-security-auditor.php +/mu-plugins/stop-long-comments.php +/mu-plugins/force-strong-passwords* +/mu-plugins/wpengine-common* +/mu-plugins/wpe-wp-sign-on-plugin* +/mu-plugins/wpe-elasticpress-autosuggest-logger* +/mu-plugins/wpe-cache-plugin* +/mu-plugins/wp-cache-memcached* +/mu-plugins/local-by-flywheel-live-link-helper.php diff --git a/tests/test_generate_path_excludes.sh b/tests/test_generate_path_excludes.sh index 38d4031..4ec9d09 100755 --- a/tests/test_generate_path_excludes.sh +++ b/tests/test_generate_path_excludes.sh @@ -38,21 +38,33 @@ test_determine_exclude_paths() { } test_generate_exclude_from() { - export REMOTE_PATH="" - local output - local expected_output + run_test_generate_exclude_from() { + export REMOTE_PATH=$1 + local output + local expected_output_file=$2 + local expected_output - output=$(generate_exclude_from) - expected_output=$(cat "tests/fixtures/excludes/exclude_from.txt") + output=$(generate_exclude_from) + expected_output=$(cat "${expected_output_file}") - if [[ "$output" != "$expected_output" ]]; then - echo -e "${RED}Test failed': generated output does not match expected output.${NC}" - echo -e "${BLUE}Generated output:${NC}" - echo "$output" - echo -e "${BLUE}Expected output:${NC}" - echo "$expected_output" - exit 1 - fi + if [[ "$output" != "$expected_output" ]]; then + echo -e "${RED}Test failed for REMOTE_PATH='${REMOTE_PATH}'': generated output does not match expected output.${NC}" + echo -e "${BLUE}Generated output:${NC}" + echo "$output" + echo -e "${BLUE}Expected output from ${expected_output_file}:${NC}" + echo "$expected_output" + exit 1 + fi + } + + run_test_generate_exclude_from "." "tests/fixtures/excludes/exclude_from_root.txt" + run_test_generate_exclude_from "" "tests/fixtures/excludes/exclude_from_root.txt" + run_test_generate_exclude_from "wp-content" "tests/fixtures/excludes/exclude_from_wp_content.txt" + run_test_generate_exclude_from "wp-content/" "tests/fixtures/excludes/exclude_from_wp_content.txt" + run_test_generate_exclude_from "wp-content/mu-plugins" "tests/fixtures/excludes/exclude_from_mu_plugins.txt" + run_test_generate_exclude_from "wp-content/mu-plugins/" "tests/fixtures/excludes/exclude_from_mu_plugins.txt" + run_test_generate_exclude_from "wp-content/plugins" "tests/fixtures/excludes/exclude_from_safe_directories.txt" + run_test_generate_exclude_from "wp-content/plugins/" "tests/fixtures/excludes/exclude_from_safe_directories.txt" echo -e "${GREEN}Test passed for generating exclude-from rules: generated output matches expected output.${NC}" }