Merge pull request #25923 from woocommerce/fix/test-install-db-socket

Correct usage of database sockets in test install script
This commit is contained in:
Christopher Allford 2020-03-17 09:08:18 -07:00 committed by GitHub
commit 917e5ff77d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 19 deletions

View File

@ -128,24 +128,22 @@ install_db() {
return 0
fi
# parse DB_HOST for port or socket references
local PARTS=(${DB_HOST//\:/ })
local DB_HOSTNAME=${PARTS[0]};
local DB_SOCK_OR_PORT=${PARTS[1]};
local EXTRA=""
if ! [ -z $DB_HOSTNAME ] ; then
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
EXTRA=" --socket=$DB_SOCK_OR_PORT"
elif ! [ -z $DB_HOSTNAME ] ; then
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
# If we're trying to connect to a socket we want to handle it differently.
if [[ "$DB_HOST" == *.sock ]]; then
# create database using the socket
mysqladmin create $DB_NAME --socket="$DB_HOST"
else
# Decide whether or not there is a port.
local PARTS=(${DB_HOST//\:/ })
if [[ ${PARTS[1]} =~ ^[0-9]+$ ]]; then
EXTRA=" --host=${PARTS[0]} --port=${PARTS[1]} --protocol=tcp"
else
EXTRA=" --host=$DB_HOST --protocol=tcp"
fi
fi
# create database
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
# create database
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
fi
}
install_wp

View File

@ -42,7 +42,7 @@ class WC_Unit_Tests_Bootstrap {
$this->tests_dir = dirname( __FILE__ );
$this->plugin_dir = dirname( $this->tests_dir );
$this->wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : '/tmp/wordpress-tests-lib';
$this->wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : sys_get_temp_dir() . '/wordpress-tests-lib';
// load test function so tests_add_filter() is available.
require_once $this->wp_tests_dir . '/includes/functions.php';

View File

@ -5,5 +5,5 @@
* @package WooCommerce\UnitTests
*/
$wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : '/tmp/wordpress-tests-lib';
$wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : sys_get_temp_dir() . '/wordpress-tests-lib';
require_once $wp_tests_dir . '/includes/listener-loader.php';

View File

@ -55,7 +55,7 @@ class WC_Tests_MaxMind_Database extends WC_Unit_Test_Case {
*/
public function test_download_database_works() {
$database_service = new WC_Integration_MaxMind_Database_Service( '' );
$expected_database = '/tmp/GeoLite2-Country_20200100/GeoLite2-Country.mmdb';
$expected_database = sys_get_temp_dir() . '/GeoLite2-Country_20200100/GeoLite2-Country.mmdb';
$result = $database_service->download_database( 'testing_license' );