App-Config-Chronicle

 view release on metacpan or  search on metacpan

t/02_attribute.t  view on Meta::CPAN

use Test::Most 0.22 (tests => 7);
use Test::NoWarnings;

use App::Config::Chronicle::Attribute;
use Data::Hash::DotNotation;

throws_ok {
    App::Config::Chronicle::Attribute->new(
        name        => 'test',
        parent_path => 'apperturescience'
    );
}
qr/Attribute \(data_set\) is required/;

throws_ok {
    App::Config::Chronicle::Attribute->new(
        name        => 'test_attribute',
        parent_path => 'test.parent',
        data_set    => {version => 1},
        definition  => {
            isa     => 'ArrayRef',
            default => 'x',
        },
    )->build;
}
qr/ArrayRef/;

throws_ok {
    App::Config::Chronicle::Attribute->new(
        name        => 'json_string',
        parent_path => 'validation.tests',
        data_set    => {version => 1},
        definition  => {
            isa     => 'json_string',
            default => 'x',
        },
    )->build;
}

t/02_attribute.t  view on Meta::CPAN

    my $attribute = App::Config::Chronicle::Attribute->new(
        name        => 'array',
        parent_path => 'valudations.test',
        data_set    => {version => 1},
        definition  => {
            isa     => 'ArrayRef',
            default => ['1', '2', '3'],
        },
    )->build;

    throws_ok { $attribute->value('a'); } qr/ArrayRef/;
};

t/08_new_api.t  view on Meta::CPAN

    *Time::HiRes::time = \&Test::MockTime::time;
}

subtest 'Global revision = 0' => sub {
    my $app_config = _new_app_config();
    is $app_config->global_revision(), 0, 'Brand new app config returns 0 revision';
};

subtest 'Cannot externally set global_revision' => sub {
    my $app_config = _new_app_config();
    throws_ok {
        $app_config->set({'_global_rev' => 1});
    }
    qr/Cannot set with key/;
};

subtest 'Dynamic keys' => sub {
    my $app_config = _new_app_config();
    my @keys       = $app_config->dynamic_keys;
    is_deeply [sort @keys], [EMAIL_KEY, REFRESH_KEY], 'Keys are listed correctly';
};

t/08_new_api.t  view on Meta::CPAN


    ok my $res = $app_config->get([EMAIL_KEY, REFRESH_KEY]);
    is $res->{EMAIL_KEY()},   FIRST_EMAIL, 'Email is retrieved successfully';
    is $res->{REFRESH_KEY()}, REFRESH_SET, 'Refresh is retrieved successfully';
    exists $res->{'_global_rev'}, 'Batch get returns global revision';
};

subtest 'Gets/sets of illegal keys' => sub {
    subtest 'Attempt to set static key' => sub {
        my $app_config = _new_app_config();
        throws_ok {
            $app_config->set({ADMINS_KEY() => ADMINS_SET});
        }
        qr/Cannot set with key/;
    };

    subtest 'Attempt to set non-existent key' => sub {
        my $app_config = _new_app_config();
        throws_ok {
            $app_config->set({NON_EXT_KEY() => ADMINS_SET});
        }
        qr/Cannot set with key/;
    };

    subtest 'Attempt to get non-existent key' => sub {
        my $app_config = _new_app_config();
        throws_ok {
            $app_config->get(NON_EXT_KEY);
        }
        qr/Cannot get with key/;
    };
};

subtest 'History chronicling' => sub {
    my $app_config = _new_app_config();
    my $module     = Test::MockModule->new('Data::Chronicle::Reader');

t/08_new_api.t  view on Meta::CPAN

        $module->unmock('get_history');

        is $get_history_called, 2, 'get_history was called twice';
    };

    subtest 'Rev too old' => sub {
        is($app_config->get_history(EMAIL_KEY, 50), undef, 'Rev older than oldest returns undef');
    };

    subtest 'History of static key' => sub {
        throws_ok {
            $app_config->get_history(ADMINS_KEY, 1);
        }
        qr/Cannot get history/;
    };
};

subtest 'Perl level caching' => sub {
    subtest "Chronicle shouldn't be engaged with perl caching enabled" => sub {
        my $app_config = _new_app_config(local_caching => 1);



( run in 0.229 second using v1.01-cache-2.11-cpan-496ff517765 )