App-Prove-Plugin-Elasticsearch
view release on metacpan or search on metacpan
scripts/testrail-migrate.pl view on Meta::CPAN
#!/usr/bin/env perl
=head1 testrail_migrate.pl [OPTIONS] pattern1...patternN
Migrates TestRail test results into the test results database.
Only migrates tests from plans/runs with names matching the provided pattern. If no patterns are provided, all will be indexed.
Requires you have a functioning ~/.testrailrc (see L<App::Prove::Plugin::TestRail>), and ~/.elastest.conf (see L<App::Prove::Elasticsearch>).
=head2 OPTIONS
=over 4
=item B<--project>: Index plans only from the provided project(s). May be passed multiple times.
=item B<--only-last>: Only index the last result for a given test, such as ones that had to be re-run to pass.
=item B<--since>: Only index the plans which have been completed since the provided unix timestamp.
=item B<--ingest>: Keep ingesting new data over and over every 5 minutes. Allows you to enjoy (some of) the benefits of App::Prove::Elasticsearch without actually integrating it in your testsuite.
=back
=cut
package TestRail::Migrate2ES;
use strict;
use warnings;
use Getopt::Long qw{GetOptionsFromArray};
use TestRail::API();
use TestRail::Utils();
use File::HomeDir qw{my_home};
use List::Util qw{any reduce};
use POSIX qw{strftime};
use App::Prove::Elasticsearch::Utils;
use App::Prove::Elasticsearch::Indexer;
our $case_cache = {};
our $sec_cache = {};
if (!caller()) {
my %ARGS = main(@ARGV);
exit 0 unless delete $ARGS{ingest};
foreach my $k (keys(%ARGS)) { delete $ARGS{$k} unless $ARGS{$k}; }
my $extra_args = delete $ARGS{patterns};
my $projects = delete $ARGS{projects};
my $olast = delete $ARGS{'only-last'};
my @args = map { ("--$_" => $ARGS{$_}) } keys(%ARGS);
push(@args,'--only-last') if $olast;
push(@args,map { ('--project' => $_ ) } @$projects) if scalar(@$projects);
push(@args,('--ingest',@$extra_args));
print "Sleeping 5 minutes...\n";
sleep 300;
exec $0,@args;
}
sub main {
my @args = @_;
my $options;
GetOptionsFromArray(\@args,
'project=s@' => \$options->{projects},
'index-plan' => \$options->{'index-plan'},
'no-tests' => \$options->{'no-tests'},
'only-last' => \$options->{'only-last'},
'since=i' => \$options->{'since'},
ingest => \$options->{ingest},
);
my @patterns = @args;
my %ret = %$options;
$ret{'since'} = time(); #XXX this is imperfect, and could lead to double ingest, but --ingest shouldn't be used on a long term basis.
$ret{'patterns'} = \@patterns;
my $trconf = TestRail::Utils::parseConfig(my_home());
my $tr = TestRail::Utils::getHandle($trconf);
$tr->{step_field} = $trconf->{step_results};
$tr->{'only-last'} = $options->{'only-last'};
my $esconf = App::Prove::Elasticsearch::Utils::process_configuration();
my $indexer = App::Prove::Elasticsearch::Utils::require_indexer($esconf);
&{ \&{$indexer . "::check_index"} }($esconf);
$tr->{current_status_map} = [];
$tr->{current_status_map} = reduce {
my $ret;
$ret = $a;
$ret->{$b->{id}} = $b->{name};
$ret->{$a->{id}} = $a->{name};
$ret
} @{$tr->getPossibleTestStatuses()};
my $projects = $tr->getProjects();
@$projects = grep {my $subj = $_; any { $subj->{name} eq $_ } @{$options->{projects}} } @$projects if scalar(@{$options->{projects}});
foreach my $project (@$projects) {
my $runs = $tr->getRuns($project->{id});
( run in 2.654 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )