Skip to content

Commit

Permalink
[CICD-761] Add additional cases for generated exclude from rules
Browse files Browse the repository at this point in the history
Tests how different REMOTE_PATHS affect the generated exclude
rule output.
  • Loading branch information
apmatthews committed Jan 7, 2025
1 parent 632088c commit 0f40e85
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 13 deletions.
34 changes: 34 additions & 0 deletions tests/fixtures/excludes/exclude_from_mu_plugins.txt
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
21 changes: 21 additions & 0 deletions tests/fixtures/excludes/exclude_from_safe_directories.txt
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions tests/fixtures/excludes/exclude_from_wp_content.txt
Original file line number Diff line number Diff line change
@@ -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
38 changes: 25 additions & 13 deletions tests/test_generate_path_excludes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
Expand Down

0 comments on commit 0f40e85

Please sign in to comment.