2019-07-10 14:30:38 +00:00
#!/usr/bin/perl
use strict ;
use warnings ;
2020-04-17 09:18:50 +00:00
use Test::More tests = > 7 ;
2019-07-10 14:30:38 +00:00
# MySQL setup
2023-10-20 08:16:10 +00:00
my $ MARIADB_DIR = $ ENV { 'MARIADB_DIR' } ;
my $ MARIADB_UNIX_PORT = $ ENV { 'MARIADB_UNIX_PORT' } ;
my $ MARIADB_PIDFILE = $ ENV { 'MARIADB_PIDFILE' } ;
my $ MARIADB_USER = $ ENV { 'MARIADB_USER' } ;
chomp ( $ MARIADB_USER ) ;
2019-07-10 14:30:38 +00:00
# DBD::MariaDB test setup
my $ DBD_MARIADB_TESTDB = $ ENV { 'DBD_MARIADB_TESTDB' } ;
my $ DBD_MARIADB_TESTHOST = $ ENV { 'DBD_MARIADB_TESTHOST' } ;
my $ DBD_MARIADB_TESTSOCKET = $ ENV { 'DBD_MARIADB_TESTSOCKET' } ;
my $ DBD_MARIADB_TESTUSER = $ ENV { 'DBD_MARIADB_TESTUSER' } ;
my $ DBD_MARIADB_TESTPASSWORD = $ ENV { 'DBD_MARIADB_TESTPASSWORD' } ;
2023-10-20 08:16:10 +00:00
system ( "mariadb-install-db --no-defaults --datadir=$MARIADB_DIR --force --skip-name-resolve --explicit_defaults_for_timestamp >/dev/null 2>&1" ) ;
is ( $? , 0 ) ;
2019-07-10 14:30:38 +00:00
2023-10-20 08:16:10 +00:00
my $ cmd = "mariadbd --no-defaults --user=$MARIADB_USER --socket=$MARIADB_UNIX_PORT --datadir=$MARIADB_DIR --pid-file=$MARIADB_PIDFILE --explicit_defaults_for_timestamp --skip-networking >/dev/null 2>&1 &" ;
2020-04-17 09:18:50 +00:00
system ( $ cmd ) ;
is ( $? , 0 ) ;
2019-07-10 14:30:38 +00:00
my $ attempts = 0 ;
2023-10-20 08:16:10 +00:00
while ( system ( "mariadb-admin --user=root --socket=$MARIADB_UNIX_PORT ping >/dev/null 2>&1" ) != 0 ) {
2019-07-10 14:30:38 +00:00
sleep 3 ;
$ attempts + + ;
if ( $ attempts > 10 ) {
2020-04-17 09:18:50 +00:00
fail ( "skipping test, mariadb/mysql server could not be contacted after 30 seconds\n" ) ;
2019-07-10 14:30:38 +00:00
}
}
ok ( 1 ) ;
2023-10-20 08:16:10 +00:00
system ( "mariadb --socket=$MARIADB_UNIX_PORT --execute \"CREATE USER '$DBD_MARIADB_TESTUSER\@localhost';\" 2>&1" ) ;
2020-04-17 09:18:50 +00:00
is ( $? , 0 ) ;
2023-10-20 08:16:10 +00:00
system ( "mariadb --socket=$MARIADB_UNIX_PORT --execute \"CREATE DATABASE IF NOT EXISTS $DBD_MARIADB_TESTDB CHARACTER SET='utf8mb4';\" 2>&1" ) ;
2020-04-17 09:18:50 +00:00
is ( $? , 0 ) ;
2023-10-20 08:16:10 +00:00
system ( "mariadb --socket=$MARIADB_UNIX_PORT --execute \"GRANT ALL PRIVILEGES ON $DBD_MARIADB_TESTDB.* TO '$DBD_MARIADB_TESTUSER\@localhost' IDENTIFIED BY '$DBD_MARIADB_TESTPASSWORD';\" 2>&1" ) ;
2020-04-17 09:18:50 +00:00
is ( $? , 0 ) ;
2023-10-20 08:16:10 +00:00
system ( "mariadb-admin --user=$DBD_MARIADB_TESTUSER --password=$DBD_MARIADB_TESTPASSWORD --socket=$DBD_MARIADB_TESTSOCKET ping >/dev/null 2>&1" ) ;
2020-04-17 09:18:50 +00:00
is ( $? , 0 ) ;