The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
use Test::More;

use strict;
use warnings;
use utf8;

use Dancer::Session::DBI;
use Dancer qw(:syntax :tests);
use DBI;

unless ( $ENV{TRAVIS_TESTING} ) {
    plan( skip_all => "Travis CI specific tests not required for installation" );
}

set session => 'DBI';

for my $config (
    {dsn => "DBI:mysql:database=myapp_test;host=127.0.0.1", user => "root"},
    {dsn => "DBI:Pg:dbname=myapp_test;host=127.0.0.1", user => "postgres"},
    {dsn => "DBI:SQLite:dbname=:memory:", user => "" }
) {

    my $dbh = DBI->connect($config->{dsn}, $config->{user}, "");

    # There is no way to reference an in-memory database created elsewhere
    # So the SQLite setup goes here.
    if (!$config->{user}) {
        $dbh->do("CREATE TABLE session (id char(72), session_data varchar(2048), PRIMARY KEY (id))");
    }

    set 'session_options' => {
        table => 'session',
        dbh   => sub { $dbh },
    };

    ok(session(testing => "123"), "Can something in the session " . $config->{user});
    is(session('testing'), '123', "Can retrieve something from the session " . $config->{user}); 
    ok(session(utf8 => "☃"), "Can set UTF8 " . $config->{user});
    is(session('utf8'), '☃', "Can get UTF8 back" . $config->{user});    
}

done_testing(12);