Kaynağa Gözat

Fix #61: change spawn to testsuite_id, allow testsuite name parameter

George S. Baugh 10 yıl önce
ebeveyn
işleme
6c08841b8b

+ 3 - 1
Changes

@@ -6,7 +6,9 @@ Revision history for Perl module TestRail::API
     - Update getRunSummary and getPlanSummary to use 'labels' rather than system names
     - Add TestRail::API::statusNamesToLabels to ease interaction with above method updates
     - Change TestRail::API::translateConfigNamesToIds to accept ARRAY arguments
-    - make above function and TestRail::API::sectionNamesToIds return values in correct order
+    - Make above function and TestRail::API::sectionNamesToIds return values in correct order
+    - Change the 'spawn' option in Test::Rail::Parser (and it's callers) to be --testsuite_id
+    - Add a --testsuite (name) option to Test::Rail::Parser
 
 0.030 2015-07-31 TEODESIAN
     - Fix testrail-tests, was calling function in incorrect namespace

+ 7 - 3
bin/testrail-report

@@ -46,11 +46,13 @@ This should provide sufficient uniqueness to get any run using names.
 
 =head3 OPTIONAL PARAMETERS
 
-    --spawn [testsuite_id] : Attempt to create a run based on the provided testsuite ID.  Uses the name provided with --run.
+    --testsuite_id [testsuite_id] : Attempt to create a run based on the provided testsuite ID.  Uses the name provided with --run.
       If plans/configurations are supplied, it will attempt to create it as a child of the provided plan, and with the supplied configurations.
       If the specified run already exists, the program will simply use the existing run, and disregard the supplied testsuite_id.
       If the specified plan does not exist, it too will be created for you.
 
+    --testsuite [testsuite name] : Pretty much the same as the testsuite_id, but a name instead.  Mutually exclusive with testsuite_id.
+
     --section [section_name] : When spawning, restrict the cases used in the provided testsuite ID to these sections.
       Option may be passed multiple times to specify multiple sections.
 
@@ -127,7 +129,8 @@ GetOptions(
     'config=s@'      => \$opts{configs},
     'plan=s'         => \$opts{plan},
     'version=s'      => \$opts{version},
-    'spawn=i'        => \$opts{spawn},
+    'testsuite_id=i' => \$opts{testsuite_id},
+    'testsuite=s'    => \$opts{testsuite},
     'section=s@'     => \$opts{sections},
     'autoclose'      => \$opts{autoclose},
     'e|encoding=s'   => \$opts{encoding},
@@ -177,7 +180,8 @@ foreach my $phil (@files) {
         'plan'           => $opts{plan},
         'configs'        => $opts{configs},
         'result_options' => $opts{result_options},
-        'spawn'          => $opts{spawn},
+        'testsuite_id'   => $opts{testsuite_id},
+        'testsuite'      => $opts{testsuite},
         'sections'       => $opts{sections},
         'autoclose'      => $opts{autoclose},
         'encoding'       => $opts{encoding},

+ 2 - 1
lib/App/Prove/Plugin/TestRail.pm

@@ -95,7 +95,8 @@ sub load {
     $ENV{'TESTRAIL_VERSION'}   = $params->{version};
     $ENV{'TESTRAIL_CASEOK'}    = $params->{case_per_ok};
     $ENV{'TESTRAIL_STEPS'}     = $params->{step_results};
-    $ENV{'TESTRAIL_SPAWN'}     = $params->{spawn};
+    $ENV{'TESTRAIL_SPAWN'}     = $params->{testsuite_id};
+    $ENV{'TESTRAIL_TESTSUITE'} = $params->{testsuite};
     $ENV{'TESTRAIL_SECTIONS'}  = $params->{sections};
     $ENV{'TESTRAIL_AUTOCLOSE'} = $params->{autoclose};
     $ENV{'TESTRAIL_ENCODING'}  = $params->{encoding};

+ 2 - 1
lib/Test/Rail/Harness.pm

@@ -55,7 +55,8 @@ sub make_parser {
     $args->{'result_options'} = {'version' => $ENV{'TESTRAIL_VERSION'}} if $ENV{'TESTRAIL_VERSION'};
     $args->{'case_per_ok'}    = $ENV{'TESTRAIL_CASEOK'};
     $args->{'step_results'}   = $ENV{'TESTRAIL_STEPS'};
-    $args->{'spawn'}          = $ENV{'TESTRAIL_SPAWN'};
+    $args->{'testsuite_id'}   = $ENV{'TESTRAIL_SPAWN'};
+    $args->{'testsuite'}      = $ENV{'TESTRAIL_TESTSUITE'};
 
     @sections = split(/:/,$ENV{'TESTRAIL_SECTIONS'}) if $ENV{'TESTRAIL_SECTIONS'};
     $args->{'sections'}  = \@sections if scalar(@sections);

+ 20 - 9
lib/Test/Rail/Parser.pm

@@ -73,7 +73,9 @@ Get the TAP Parser ready to talk to TestRail, and register a bunch of callbacks
 
 =item B<custom_options> - HASHREF (optional): Custom options to set with your result.  See L<TestRail::API>'s createTestResults function for more information.  step_results will be set here, if the option is passed.
 
-=item B<spawn> - INTEGER (optional): Attempt to create a run based on the provided testsuite identified by the ID passed here.  If plan/configs is passed, create it as a child of said plan with the listed configs.  If the run exists, use it and disregard the provided testsuite ID.  If the plan does not exist, create it too.
+=item B<testsuite> - STRING (optional): Attempt to create a run based on the testsuite identified by the name passed here.  If plan/configs are passed, create it as a child of said plan with the listed configs.  If the run exists, use it and disregard this option.  If the containing plan does not exist, create it too.  Mutually exclusive with 'testsuite_id'.
+
+=item B<testsuite_id> - INTEGER (optional): Attempt to create a run based on the testsuite identified by the ID passed here.  If plan/configs are passed, create it as a child of said plan with the listed configs.  If the run exists, use it and disregard this option.  If the plan does not exist, create it too.  Mutually exclusive with 'testsuite'.
 
 =item B<sections> - ARRAYREF (optional): Restrict a spawned run to cases in these particular sections.
 
@@ -131,7 +133,8 @@ sub new {
         'case_per_ok'  => delete $opts->{'case_per_ok'},
         'plan'         => delete $opts->{'plan'},
         'configs'      => delete $opts->{'configs'} // [],
-        'spawn'        => delete $opts->{'spawn'},
+        'testsuite_id' => delete $opts->{'testsuite_id'},
+        'testsuite'    => delete $opts->{'testsuite'},
         'encoding'     => delete $opts->{'encoding'},
         'sections'     => delete $opts->{'sections'},
         'autoclose'    => delete $opts->{'autoclose'},
@@ -183,6 +186,14 @@ sub new {
     $tropts->{'todo_pass'} = $todop[0];
     $tropts->{'retest'}    = $retest[0];
 
+    confess "testsuite and testsuite_id are mutually exclusive" if ( $tropts->{'testsuite_id'} && $tropts->{'testsuite'});
+    #Grab testsuite by name if needed
+    if ($tropts->{'testsuite'}) {
+        my $ts = $tr->getTestSuiteByName($tropts->{'project_id'},$tropts->{'testsuite'});
+        confess("No such testsuite '".$tropts->{'testsuite'}."' found!") unless $ts;
+        $tropts->{'testsuite_id'} = $ts->{'id'};
+    }
+
     #Grab run
     my $run_id = $tropts->{'run_id'};
     my ($run,$plan,$config_ids);
@@ -207,8 +218,8 @@ sub new {
                 }
             } else {
                 #Try to make it if spawn is passed
-                $tropts->{'plan'} = $tr->createPlan($tropts->{'project_id'},$tropts->{'plan'},"Test plan created by TestRail::API");
-                confess("Could not find plan ".$tropts->{'plan'}." in provided project, and spawning failed!") if !$tropts->{'plan'};
+                $tropts->{'plan'} = $tr->createPlan($tropts->{'project_id'},$tropts->{'plan'},"Test plan created by TestRail::API") if $tropts->{'testsuite_id'};
+                confess("Could not find plan ".$tropts->{'plan'}." in provided project, and spawning failed (or was not indicated)!") if !$tropts->{'plan'};
             }
         } else {
             $run = $tr->getRunByName($tropts->{'project_id'},$tropts->{'run'});
@@ -222,16 +233,16 @@ sub new {
     }
 
     #If spawn was passed and we don't have a Run ID yet, go ahead and make it
-    if ($tropts->{'spawn'} && !$tropts->{'run_id'}) {
+    if ($tropts->{'testsuite_id'} && !$tropts->{'run_id'}) {
         print "# Spawning run\n";
         my $cases = [];
         if ($tropts->{'sections'}) {
             print "# with specified sections\n";
             #Then translate the sections into an array of case IDs.
             confess("Sections passed to spawn must be ARRAYREF") unless (reftype($tropts->{'sections'}) || 'undef') eq 'ARRAY';
-            @{$tropts->{'sections'}} = $tr->sectionNamesToIds($tropts->{'project_id'},$tropts->{'spawn'},@{$tropts->{'sections'}});
+            @{$tropts->{'sections'}} = $tr->sectionNamesToIds($tropts->{'project_id'},$tropts->{'testsuite_id'},@{$tropts->{'sections'}});
             foreach my $section (@{$tropts->{'sections'}}) {
-                my $section_cases = $tr->getCases($tropts->{'project_id'},$tropts->{'spawn'},{ 'section_id' => $section });
+                my $section_cases = $tr->getCases($tropts->{'project_id'},$tropts->{'testsuite_id'},{ 'section_id' => $section });
                 push(@$cases,@$section_cases) if (reftype($section_cases) || 'undef') eq 'ARRAY';
             }
         }
@@ -244,14 +255,14 @@ sub new {
 
         if ($tropts->{'plan'}) {
             print "# inside of plan\n";
-            $plan = $tr->createRunInPlan( $tropts->{'plan'}->{'id'}, $tropts->{'spawn'}, $tropts->{'run'}, undef, $config_ids, $cases );
+            $plan = $tr->createRunInPlan( $tropts->{'plan'}->{'id'}, $tropts->{'testsuite_id'}, $tropts->{'run'}, undef, $config_ids, $cases );
             $run = $plan->{'runs'}->[0] if exists($plan->{'runs'}) && (reftype($plan->{'runs'}) || 'undef') eq 'ARRAY' && scalar(@{$plan->{'runs'}});
             if (defined($run) && (reftype($run) || 'undef') eq 'HASH') {
                 $tropts->{'run'} = $run;
                 $tropts->{'run_id'} = $run->{'id'};
             }
         } else {
-            $run = $tr->createRun( $tropts->{'project_id'}, $tropts->{'spawn'}, $tropts->{'run'}, "Automatically created Run from TestRail::API", undef, undef, $cases );
+            $run = $tr->createRun( $tropts->{'project_id'}, $tropts->{'testsuite_id'}, $tropts->{'run'}, "Automatically created Run from TestRail::API", undef, undef, $cases );
             if (defined($run) && (reftype($run) || 'undef') eq 'HASH') {
                 $tropts->{'run'} = $run;
                 $tropts->{'run_id'} = $run->{'id'};

+ 3 - 3
t/App-Prove-Plugin-Testrail.t

@@ -29,17 +29,17 @@ is (exception {$prove->run()},undef,"Running TR parser case via plugin functions
 #Check that spawn options make it through
 
 $prove = App::Prove->new();
-$prove->process_args("-PTestRail=apiurl=http://some.testlink.install/,user=someUser,password=somePassword,project=TestProject,run=TestingSuite2,version=0.014,case_per_ok=1,spawn=9",'t/skipall.test');
+$prove->process_args("-PTestRail=apiurl=http://some.testlink.install/,user=someUser,password=somePassword,project=TestProject,run=TestingSuite2,version=0.014,case_per_ok=1,testsuite_id=9",'t/skipall.test');
 
 is (exception {$prove->run()},undef,"Running TR parser case via plugin functions works with configs/plans");
 
 $prove = App::Prove->new();
-$prove->process_args("-PTestRail=apiurl=http://some.testlink.install/,user=someUser,password=somePassword,project=TestProject,plan=bogoPlan,run=bogoRun,version=0.014,case_per_ok=1,spawn=9",'t/skipall.test');
+$prove->process_args("-PTestRail=apiurl=http://some.testlink.install/,user=someUser,password=somePassword,project=TestProject,plan=bogoPlan,run=bogoRun,version=0.014,case_per_ok=1,testsuite=HAMBURGER-IZE HUMANITY",'t/skipall.test');
 
 is (exception {$prove->run()},undef,"Running TR parser spawns both runs and plans");
 
 $prove = App::Prove->new();
-$prove->process_args("-PTestRail=apiurl=http://some.testlink.install/,user=someUser,password=somePassword,project=TestProject,run=bogoRun,version=0.014,case_per_ok=1,spawn=9,sections=fake.test:CARBON LIQUEFACTION",'t/fake.test');
+$prove->process_args("-PTestRail=apiurl=http://some.testlink.install/,user=someUser,password=somePassword,project=TestProject,run=bogoRun,version=0.014,case_per_ok=1,testsuite_id=9,sections=fake.test:CARBON LIQUEFACTION",'t/fake.test');
 
 is (exception {$prove->run()},undef,"Running TR parser can discriminate by sections correctly");
 

+ 13 - 13
t/Test-Rail-Parser.t

@@ -297,7 +297,7 @@ $res = exception {
         'plan'                => 'mah dubz plan',
         'configs'             => ['testPlatform1'],
         'project'             => 'TestProject',
-        'spawn'               => 9,
+        'testsuite_id'        => 9,
         'merge'               => 1
     });
 };
@@ -322,7 +322,7 @@ $res = exception {
         'browser'             => $browser,
         'run'                 => 'TestingSuite2',
         'project'             => 'TestProject',
-        'spawn'               => 9,
+        'testsuite'           => 'HAMBURGER-IZE HUMANITY',
         'merge'               => 1
     });
 };
@@ -347,7 +347,7 @@ $res = exception {
         'run'                 => 'BogoRun',
         'plan'                => 'BogoPlan',
         'project'             => 'TestProject',
-        'spawn'               => 9,
+        'testsuite_id'        => 9,
         'merge'               => 1
     });
 };
@@ -372,7 +372,7 @@ $res = exception {
         'run'                 => 'BogoRun',
         'plan'                => 'BogoPlan',
         'project'             => 'TestProject',
-        'spawn'               => 9,
+        'testsuite_id'        => 9,
         'merge'               => 1,
         'case_per_ok'         => 1,
         'step_results'        => 'sr_step_results'
@@ -393,7 +393,7 @@ $res = exception {
         'run'                 => 'BogoRun',
         'project'             => 'TestProject',
         'merge'               => 1,
-        'spawn'               => 9,
+        'testsuite_id'        => 9,
         'sections'            => ['fake.test'],
         'case_per_ok'         => 1
     });
@@ -420,7 +420,7 @@ $res = exception {
         'plan'                => 'BogoPlan',
         'project'             => 'TestProject',
         'merge'               => 1,
-        'spawn'               => 9,
+        'testsuite_id'        => 9,
         'sections'            => ['fake.test'],
         'case_per_ok'         => 1
     });
@@ -445,7 +445,7 @@ $res = exception {
         'run'                 => 'BogoRun',
         'project'             => 'TestProject',
         'merge'               => 1,
-        'spawn'               => 9,
+        'testsuite_id'        => 9,
         'sections'            => ['potzrebie'],
         'case_per_ok'         => 1
     });
@@ -464,7 +464,7 @@ $res = exception {
         'run'                 => 'BogoRun',
         'project'             => 'TestProject',
         'merge'               => 1,
-        'spawn'               => 9,
+        'testsuite_id'        => 9,
     });
 };
 is($res,undef,"TR Parser doesn't explode on instantiation");
@@ -488,7 +488,7 @@ $res = exception {
         'run'                 => 'BogoRun',
         'project'             => 'TestProject',
         'merge'               => 1,
-        'spawn'               => 9,
+        'testsuite_id'        => 9,
     });
 };
 is($res,undef,"TR Parser doesn't explode on instantiation");
@@ -512,7 +512,7 @@ $res = exception {
         'run'                 => 'BogoRun',
         'project'             => 'TestProject',
         'merge'               => 1,
-        'spawn'               => 9,
+        'testsuite_id'        => 9,
     });
 };
 is($res,undef,"TR Parser doesn't explode on instantiation");
@@ -538,7 +538,7 @@ $res = exception {
         'project'             => 'TestProject',
         'merge'               => 1,
         'autoclose'           => 1,
-        'spawn'               => 9,
+        'testsuite_id'        => 9,
     });
 };
 is($res,undef,"TR Parser doesn't explode on instantiation");
@@ -564,7 +564,7 @@ $res = exception {
         'project'             => 'TestProject',
         'merge'               => 1,
         'autoclose'           => 1,
-        'spawn'               => 9,
+        'testsuite_id'        => 9,
     });
 };
 is($res,undef,"TR Parser doesn't explode on instantiation");
@@ -617,7 +617,7 @@ $res = exception {
         'run'                 => 'BogoRun',
         'plan'                => 'BogoPlan',
         'project'             => 'TestProject',
-        'spawn'               => 9,
+        'testsuite_id'        => 9,
         'merge'               => 1,
         'autoclose'           => 1,
         'case_per_ok'         => 1

+ 28 - 0
t/lib/Test/LWP/UserAgent/TestRailMock.pm

@@ -229,6 +229,34 @@ $mockObject->map_response(qr/\Q$VAR1\E/,HTTP::Response->new($VAR2, $VAR3, $VAR4,
 
 }
 
+#OK, this one is pretty bogus, but ehhhh
+{
+
+$VAR1 = 'index.php?/api/v2/get_suites/10';
+$VAR2 = '200';
+$VAR3 = 'OK';
+$VAR4 = bless( {
+                 'connection' => 'close',
+                 'x-powered-by' => 'PHP/5.5.9-1ubuntu4.5',
+                 'client-response-num' => 1,
+                 'date' => 'Tue, 23 Dec 2014 20:02:08 GMT',
+                 'client-peer' => '192.168.122.217:80',
+                 'content-length' => '256',
+                 '::std_case' => {
+                                   'client-date' => 'Client-Date',
+                                   'x-powered-by' => 'X-Powered-By',
+                                   'client-response-num' => 'Client-Response-Num',
+                                   'client-peer' => 'Client-Peer'
+                                 },
+                 'client-date' => 'Tue, 23 Dec 2014 20:02:08 GMT',
+                 'content-type' => 'application/json; charset=utf-8',
+                 'server' => 'Apache/2.4.7 (Ubuntu)'
+               }, 'HTTP::Headers' );
+$VAR5 = '[{"id":9,"name":"HAMBURGER-IZE HUMANITY","description":"Robo-Signed Patriotic People\'s TestSuite","project_id":9,"is_master":false,"is_baseline":false,"is_completed":false,"completed_on":null,"url":"http:\\/\\/testrail.local\\/\\/index.php?\\/suites\\/view\\/9"}]';
+$mockObject->map_response(qr/\Q$VAR1\E/,HTTP::Response->new($VAR2, $VAR3, $VAR4, $VAR5));
+
+}
+
 {
 
 $VAR1 = 'index.php?/api/v2/get_suite/9';

+ 4 - 4
t/testrail-report.t

@@ -30,18 +30,18 @@ $matches = () = $out =~ m/Reporting result of case.*OK/ig;
 is($matches,2,"Attempts to to plans work");
 
 #Test that spawn works
-@args = ($^X,qw{bin/testrail-report --apiurl http://testrail.local --user "test@fake.fake" --password "fake" --project "TestProject" --run "TestingSuite2" --spawn 9 --case-ok --mock t/test_subtest.tap});
+@args = ($^X,qw{bin/testrail-report --apiurl http://testrail.local --user "test@fake.fake" --password "fake" --project "TestProject" --run "TestingSuite2" --testsuite_id 9 --case-ok --mock t/test_subtest.tap});
 $out = `@args`;
 is($? >> 8, 0, "Exit code OK reported with spawn");
 $matches = () = $out =~ m/Reporting result of case.*OK/ig;
-is($matches,2,"Attempts to spawn work");
+is($matches,2,"Attempts to spawn work: testsuite_id");
 
 #Test that spawn works w/sections
-@args = ($^X,qw{bin/testrail-report --apiurl http://testrail.local --user "test@fake.fake" --password "fake" --project "TestProject" --run "TestingSuite2" --spawn 9 --case-ok --section "CARBON LIQUEFACTION" --mock t/test_subtest.tap});
+@args = ($^X,qw{bin/testrail-report --apiurl http://testrail.local --user "test@fake.fake" --password "fake" --project "TestProject" --run "TestingSuite2" --testsuite "HAMBURGER-IZE HUMANITY" --case-ok --section "CARBON LIQUEFACTION" --mock t/test_subtest.tap});
 $out = `@args`;
 is($? >> 8, 0, "Exit code OK reported with spawn");
 $matches = () = $out =~ m/with specified sections/ig;
-is($matches,1,"Attempts to spawn work");
+is($matches,1,"Attempts to spawn work: testsuite name");
 
 #Test that the autoclose option works
 @args = ($^X,qw{bin/testrail-report --apiurl http://testrail.local --user "test@fake.fake" --password "fake" --project "TestProject" --run "FinalRun" --plan "FinalPlan" --config "testConfig" --case-ok --autoclose --mock t/fake.tap});