Blame SOURCES/test-setup.t

81dc9f
#!/usr/bin/perl
81dc9f
81dc9f
use strict;
81dc9f
use warnings;
81dc9f
81dc9f
use Test::More tests => 7;
81dc9f
81dc9f
# MySQL setup
81dc9f
my $MYSQL_DIR       = $ENV{'MYSQL_DIR'};
81dc9f
my $MYSQL_UNIX_PORT = $ENV{'MYSQL_UNIX_PORT'};
81dc9f
my $MYSQL_PIDFILE   = $ENV{'MYSQL_PIDFILE'};
81dc9f
my $MYSQL_USER      = $ENV{'MYSQL_USER'};
81dc9f
chomp($MYSQL_USER);
81dc9f
81dc9f
# DBD::MariaDB test setup
81dc9f
my $DBD_MARIADB_TESTDB       = $ENV{'DBD_MARIADB_TESTDB'};
81dc9f
my $DBD_MARIADB_TESTHOST     = $ENV{'DBD_MARIADB_TESTHOST'};
81dc9f
my $DBD_MARIADB_TESTSOCKET   = $ENV{'DBD_MARIADB_TESTSOCKET'};
81dc9f
my $DBD_MARIADB_TESTUSER     = $ENV{'DBD_MARIADB_TESTUSER'};
81dc9f
my $DBD_MARIADB_TESTPASSWORD = $ENV{'DBD_MARIADB_TESTPASSWORD'};
81dc9f
81dc9f
my $MYSQLD = '';
81dc9f
my $mysql_version = readpipe("mysql --version");
81dc9f
if ($mysql_version =~ /MariaDB/) {
81dc9f
    system("mysql_install_db --no-defaults --datadir=$MYSQL_DIR --force --skip-name-resolve --explicit_defaults_for_timestamp >/dev/null 2>&1");
81dc9f
    is($?, 0);
81dc9f
    $MYSQLD = '/usr/libexec/mysqld';
81dc9f
} else {
81dc9f
    $MYSQLD = '/usr/sbin/mysqld';
81dc9f
    system("$MYSQLD --no-defaults --initialize-insecure --datadir=$MYSQL_DIR --explicit_defaults_for_timestamp --user=$MYSQL_USER >/dev/null 2>&1");
81dc9f
    is($?, 0);
81dc9f
}
81dc9f
81dc9f
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 &";
81dc9f
system($cmd);
81dc9f
is($?, 0);
81dc9f
81dc9f
my $attempts = 0;
81dc9f
while (system("/usr/bin/mysqladmin --user=root --socket=$MYSQL_UNIX_PORT ping >/dev/null 2>&1") != 0) {
81dc9f
    sleep 3;
81dc9f
    $attempts++;
81dc9f
    if ($attempts > 10) {
81dc9f
        fail("skipping test, mariadb/mysql server could not be contacted after 30 seconds\n");
81dc9f
    }
81dc9f
}
81dc9f
ok(1);
81dc9f
81dc9f
system("mysql --socket=$MYSQL_UNIX_PORT --execute \"CREATE USER '$DBD_MARIADB_TESTUSER\@localhost';\" 2>&1");
81dc9f
is($?, 0);
81dc9f
system("mysql --socket=$MYSQL_UNIX_PORT --execute \"CREATE DATABASE IF NOT EXISTS $DBD_MARIADB_TESTDB CHARACTER SET='utf8mb4';\" 2>&1");
81dc9f
is($?, 0);
81dc9f
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");
81dc9f
is($?, 0);
81dc9f
system("/usr/bin/mysqladmin --user=$DBD_MARIADB_TESTUSER --password=$DBD_MARIADB_TESTPASSWORD --socket=$DBD_MARIADB_TESTSOCKET ping >/dev/null 2>&1");
81dc9f
is($?, 0);