Skip to content

Commit 1658f1e

Browse files
authored
Fix database restore SSL issues and improve test setup logging (#862)
* Fix database restore to use mariadb client directly Replace wp-cli database import with mariadb client to avoid SSL connection errors. The mariadb client with --skip-ssl flag properly handles the database connection without requiring SSL certificates. Changes: - Update restore_db function to use mariadb client instead of wp-cli - Add proper stdin handling for SQL dump file import - Add necessary imports for File and Stdio * Improve log output for make test-server command Suppress verbose curl responses during WordPress setup to reduce log clutter while preserving error messages for debugging. Added descriptive echo statements to track setup progress. Changes: - Redirect curl stdout to /dev/null for template creation - Redirect curl stdout to /dev/null for post revision generation - Add progress messages for template and revision setup steps * Add comments to wp_cli::restore_db * Combine password flag in restore_db
1 parent 57d2846 commit 1658f1e

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

scripts/setup-test-site.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ create_test_credentials () {
123123
# Trash the post
124124
wp post delete "$TRASHED_POST_ID"
125125

126-
# Create a custom template
127-
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
126+
echo "Creating a custom template for integration tests.."
127+
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
128128
INTEGRATION_TEST_CUSTOM_TEMPLATE_ID="twentytwentyfour//integration_test_custom_template"
129129

130-
# Setup a post with post revisions for integration tests
130+
echo "Setting up a post with 10 revisions for integration tests.."
131131
REVISIONED_POST_ID="$(wp post create --post_type=post --post_title=Revisioned_POST_FOR_INTEGRATION_TESTS --porcelain)"
132132
for i in {1..10};
133133
do
134-
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"
134+
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
135135
done
136136
# 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
137137
REVISION_ID_FOR_REVISIONED_POST_ID=$((REVISIONED_POST_ID + 1))

wp_cli/src/lib.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
use std::{collections::HashMap, ffi::OsStr, process::Command};
1+
use std::{
2+
collections::HashMap,
3+
ffi::OsStr,
4+
fs::File,
5+
process::{Command, Stdio},
6+
};
27

38
mod wp_cli_categories;
49
mod wp_cli_comments;
@@ -17,7 +22,27 @@ pub use wp_cli_users::*;
1722
const BACKUP_PATH: &str = "/var/www/html/wp-content/dump.sql";
1823

1924
pub fn restore_db() -> std::process::Output {
20-
run_wp_cli_command(["db", "import", BACKUP_PATH])
25+
Command::new("mariadb")
26+
// Disable SSL to avoid connection errors
27+
.arg("--skip-ssl")
28+
// Host flag
29+
.arg("-h")
30+
// MySQL/MariaDB container hostname
31+
.arg("database")
32+
// Username flag
33+
.arg("-u")
34+
// Database username
35+
.arg("wordpress")
36+
// Database password
37+
.arg("-pwordpress")
38+
// Database name to connect to
39+
.arg("wordpress")
40+
// Pipe SQL dump file contents to stdin
41+
.stdin(Stdio::from(
42+
File::open(BACKUP_PATH).expect("Failed to open backup file"),
43+
))
44+
.output()
45+
.expect("Failed to restore db")
2146
}
2247

2348
fn run_wp_cli_command<I, S>(args: I) -> std::process::Output

0 commit comments

Comments
 (0)