Prechádzať zdrojové kódy

Fix #112: allow testsuite_id filtering in TestRail::API::getChildRunByName

George S. Baugh 9 rokov pred
rodič
commit
1533ba934f
3 zmenil súbory, kde vykonal 10 pridanie a 5 odobranie
  1. 1 0
      Changes
  2. 6 3
      lib/TestRail/API.pm
  3. 3 2
      t/TestRail-API.t

+ 1 - 0
Changes

@@ -7,6 +7,7 @@ Revision history for Perl module TestRail::API
     - Don't override filename in TAP Parser if we already have it
     - Fix issue where non-standard status overrides were not possible
     - Add finder callback to TestRail::Utils::FindTests
+    - Add testsuite_id filter to TestRail::API::getChildRunByName
 
 0.037 2016-08-10 TEODESIAN
     - Fix incorrect POD for TestRail::API::createRunInPlan

+ 6 - 3
lib/TestRail/API.pm

@@ -1399,7 +1399,7 @@ sub getChildRuns {
     return $plans;
 }
 
-=head2 B<getChildRunByName(plan,name,configurations)>
+=head2 B<getChildRunByName(plan,name,configurations,testsuite_id)>
 
 =over 4
 
@@ -1409,6 +1409,8 @@ sub getChildRuns {
 
 =item ARRAYREF C<CONFIGURATIONS> (optional) - Names of configurations to filter runs by.
 
+=item INTEGER C<TESTSUITE_ID> (optional) - Filter by the provided Testsuite ID.  Helpful for when child runs have duplicate names, but are from differing testsuites.
+
 =back
 
 Returns run definition HASHREF, or false if no such run is found.
@@ -1419,10 +1421,11 @@ Will throw a fatal error if one or more of the configurations passed does not ex
 =cut
 
 sub getChildRunByName {
-    state $check = compile(Object, HashRef, Str, Optional[Maybe[ArrayRef[Str]]]);
-    my ($self,$plan,$name,$configurations) = $check->(@_);
+    state $check = compile(Object, HashRef, Str, Optional[Maybe[ArrayRef[Str]]], Optional[Maybe[Int]]);
+    my ($self,$plan,$name,$configurations,$testsuite_id) = $check->(@_);
 
     my $runs = $self->getChildRuns($plan);
+    @$runs = grep {$_->{suite_id} == $testsuite_id}  @$runs if $testsuite_id;
     return 0 if !$runs;
 
     my @pconfigs = ();

+ 3 - 2
t/TestRail-API.t

@@ -7,7 +7,7 @@ use lib "$FindBin::Bin/lib";
 use TestRail::API;
 use Test::LWP::UserAgent::TestRailMock;
 
-use Test::More tests => 88;
+use Test::More tests => 89;
 use Test::Fatal;
 use Test::Deep;
 use Scalar::Util ();
@@ -155,7 +155,8 @@ is($tr->getPlanByID($new_plan->{'id'})->{'id'},$new_plan->{'id'},"Can get plan b
 #Get runs per plan, create runs in plan
 my $prun = $new_plan->{'entries'}->[0]->{'runs'}->[0];
 is($tr->getRunByID($prun->{'id'})->{'name'},"Executing the great plan","Can get child run of plan by ID");
-is($tr->getChildRunByName($new_plan,"Executing the great plan")->{'id'},$prun->{'id'},"Can find child run of plan by name");
+is($tr->getChildRunByName($new_plan,"Executing the great plan", [], 9)->{'id'},$prun->{'id'},"Can find child run of plan by name filtering by testsuite");
+is($tr->getChildRunByName($new_plan,"Executing the great plan", [], 8),0,"Can't find child run of plan by name filtering by (bad) testsuite");
 
 SKIP: {
     skip("Cannot create configurations programattically in the API like in mocks",2) if !$is_mock;