2019-07-10 14:30:38 +00:00
#!/usr/bin/perl
use strict ;
use warnings ;
use Test::More tests = > 6 ;
# MySQL setup
my $ MYSQL_DIR = $ ENV { 'MYSQL_DIR' } ;
my $ MYSQL_UNIX_PORT = $ ENV { 'MYSQL_UNIX_PORT' } ;
my $ MYSQL_PIDFILE = $ ENV { 'MYSQL_PIDFILE' } ;
my $ MYSQL_USER = $ ENV { 'MYSQL_USER' } ;
chomp ( $ MYSQL_USER ) ;
# 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' } ;
my $ MYSQLD = '' ;
my $ mysql_version = readpipe ( "mysql --version" ) ;
if ( $ mysql_version =~ /MariaDB/ ) {
2020-02-04 11:59:30 +00:00
system ( "mysql_install_db --no-defaults --datadir=$MYSQL_DIR --force --skip-name-resolve --explicit_defaults_for_timestamp >/dev/null 2>&1" ) ;
2019-07-10 14:30:38 +00:00
ok ( $? >> 8 == 0 ) ;
$ MYSQLD = '/usr/libexec/mysqld' ;
} else {
$ MYSQLD = '/usr/sbin/mysqld' ;
system ( "$MYSQLD --no-defaults --initialize-insecure --datadir=$MYSQL_DIR --explicit_defaults_for_timestamp --user=$MYSQL_USER >/dev/null 2>&1" ) ;
ok ( $? >> 8 == 0 ) ;
}
my $ cmd = "$MYSQLD --no-defaults --user=$MYSQL_USER --socket=$MYSQL_UNIX_PORT --datadir=$MYSQL_DIR --pid-file=$MYSQL_PIDFILE --explicit_defaults_for_timestamp --skip-networking >/dev/null 2>&1 &" ;
my $ pid = fork ( ) ;
if ( defined ( $ pid ) && $ pid == 0 ) {
# background process
system ( $ cmd ) ;
exit $? >> 8 ;
}
my $ attempts = 0 ;
while ( system ( "/usr/bin/mysqladmin --user=root --socket=$MYSQL_UNIX_PORT ping >/dev/null 2>&1" ) != 0 ) {
sleep 3 ;
$ attempts + + ;
if ( $ attempts > 10 ) {
printf "skipping test, mariadb/mysql server could not be contacted after 30 seconds\n" ;
ok ( 0 ) ;
}
}
ok ( 1 ) ;
2020-02-04 11:59:30 +00:00
system ( "mysql --socket=$MYSQL_UNIX_PORT --execute \"CREATE USER '$DBD_MARIADB_TESTUSER\@localhost';\" 2>&1" ) ;
2019-07-10 14:30:38 +00:00
ok ( $? >> 8 == 0 ) ;
2020-02-04 11:59:30 +00:00
system ( "mysql --socket=$MYSQL_UNIX_PORT --execute \"CREATE DATABASE IF NOT EXISTS $DBD_MARIADB_TESTDB CHARACTER SET='utf8mb4';\" 2>&1" ) ;
2019-07-10 14:30:38 +00:00
ok ( $? >> 8 == 0 ) ;
2020-02-04 11:59:30 +00:00
system ( "mysql --socket=$MYSQL_UNIX_PORT --execute \"GRANT ALL PRIVILEGES ON $DBD_MARIADB_TESTDB.* TO '$DBD_MARIADB_TESTUSER\@localhost' IDENTIFIED BY '$DBD_MARIADB_TESTPASSWORD';\" 2>&1" ) ;
2019-07-10 14:30:38 +00:00
ok ( $? >> 8 == 0 ) ;
system ( "/usr/bin/mysqladmin --user=$DBD_MARIADB_TESTUSER --password=$DBD_MARIADB_TESTPASSWORD --socket=$DBD_MARIADB_TESTSOCKET ping >/dev/null 2>&1" ) ;
ok ( $? >> 8 == 0 ) ;