Просмотр исходного кода

Fix #108, add version metrics to testrail-results

Also fixup POD, and add json output for defects
George S. Baugh 9 лет назад
Родитель
Сommit
534d2ccf79
4 измененных файлов с 36 добавлено и 3 удалено
  1. 1 0
      Changes
  2. 17 0
      bin/testrail-results
  3. 9 0
      lib/TestRail/Utils/Find.pm
  4. 9 3
      t/testrail-results.t

+ 1 - 0
Changes

@@ -9,6 +9,7 @@ Revision history for Perl module TestRail::API
     - Add finder callback to TestRail::Utils::FindTests
     - Add testsuite_id filter to TestRail::API::getChildRunByName
     - Add defect metrics to testrail-results
+    - Add version metrics to testrail-results
 
 0.037 2016-08-10 TEODESIAN
     - Fix incorrect POD for TestRail::API::createRunInPlan

+ 17 - 0
bin/testrail-results

@@ -63,6 +63,10 @@ All mandatory options not passed with the above switches, or in your ~/.testrail
 
 -g --grep    : Restrict results printed to those matching the provided pattern. Great for looking for specific failure conditions.
 
+-v --version : Restrict results printed to those tested on the provided version(s).  May be passed multiple times.
+
+-d --defect  : Restrict results printed to those related to the provided defect(s).  May be passed multiple times.
+
 -c --cachefile : Load the provided file as a place to pick up your search from.
 
 --json       : Print results as a JSON serialization.
@@ -127,6 +131,7 @@ sub run {
         'e|encoding=s'    => \$opts->{'encoding'},
         'g|grep=s'        => \$opts->{'pattern'},
         'd|defect=s@'     => \$opts->{'defects'},
+        'v|version=s@'    => \$opts->{'versions'},
         'c|cachefile=s'   => \$opts->{'cachefile'},
         'json'            => \$opts->{'json'},
         'h|help'          => \$opts->{'help'},
@@ -174,6 +179,7 @@ sub run {
         $out .= "#############################\n";
         my $num_runs = 0;
         my $casetotals = {};
+        my $versions_by_status = {};
         my $defects = [];
         my $total_elapsed = 0;
         my $avg_elapsed = 0;
@@ -187,12 +193,17 @@ sub run {
             #$out .= "Found case '$case' in run $casedef->{run_id}\n";
             foreach my $result (@{$casedef->{results}}) {
                 $casetotals->{$result->{status_id}}++;
+                $versions_by_status->{$result->{status_id}} //= [];
+                push(@{$versions_by_status->{$result->{status_id}}},$result->{version}) if $result->{version};
                 push(@$defects, @{$result->{defects}}) if $result->{defects};
                 push(@$elapsetotals,_elapsed2secs($result->{'elapsed'}));
             }
         }
         @$seen_runs = uniq(@$seen_runs);
         @$defects   = uniq(@$defects);
+        foreach my $st (keys(%$versions_by_status)) {
+            @{$versions_by_status->{$st}} = uniq(@{$versions_by_status->{$st}});
+        }
 
         my $pattern_output = '';
         $out_json->{$case}->{search_string} = $opts->{'pattern'};
@@ -227,7 +238,13 @@ sub run {
             $out_json->{$case}->{$status_map{$status}} = $casetotals->{$status};
         }
 
+        foreach my $status (keys(%$versions_by_status)) {
+            $out .= "Versions $status_map{$status} in:\n".join(',',@{$versions_by_status->{$status}})."\n";
+        }
+        $out_json->{$case}->{versions_by_status} = $versions_by_status;
+
         $out .= "\nDefects related to case:\n".join(',',@$defects)."\n" if @$defects;
+        $out_json->{$case}->{defects} = $defects;
 
     }
 

+ 9 - 0
lib/TestRail/Utils/Find.pm

@@ -410,6 +410,15 @@ sub getResults {
                     } @{$c->{results}};
                 }
 
+                #Filter by the provided versions, if any
+                if (ref($opts->{'versions'}) eq 'ARRAY' && scalar(@{$opts->{versions}})) {
+                    @{$c->{results}} = grep {
+                        my $version = $_->{version};
+                        any { $version eq $_ } @{$opts->{versions}};
+                    } @{$c->{results}};
+                }
+
+
                 push(@{$res->{$case}}, $c) if scalar(@{$c->{results}}); #Make sure they weren't filtered out
             }
         }

+ 9 - 3
t/testrail-results.t

@@ -9,7 +9,7 @@ require 'testrail-results';
 use lib $FindBin::Bin.'/lib';
 use Test::LWP::UserAgent::TestRailMock;
 
-use Test::More 'tests' => 24;
+use Test::More 'tests' => 26;
 use Capture::Tiny qw{capture_merged};
 use List::MoreUtils qw{uniq};
 
@@ -94,15 +94,21 @@ unlike($out,qr/Failed: 515/,"Gets correct # & status of runs with test inside it
 is($code, 0, "Exit code OK looking for results of fake.test in json mode");
 like($out,qr/num_runs/,"Gets # of runs with test inside it in json mode");
 
-#check defect filters
+#check defect & version filters
 {
     no warnings qw{redefine once};
     local *TestRail::API::getTestByName = sub { return { 'id' => '666', 'run_id' => 123, 'elapsed' => 1 } };
-    local *TestRail::API::getTestResults = sub { return [{ 'defects' => ['YOLO-666'], 'status_id' => 2  }, { 'defects' => undef, 'status_id' => 1 }] };
+    local *TestRail::API::getTestResults = sub { return [{ 'defects' => ['YOLO-666'], 'status_id' => 2, 'version' => 666  }, { 'defects' => undef, 'status_id' => 1, 'version' => 333 }] };
     @args = qw{--apiurl http://testrail.local --user test@fake.fake --password fake --defect YOLO-666 t/skip.test };
     ($out,$code) = TestRail::Bin::Results::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
     is($code, 0, "Exit code OK looking for defects of skip.test");
     like($out,qr/YOLO-666/,"Gets # of runs with defects inside it");
+
+    @args = qw{--apiurl http://testrail.local --user test@fake.fake --password fake --version 333 t/skip.test };
+    ($out,$code) = TestRail::Bin::Results::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
+    is($code, 0, "Exit code OK looking for version 333 for skip.test");
+    like($out,qr/333/,"Gets # of runs with version 333 inside it");
+
 }
 
 #For making the test data to test the caching