BusyBird

 view release on metacpan or  search on metacpan

t/StatusStorage_SQLite.t  view on Meta::CPAN

use strict;
use warnings;
use Test::More;
use Test::Fatal;
use BusyBird::Test::StatusStorage qw(:storage :status);
use File::Temp 0.19;
use Test::MockObject::Extends;
use DBI;
use lib "t";
use testlib::Timeline_Util qw(sync status test_sets);
use testlib::StatusStorage::CrazyStatus qw(test_storage_crazy_statuses);

BEGIN {
    use_ok('BusyBird::StatusStorage::SQLite');
}

my %STORAGE_PATH_BUILDER = (
    file => sub { File::Temp->new(EXLOCK => 0) },
    memory => sub { ":memory:" },
);

sub create_storage {
    my ($type) = @_;
    my $path = $STORAGE_PATH_BUILDER{$type}->();
    my $storage = BusyBird::StatusStorage::SQLite->new(path => "$path");
    return ($path, $storage);
}

sub connect_db {
    my ($filename) = @_;
    my $dbh = DBI->connect("dbi:SQLite:dbname=$filename", "", "", {
        PrintError => 0, RaiseError => 1, AutoCommit => 1
    });
    $dbh->do(q{PRAGMA foreign_keys = ON});
    return $dbh;
}

sub test_sqlite {
    my ($storage_type) = @_;
    note("------------ test $storage_type");
    {
        my ($path, $storage) = create_storage($storage_type);
        test_storage_common($storage);
        test_storage_ordered($storage);
        test_storage_missing_arguments($storage);
        test_storage_requires_status_ids($storage);
        test_storage_undef_in_array($storage);
        test_storage_crazy_statuses($storage);
    }
    {
        my $path = $STORAGE_PATH_BUILDER{$storage_type}->();
        my $storage = BusyBird::StatusStorage::SQLite->new(
            path => "$path", max_status_num => 5, hard_max_status_num => 10
        );
        test_storage_truncation($storage, {soft_max => 5, hard_max => 10});
    }
    {
        note('------ vacuum_on_delete tests.');
        my $path = $STORAGE_PATH_BUILDER{$storage_type}->();
        my @vacuum_log = ();
        my $create_spied_storage = sub {
            my $storage = BusyBird::StatusStorage::SQLite->new(
                path => "$path",
                max_status_num => 10, hard_max_status_num => 20, vacuum_on_delete => 5



( run in 1.088 second using v1.01-cache-2.11-cpan-54e63673c56 )