App-Prove-Plugin-Elasticsearch

 view release on metacpan or  search on metacpan

t/App-Prove-Elasticsearch-Planner-Default.t  view on Meta::CPAN


    no warnings qw{redefine once};
    local *Search::Elasticsearch::exists = sub { return 1 };
    use warnings;
    is(App::Prove::Elasticsearch::Planner::Default::add_plan_to_index(), 0, "add_plan_to_index returns 0 in the event of success");

}

UPDATE_PLAN: {
    no warnings qw{redefine once};
    local *Search::Elasticsearch::update = sub {
        shift;
        my %in = @_;

        foreach my $test ( @{$in{body}{doc}{tests}} ) {
            print "$test ";
        }
        print "#\n";
        return { result => 'sadness came to us' };
    };
    use warnings;
    $App::Prove::Elasticsearch::Planner::Default::e = bless( {} , "Search::Elasticsearch");

    my $plan = {
        update => {
            addition => {
                tests => [
                    'zippy.test'
                ]
            },
            subtraction => {
                tests => [
                    'happy.test'
                ]
            },
        },
        tests => [ 'happy.test','chompy.test' ],
        id => 666,
    };
    my $res;
    my $out = capture_merged { $res = App::Prove::Elasticsearch::Planner::Default::_update_plan($plan) };
    is($res,1,"_update_plan returns 1 on failure");
    like($out,qr/^chompy.test zippy.test #/i,"Correct tests sent to update");

    no warnings qw{redefine once};
    local *Search::Elasticsearch::update = sub {
        return { result => 'noop' };
    };
    use warnings;
    is(App::Prove::Elasticsearch::Planner::Default::_update_plan($plan),0,"_update_plan returns 0 on success");
}

MAKE_PLAN: {
    $App::Prove::Elasticsearch::Planner::Default::e = undef;
    like(exception {App::Prove::Elasticsearch::Planner::Default::make_plan()}, qr/es object not defined/i, "make_plan requires check_index be run first");
    $App::Prove::Elasticsearch::Planner::Default::e = bless( {} , "Search::Elasticsearch");

    my %out = (
        pairwise => 1,
        show => 1,
        prompt => 1,
        allplatforms => 1,
        exts => 1,
        recurse => 1,
        name => undef,
        tests => ['zippy'],
    );

    my $expected = {
        pairwise => 'true',
        tests    => ['zippy'],
    };

    is_deeply(App::Prove::Elasticsearch::Planner::Default::make_plan(%out),$expected,"make_plan sanitizes: no name, pairwise => true & noop => 0");

    $out{pairwise} = 0;
    $expected->{pairwise} = 'false';
    $out{tests} = [];
    $expected->{tests} = [];
    $expected->{noop} = 1;
    $out{name} = 'eee';
    $expected->{name} = 'eee';

    is_deeply(App::Prove::Elasticsearch::Planner::Default::make_plan(%out),$expected,"make_plan sanitizes: name, pairwise => false & noop => 1");

}

MAKE_PLAN_UPDATE: {
    $App::Prove::Elasticsearch::Planner::Default::e = undef;
    like(exception {App::Prove::Elasticsearch::Planner::Default::make_plan_update()}, qr/es object not defined/i, "make_plan_update requires check_index be run first");
    $App::Prove::Elasticsearch::Planner::Default::e = bless( {} , "Search::Elasticsearch");

    my $existing = {
        tests     => ['hoosafudge'],
    };

    my %out = (
        tests => ['zippy'],
    );

    my $expected = {
        tests    => ['hoosafudge'],
        update   => {
            addition    => { tests => ['zippy'] },
            subtraction => { tests => ['hoosafudge'] },
        }
    };

    is_deeply(App::Prove::Elasticsearch::Planner::Default::make_plan_update($existing,%out),$expected,"make_plan_update mongles: test add & sub & noop => 0");

    $out{tests}        = ['zippy'];
    $existing->{tests} = ['zippy'];
    $expected->{tests} = ['zippy'];
    delete $existing->{update};
    delete $expected->{update};
    $expected->{noop} = 1;

    is_deeply(App::Prove::Elasticsearch::Planner::Default::make_plan_update($existing,%out),$expected,"make_plan_update mongles: noop => 1");

}



( run in 0.735 second using v1.01-cache-2.11-cpan-6aa56a78535 )