Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions scripts/setup-test-site.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
29 changes: 27 additions & 2 deletions wp_cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the password passed twice: -pwordpress wordpress?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second one is the database name. I've added comments to each argument in df9de22.

It's not great to have these be part of the Rust file, but I really don't want to spend any more time on the setup right now and would rather finish the features I am working on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting -pwordpress in df9de22 didn't work, which should be addressed in 34892fc.

// 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<I, S>(args: I) -> std::process::Output
Expand Down