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
16 changes: 16 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ jobs:
- name: Run tests
run: DOD_TEST_DRIVER=MySQL prove -lr -j4 t

mariadb:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: perl -V
run: perl -V
- name: setup mariadb repo
run: curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
- name: apt-get
run: sudo apt-get update && sudo apt-get install -y libmariadb-dev mariadb-server
- name: Install dependencies
run: curl -sL https://git.io/cpm | sudo perl - install -g --with-recommends --with-test --with-configure --show-build-log-on-failure --feature=test_mariadb
- name: Run tests
run: DOD_TEST_DRIVER=MariaDB prove -lr -j4 t

postgresql:
runs-on: ubuntu-latest

Expand Down
6 changes: 6 additions & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ feature 'test_mysql', 'Test MySQL' => sub {
requires 'SQL::Translator';
};

feature 'test_mariadb', 'Test MariaDB' => sub {
requires 'DBD::MariaDB';
requires 'Test::mysqld';
requires 'SQL::Translator';
};

feature 'test_postgresql', 'Test PostgreSQL' => sub {
requires 'DBD::Pg';
requires 'Test::PostgreSQL';
Expand Down
10 changes: 10 additions & 0 deletions lib/Data/ObjectDriver/Driver/DBD/MariaDB.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# $Id$

package Data::ObjectDriver::Driver::DBD::MariaDB;
use strict;
use warnings;
use base qw( Data::ObjectDriver::Driver::DBD::mysql );

sub fetch_id { $_[3]->{mariadb_insertid} || $_[3]->{insertid} }

1;
28 changes: 24 additions & 4 deletions t/lib/DodTestUtil.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ our @EXPORT = qw/setup_dbs teardown_dbs disconnect_all/;
my %Requires = (
SQLite => 'DBD::SQLite',
MySQL => 'Test::mysqld',
MariaDB => 'Test::mysqld',
PostgreSQL => 'Test::PostgreSQL',
Oracle => 'DBD::Oracle',
SQLServer => 'DBD::ODBC',
Expand Down Expand Up @@ -51,20 +52,38 @@ sub db_filename {
$dbname . $$ . '.db';
}

my $test_mysqld_dsn;
sub dsn {
my($dbname) = @_;
my $driver = driver();
if ( my $dsn = env('DOD_TEST_DSN', $dbname) ) {
return "$dsn;dbname=$dbname";
}
if ( $driver eq 'MySQL' ) {
if ( $driver =~ /MySQL|MariaDB/ ) {
if ( $driver eq 'MariaDB' && !$test_mysqld_dsn ) {
my $help = `mysql --help`;
my ($mariadb_version) = $help =~ /\A.*?([0-9]+\.[0-9]+)\.[0-9]+\-MariaDB/;
no warnings 'redefine';
$test_mysqld_dsn = \&Test::mysqld::dsn;
*Test::mysqld::dsn = sub {
my $dsn = $test_mysqld_dsn->(@_);
# cf. https://github.com/kazuho/p5-test-mysqld/issues/32
$dsn =~ s/;user=root// if $mariadb_version && $mariadb_version > 10.3;
$dsn;
};
}
$TestDB{$dbname} ||= Test::mysqld->new(
my_cnf => {
'skip-networking' => '', # no TCP socket
'sql-mode' => 'TRADITIONAL,NO_AUTO_VALUE_ON_ZERO,ONLY_FULL_GROUP_BY',
}
) or die $Test::mysqld::errstr;
return $TestDB{$dbname}->dsn;
my $dsn = $TestDB{$dbname}->dsn;
if ( $driver eq 'MariaDB' ) {
$dsn =~ s/^dbi:mysql/dbi:MariaDB/i;
$dsn =~ s/mysql_/mariadb_/ig;
}
return $dsn;
}
if ( $driver eq 'PostgreSQL' ) {
$TestDB{$dbname} ||= Test::PostgreSQL->new(
Expand All @@ -86,8 +105,8 @@ sub setup_dbs {
for my $dbname (keys %$info) {
my $dbh = DBI->connect(
dsn($dbname),
env('DOD_TEST_USER', $dbname),
env('DOD_TEST_PASS', $dbname),
env('DOD_TEST_USER', $dbname) || undef,
env('DOD_TEST_PASS', $dbname) || undef,
{ RaiseError => 1, PrintError => 0, ShowErrorStatement => 1 });
for my $table (@{ $info->{$dbname} }) {
$dbh->do($_) for create_sql($table);
Expand Down Expand Up @@ -138,6 +157,7 @@ sub disconnect_all {
sub create_sql {
my($table) = @_;
my $driver = driver();
$driver = 'MySQL' if $driver eq 'MariaDB';
my $file = File::Spec->catfile('t', 'schemas', $table . '.sql');
open my $fh, $file or die "Can't open $file: $!";
my $sql = do { local $/; <$fh> };
Expand Down