App-Prove-Plugin-Elasticsearch

 view release on metacpan or  search on metacpan

lib/App/Prove/Elasticsearch/Planner/Default.pm  view on Meta::CPAN

    return 0;
}

sub make_plan {
    my (%options) = @_;
    die "check_index not run, ES object not defined!" unless $e;

    my %out = %options;
    $out{pairwise} = $out{pairwise} ? "true" : "false";
    delete $out{show};
    delete $out{prompt};
    delete $out{allplatforms};
    delete $out{exts};
    delete $out{recurse};
    delete $out{name} unless $out{name};

    $out{noop} = 1 unless scalar(@{$out{tests}});

    return \%out;
}

lib/App/ape/plan.pm  view on Meta::CPAN


sub new {
    my ($class, @args) = @_;

    my (%options, @conf, $help);
    GetOptionsFromArray(
        \@args,
        'platform=s@'   => \$options{platforms},
        'version=s'     => \$options{version},
        'show'          => \$options{show},
        'prompt'        => \$options{prompt},
        'pairwise'      => \$options{pairwise},
        'all-platforms' => \$options{allplatforms},
        'recurse'       => \$options{recurse},
        'extension=s@'  => \$options{exts},
        'name'          => \$options{name},
        'requeue'       => \$options{requeue},
        'replay'        => \$options{replay},
        'help'          => \$help,
    );
    $options{platforms} //= [];

lib/App/ape/plan.pm  view on Meta::CPAN

    pod2usage(0) if $help;

    if (!$options{version}) {
        pod2usage(
            -exitval => "NOEXIT",
            -msg     => "Insufficient arguments.  You must pass --version.",
        );
        return 2;
    }

    if ($options{prompt} && $options{show}) {
        pod2usage(
            -exitval => "NOEXIT",
            -msg =>
              "--prompt and --show are mutually exclusive options.  You must pass one or the other.",
        );
        return 3;
    }

    #Store platform groups in the configuration to differentiate further plans
    my $conf = App::Prove::Elasticsearch::Utils::process_configuration(@conf);

    if (
        scalar(
            grep {

lib/App/ape/plan.pm  view on Meta::CPAN

            $plan->{replay} = $self->{cases} if $self->{options}{replay};

            #Get the state of the plan
            $plan->{state} = [];
            @{$plan->{state}} = &{\&{$self->{planner} . "::get_plan_status"}}
              ($plan, $self->{searcher});

            _print_plan($plan, 1);
            next;
        }
        if ($self->{options}{prompt}) {
            _print_plan($plan);
            if (!$plan->{noop}) {
                IO::Prompter::prompt("Do you want to enact the above changes?")
                  or next;
            } else {
                (
                    IO::Prompter::prompt("Do you want to re-queue the plan?")
                      or next
                ) unless $self->{options}{requeue};
                $self->{queue}->{requeue} = 1;
                $queue_result += $self->{queue}->queue_jobs($plan);
                next;
            }
        }

        #Ensure bogus data doesn't get into ES
        delete $plan->{replay};

lib/App/ape/plan.pm  view on Meta::CPAN

Tests passed which cannot be found will be ignored.
If no tests are passed, any tests in t/ will be used by default.

=head2 optional switches

=over 4

=item B<--show> - display the proposed plan instead of creating it, and whether or not it already exists (or will be modified by passed arguments).
If the plan already exists, the execution status of the relevant tests will also be displayed.

=item B<--prompt> - display proposed modifications to a plan (if any) will be made on the server.

=item B<--pairwise> - If configured with platform groups (see below), consider the plan satisfied if each platform passed appears at least once.
In the event that a plan update is made, tests will be properly apportioned upon update.

=item B<--all-platforms> - If configured with platform groups, use all those available rather than passing manually with --platform.

=item B<--name> - If you want to differentiate your run from others with the same versions/platforms, use this.

=item B<--recurse> - if passing directories of tests, recurse past the first level to find tests.

=item B<--extension> - If passing directories, check for tests with these extensions.  May be passed multiple times, defaults to t

=item B<--requeue> - Re-queue an existing plan, in case something didn't quite work out.  Use to suppress prompts about re-queueing in --prompt mode.

=item B<--replay> - Dump the body of the test(s) associated when in --show mode.  Filter the tests displayed by passing test names.

=back

=head1 CONFIGURATION

Aside from the usual configuration from L<App::Prove::Plugin::Elasticsearch>,
you can add a new section to describe mutually exclusive platforms (combinations, for my fellow math geeks out there).

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

}

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'],

t/App-ape-plan.t  view on Meta::CPAN

use parent qw{Test::Class};
use Test::More;
use Test::Fatal;
use Test::Deep;
use Capture::Tiny qw{capture};

use App::ape::plan;

sub test_new : Test(5) {
    is(App::ape::plan->new(),2,"No args returns bad exit code");
    is(App::ape::plan->new(qw{--version 666 --show --prompt}),3,"Bad exit code returned due to incompatible options");

    no warnings qw{redefine once};
    local *App::Prove::Elasticsearch::Utils::process_configuration = sub{return {}};
    use warnings;

    is(App::ape::plan->new(qw{--version 666}),4,"Bad exit code returned due to insufficient configuration");

    no warnings qw{redefine once};
    local *App::Prove::Elasticsearch::Utils::process_configuration = sub {return { 'server.host' => 'bogus', 'server.port' => 'bogus'}};
    local *App::Prove::Elasticsearch::Utils::require_platformer = sub { return 'Grape::Ape::BananaBoat' };

t/App-ape-plan.t  view on Meta::CPAN

    my $expected = {
       'allplatforms' => undef,
       'exts' => [
         '.t'
       ],
       'name' => undef,
       'pairwise' => undef,
       'platforms' => [
         'zippy'
       ],
       'prompt' => undef,
       'recurse' => undef,
       'replay' => undef,
       'requeue' => undef,
       'show' => undef,
       'version' => '666'
    };

    isa_ok($obj,"App::ape::plan");
    is_deeply($obj->{options},$expected,"args appear to parse correctly");
}

t/App-ape-plan.t  view on Meta::CPAN

       cases => [],
       options => {
            show => 1,
            requeue => 1,
       },
    },"App::ape::plan");

    is( $test_obj->run(), 0, "Can run all the way through OK in --show mode");

    $test_obj->{options}{show} = 0;
    $test_obj->{options}{prompt} = 0;

    no warnings qw{redefine once};
    local *Banana::In::Tailpipe::add_plan_to_index = sub { return 0 };
    local *Banana::In::Tailpipe::queue_jobs = sub { return 0 };
    use warnings;

    is( $test_obj->run(), 0, "Can run all the way through OK in no-show no-prompt mode");

    $test_obj->{options}{prompt} = 1;
    $test_obj->{options}{requeue} = 0;

    no warnings qw{redefine once};
    local *IO::Prompter::prompt = sub { return 1 };
    use warnings;

    is( $test_obj->run(), 0, "Can run all the way through OK in prompt mode: noop");

    no warnings qw{redefine once};
    local *App::ape::plan::_build_plans = sub { return ( { noop => 0 } ) };
    use warnings;

    is( $test_obj->run(), 0, "Can run all the way through OK in prompt mode: normal execution");

    no warnings qw{redefine once};
    local *Banana::In::Tailpipe::add_plan_to_index = sub { return 1 };
    local *Banana::In::Tailpipe::queue_jobs = sub { return 1 };
    use warnings;

    is( $test_obj->run(), 2, "Can run all the way through and get bad exit code when add plan/queue fails");

}



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