diff --git a/scripts/setup-test-site.sh b/scripts/setup-test-site.sh index e019ce0f7..078e296a2 100755 --- a/scripts/setup-test-site.sh +++ b/scripts/setup-test-site.sh @@ -123,15 +123,15 @@ create_test_credentials () { # Trash the post wp post delete "$TRASHED_POST_ID" - # Create a custom template - curl --user "$ADMIN_USERNAME":"$ADMIN_PASSWORD" -H "Content-Type: application/json" -d '{"slug":"INTEGRATION_TEST_CUSTOM_TEMPLATE", "content": "Integration test custom template content"}' http://localhost/wp-json/wp/v2/templates + echo "Creating a custom template for integration tests.." + curl --silent --user "$ADMIN_USERNAME":"$ADMIN_PASSWORD" -H "Content-Type: application/json" -d '{"slug":"INTEGRATION_TEST_CUSTOM_TEMPLATE", "content": "Integration test custom template content"}' http://localhost/wp-json/wp/v2/templates > /dev/null INTEGRATION_TEST_CUSTOM_TEMPLATE_ID="twentytwentyfour//integration_test_custom_template" - # Setup a post with post revisions for integration tests + echo "Setting up a post with 10 revisions for integration tests.." REVISIONED_POST_ID="$(wp post create --post_type=post --post_title=Revisioned_POST_FOR_INTEGRATION_TESTS --porcelain)" for i in {1..10}; do - curl --silent --user "$ADMIN_USERNAME":"$ADMIN_PASSWORD" -H "Content-Type: application/json" -d "{\"content\":\"content_revision_$i\", \"author\": $ADMIN_USER_ID}" "http://localhost/wp-json/wp/v2/posts/$REVISIONED_POST_ID" + curl --silent --user "$ADMIN_USERNAME":"$ADMIN_PASSWORD" -H "Content-Type: application/json" -d "{\"content\":\"content_revision_$i\", \"author\": $ADMIN_USER_ID}" "http://localhost/wp-json/wp/v2/posts/$REVISIONED_POST_ID" > /dev/null done # Generating revisions don't return an id, but since we just created the `REVISIONED_POST_ID`, we can use it to calculate the revision id REVISION_ID_FOR_REVISIONED_POST_ID=$((REVISIONED_POST_ID + 1)) diff --git a/wp_cli/src/lib.rs b/wp_cli/src/lib.rs index 09b0b923e..366c44c32 100644 --- a/wp_cli/src/lib.rs +++ b/wp_cli/src/lib.rs @@ -1,4 +1,9 @@ -use std::{collections::HashMap, ffi::OsStr, process::Command}; +use std::{ + collections::HashMap, + ffi::OsStr, + fs::File, + process::{Command, Stdio}, +}; mod wp_cli_categories; mod wp_cli_comments; @@ -17,7 +22,27 @@ pub use wp_cli_users::*; const BACKUP_PATH: &str = "/var/www/html/wp-content/dump.sql"; pub fn restore_db() -> std::process::Output { - run_wp_cli_command(["db", "import", BACKUP_PATH]) + Command::new("mariadb") + // Disable SSL to avoid connection errors + .arg("--skip-ssl") + // Host flag + .arg("-h") + // MySQL/MariaDB container hostname + .arg("database") + // Username flag + .arg("-u") + // Database username + .arg("wordpress") + // Database password + .arg("-pwordpress") + // Database name to connect to + .arg("wordpress") + // Pipe SQL dump file contents to stdin + .stdin(Stdio::from( + File::open(BACKUP_PATH).expect("Failed to open backup file"), + )) + .output() + .expect("Failed to restore db") } fn run_wp_cli_command(args: I) -> std::process::Output