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

NAME

BusyBird::Test::StatusStorage - Test routines for StatusStorage

SYNOPSIS

:storage tag functions

    use Test::More;
    use BusyBird::Test::StatusStorage qw(:storage);
    
    my $storage = My::StatusStorage->new();
    test_storage_common($storage);
    test_storage_ordered($storage);
    test_storage_truncation($storage, {soft_max => 25, hard_max => 50});
    done_testing();

:status tag functions

    use Test::More;
    use BusyBird::Test::StatusStorage qw(:status);
    
    $storage->get_statuses(
        timeline => "hoge", count => 10, callback => sub {
            my ($error, $got_statuses) = @_;
            is $error, undef, "it should succeed";
            test_status_id_set $got_statuses, ["id1", "id2", "id3"], "got status IDs OK";
        }
    );

DESCRIPTION

This module provides some functions mainly for testing StatusStorage objects.

This module exports the following functions only by request. The functions are categorized by tags.

If you want to import all functions, import :all tag.

:storage TAG FUNCTIONS

test_storage_common($storage, [$loop, $unloop])

Test the StatusStorage object. All StatusStorage implementations should pass this test.

$storage is the StatusStorage object to be tested. $loop is a subroutine reference to go into the event loop, $unloop is a subroutine reference to go out of the event loop. If the storage does not use any event loop mechanism, $loop and $unloop can be omitted.

In general test of statuses are based on status IDs. This allows implementations to modify statuses internally. In addition, statuses are tested unordered.

test_storage_ordered($storage, [$loop, $unloop])

Test the order of statuses obtained by get_statuses() method.

This test assumes the $storage conforms to the "Order of Statuses" in BusyBird::StatusStorage guideline. StatusStorage that does not conform to the guideline should not run this test.

The arguments are the same as test_storage_common function.

test_storage_truncation($storage, $options, [$loop, $unloop])

Test if statuses are properly truncated in the storage.

This test assumes the $storage passes test_storage_ordered() test. In each timeline, the "oldest" status should be removed first.

$storage is the StatusStorage object to be tested.

$options is a hash-ref. Fields in %$options are:

soft_max => INT (mandatory)

The number of statuses per timeline the storage guarantees to keep.

hard_max => INT (optional, default: same value as soft_max)

The number of statuses per timeline the storage is able to keep.

If the user tries to put more statuses than hard_max, the storage should automatically truncate the timeline so that the timeline has exactly soft_max statuses.

$loop and $unloop are the same as test_storage_common function.

test_storage_missing_arguments($storage, [$loop, $unloop])

Test if the $storage throws an exception when a mandatory argument is missing.

The arguments are the same as test_storage_common function.

test_storage_requires_status_ids($storage, [$loop, $unloop])

Test if the $storage throws an exception when some statuses given to put_statuses() methods do not have their id fields.

The arguments are the same as test_storage_common function.

test_storage_undef_in_array($storage, [$loop, $unloop])

Test if the $storage throws an exception when array arguments for various methods contain undef.

The arguments are the same as test_storage_common function.

:status TAG FUNCTIONS

test_status_id_set ($got_statuses, $exp_statuses_or_ids, $msg)

Test if the set of statuses is expected.

This function only checks IDs of given statuses. The test does not care about any other fields in statuses. This function does not care about the order of statuses either.

$got_statuses is an array-ref of status objects to be tested. $exp_statues_or_ids is an array-ref of status objects or IDs that are expected. $msg is the test message.

test_status_id_list ($got_statuses, $exp_statuses_or_ids, $msg)

Almost the same as the test_status_id_set function, but this test DOES care the order of statuses.

AUTHOR

Toshio Ito <toshioito [at] cpan.org>