Ver código fonte

Fix #31: make configuration filtering actually work

George S. Baugh 10 anos atrás
pai
commit
92b1461d2c
4 arquivos alterados com 20 adições e 7 exclusões
  1. 4 0
      Changes
  2. 1 1
      dist.ini
  3. 12 4
      lib/TestRail/API.pm
  4. 3 2
      t/TestRail-API.t

+ 4 - 0
Changes

@@ -1,5 +1,9 @@
 Revision history for Perl module TestRail::API
 
+0.021 2015-04-07 TEODESIAN
+    - Fix issue where getChildRuns did not return anything past first run
+    - Fix issue where getChildRunByName did not perform configuration filtering correctly
+
 0.020 2015-03-25 TEODESIAN
     - Add getRunsPaginated and getPlansPaginated to get around 250 hardlimit in TR results
     - Modify getRuns and getPlans to use the above to actually get all runs/plans

+ 1 - 1
dist.ini

@@ -1,6 +1,6 @@
 name = TestRail-API
 main_module = lib/TestRail/API.pm
-version = 0.020
+version = 0.021
 author = George S. Baugh <teodesian@cpan.org>
 license = Perl_5
 copyright_holder = George S. Baugh

+ 12 - 4
lib/TestRail/API.pm

@@ -1179,8 +1179,10 @@ sub getChildRuns {
     confess("Object methods must be called by an instance") unless ref($self);
     confess("Plan must be HASHREF") unless defined($plan) && (reftype($plan) || 'undef') eq 'HASH';
     return 0 unless defined($plan->{'entries'}) && (reftype($plan->{'entries'}) || 'undef') eq 'ARRAY';
-    return 0 unless defined($plan->{'entries'}->[0]->{'runs'}) && (reftype($plan->{'entries'}->[0]->{'runs'}) || 'undef') eq 'ARRAY';
-    return $plan->{'entries'}->[0]->{'runs'};
+    return 0 unless defined($plan->{'entries'}) && (reftype($plan->{'entries'}) || 'undef') eq 'ARRAY';
+    my $entries = $plan->{'entries'};
+    my @plans = map { $_->{'runs'}->[0] } @$entries; #XXX not sure if this list-ification is intentional
+    return \@plans;
 }
 
 =head2 B<getChildRunByName(plan,name,configurations)>
@@ -1217,12 +1219,18 @@ sub getChildRunByName {
         my ($cname);
         @pconfigs = map {$_->{'id'}} grep { $cname = $_->{'name'}; grep {$_ eq $cname} @$configurations } @$avail_configs; #Get a list of IDs from the names passed
     }
+    my $found;
     foreach my $run (@$runs) {
+        next if $run->{name} ne $name;
+        next if scalar(@pconfigs) ne scalar(@{$run->{'config_ids'}});
+
         #Compare run config IDs against desired, invalidate run if all conditions not satisfied
+        $found = 0;
         foreach my $cid (@{$run->{'config_ids'}}) {
-            next unless List::Util::all {$_ eq $cid} @pconfigs;
+            $found++ if grep {$_ == $cid} @pconfigs;
         }
-        return $run if $run->{name} eq $name;
+
+        return $run if $found == scalar(@{$run->{'config_ids'}});
     }
     return 0;
 }

+ 3 - 2
t/TestRail-API.t

@@ -4,7 +4,7 @@ use warnings;
 use TestRail::API;
 use Test::LWP::UserAgent::TestRailMock;
 
-use Test::More tests => 59;
+use Test::More tests => 60;
 use Test::Fatal;
 use Scalar::Util 'reftype';
 use ExtUtils::MakeMaker qw{prompt};
@@ -114,7 +114,8 @@ is($tr->getPlanByID($new_plan->{'id'})->{'id'},$new_plan->{'id'},"Can get plan b
 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");
-isnt($tr->getChildRunByName($namePlan,"Executing the great plan")->{'id'},undef,"Getting run by name returns child runs");
+isnt($tr->getChildRunByName($namePlan,"Executing the great plan",['Chrome']),0,"Getting run by name returns child runs");
+is($tr->getChildRunByName($namePlan,"Executing the great plan"),0,"Getting run by name without sufficient configuration data returns child runs");
 
 #Test createRunInPlan
 my $updatedPlan = $tr->createRunInPlan($new_plan->{'id'},$new_suite->{'id'},'Dynamic Plan Run');