App-Ikaros

 view release on metacpan or  search on metacpan

lib/App/Ikaros.pm  view on Meta::CPAN

package App::Ikaros;
use 5.008_001;
use strict;
use warnings;
use parent qw/Class::Accessor::Fast/;
use App::Ikaros::Config::Loader;
use App::Ikaros::Planner;
use App::Ikaros::LandingPoint;
use App::Ikaros::Builder;
use App::Ikaros::Reporter;
use App::Ikaros::PathMaker qw/prove lib_dir/;
use Data::Dumper;

our $VERSION = '0.02';

__PACKAGE__->mk_accessors(qw/
    hosts
    config
    tests
    output_filename
    enable_profile
    verbose
    recovery_testing_command
/);

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

    my $loaded_conf = App::Ikaros::Config::Loader->new({
        config         => $options->{config},
        config_type    => $options->{config_type},
        config_options => $options->{config_options}
    })->load;

    my $ikaros = $class->SUPER::new({
        config   => $loaded_conf,
        hosts    => [],
        verbose  => $options->{verbose},
        enable_profile  => $options->{enable_profile},
        output_filename => $options->{output_filename}
    });

    $ikaros->__setup_landing_points;
    $ikaros->__planning;
    return $ikaros;
}

sub __setup_landing_points {
    my ($self) = @_;
    my $default = $self->config->{default};
    foreach my $host (@{$self->config->{hosts}}) {
        push @{$self->hosts}, App::Ikaros::LandingPoint->new($default, $host);
    }
}

sub __planning {
    my ($self) = @_;
    my $plan = $self->config->{plan};
    my $planner = App::Ikaros::Planner->new($self->hosts, $plan);
    $planner->planning($_, $plan) foreach @{$self->hosts};
    $self->tests([ @{$plan->{prove_tests}}, @{$plan->{forkprove_tests}} ]);
    $self->__setup_recovery_testing_command($plan);
}

sub __setup_recovery_testing_command {
    my ($self, $args) = @_;
    my $lib = lib_dir 'App/Prove.pm';
    my @prove_commands = map {
        ($_ =~ /\$prove/) ? ("-I$lib", prove) : $_;
    } @{$args->{prove_command}};
    $self->recovery_testing_command(\@prove_commands);
}

sub launch {
    my ($self, $callback) = @_;
    my $builder = App::Ikaros::Builder->new;
    $builder->rsync($self->hosts, $self->config->{plan}{rsync});
    $builder->build($self->hosts);
    my $failed_tests = App::Ikaros::Reporter->new({
        verbose => $self->verbose,
        tests   => $self->tests,
        enable_profile  => $self->enable_profile,
        output_filename => $self->output_filename,
        recovery_testing_command => $self->recovery_testing_command
    })->report($self->hosts);
    return &$callback($failed_tests);
}

1;

__END__

=head1 NAME

App::Ikaros - distributed testing framework for jenkins



( run in 0.976 second using v1.01-cache-2.11-cpan-3c2a17b8caa )