Jelajahi Sumber

Re-factor friggin' everything

George S. Baugh 10 tahun lalu
induk
melakukan
cc3c31b1e6

+ 1 - 0
Changes

@@ -8,6 +8,7 @@ Revision history for Perl module TestRail::API
     - Add new TestRail::Utils::Find functions; getCases, findCases
     - Add new script bin/testrail-cases
     - Change all binaries into modulinos.
+    - Resolve issue where testrail-lock would not function
 
 0.031 2015-08-14 TEODESIAN
     - Update getCases to use testRail 4.0 filters, change filter args to HASHREF

+ 9 - 7
bin/testrail-bulk-mark-results

@@ -7,7 +7,7 @@
   testrail-bulk-mark-results [OPTIONS] status [reason]
 
   require `which testrail-bulk-mark-results`;
-  TestRail::Bin::BulkMarkResults::run(@args);
+  TestRail::Bin::BulkMarkResults::run('args' => \@args);
 
 =head1 DESCRIPTION
 
@@ -16,6 +16,7 @@ For example, if a binary produced for test fails to run at all, more detailed te
 it would save time to just mark everything as blocked.
 
 Can be used as the modulino TestRail::Bin::BulkMarkResults.
+Has a single 'run' function which accepts a hash with the 'args' parameter being the array of arguments.
 
 =head1 PARAMETERS:
 
@@ -91,13 +92,13 @@ Getopt::Long::Configure('pass_through');
 use File::HomeDir qw{my_home};
 
 if (!caller()) {
-    my ($out,$code) = run(@ARGV);
+    my ($out,$code) = run('args' => \@ARGV);
     print $out;
     exit $code;
 }
 
 sub run {
-    my $args = \@_;
+    my %params = @_;
     my $opts = {};
 
     # Parse config file
@@ -107,7 +108,7 @@ sub run {
     }
 
     # Override configuration with switches
-    GetOptionsFromArray($args,
+    GetOptionsFromArray($params{'args'},
         'apiurl=s'        => \$opts->{'apiurl'},
         'password=s'      => \$opts->{'password'},
         'user=s'          => \$opts->{'user'},
@@ -120,13 +121,14 @@ sub run {
         'a|assignedto=s@' => \$opts->{'users'},
         'e|encoding=s'    => \$opts->{'encoding'},
         'h|help'          => \$opts->{'help'},
-        'mock'            => \$opts->{'mock'}
     );
 
     if ($opts->{help}) { return ('',TestRail::Utils::help()); }
 
-    my $status = $args->[0];
-    my $reason = $args->[1];
+    $opts->{'browser'} = $params{'browser'};
+
+    my $status = $params{'args'}->[0];
+    my $reason = $params{'args'}->[1];
 
     die("No status to set provided.") unless $status;
     TestRail::Utils::interrogateUser($opts,qw{apiurl user password project run});

+ 7 - 5
bin/testrail-cases

@@ -7,7 +7,7 @@
   testrail-cases [OPTIONS]
 
   require `which testrail-cases`;
-  TestRail::Bin::Cases::run(@args);
+  TestRail::Bin::Cases::run('args' => @args);
 
 =head1 DESCRIPTION
 
@@ -16,6 +16,7 @@ testrail-cases - get information about cases inside various testsuites/sections.
 By default will tell you which cases are in both the testsuite and directory passed.
 
 Can be used as the modulino TestRail::Bin::Cases.
+Has a single 'run' function which accepts a hash with the 'args' parameter being the array of arguments.
 
 =head1 PARAMETERS:
 
@@ -97,13 +98,13 @@ use Getopt::Long qw{GetOptionsFromArray};
 use File::HomeDir qw{my_home};
 
 if (!caller()) {
-    my ($out,$code) = run(@ARGV);
+    my ($out,$code) = run('args' => @ARGV);
     print $out;
     exit $code;
 }
 
 sub run {
-    my $args = \@_;
+    my %params = @_;
     my $opts ={};
 
     #Parse config file if we are missing api url/key or user
@@ -112,7 +113,7 @@ sub run {
         $opts = TestRail::Utils::parseConfig($homedir);
     }
 
-    GetOptionsFromArray($args,
+    GetOptionsFromArray($params{'args'},
         'apiurl=s'        => \$opts->{'apiurl'},
         'password=s'      => \$opts->{'password'},
         'user=s'          => \$opts->{'user'},
@@ -128,11 +129,12 @@ sub run {
         'extension=s'     => \$opts->{'extension'},
         'h|help'          => \$opts->{'help'},
         'test'            => \$opts->{'test'},
-        'mock'            => \$opts->{'mock'} #actually do something, but bogusly
     );
 
     if ($opts->{help}) { return ('',TestRail::Utils::help()); }
 
+    $opts->{'browser'} = $params{'browser'};
+
     #Mutual exclusivity
     $opts->{'no-missing'} = !$opts->{'missing'};
     $opts->{'update'} = !($opts->{'orphans'} || $opts->{'missing'});

+ 8 - 6
bin/testrail-lock

@@ -8,7 +8,7 @@
   testrail-tests [OPTIONS] | xargs testrail-lock [OPTIONS] | xargs prove -PTestrail=...
 
   require `which testrail-lock`;
-  TestRail::Bin::Lock::run(@args);
+  TestRail::Bin::Lock::run('args' => \@args);
 
 =head1 DESCRIPTION
 
@@ -23,6 +23,7 @@ Will respect test priority when making the choice of what test to lock.
 This obviously does not make sense with case_per_ok test upload; support for locking entire sections when in case_per_ok upload mode is not supported at this time.
 
 Can also be used as the modulino TestRail::Bin::Lock.
+Has a single 'run' function which accepts a hash with the 'args' parameter being the array of arguments.
 
 =head1 PARAMETERS:
 
@@ -95,19 +96,20 @@ use warnings;
 use utf8;
 
 use TestRail::Utils;
+use TestRail::Utils::Lock;
 
 use Getopt::Long qw{GetOptionsFromArray};
 use File::HomeDir qw{my_home};
 use Sys::Hostname qw{hostname};
 
 if (!caller()) {
-    my ($out,$code) = run(@ARGV);
+    my ($out,$code) = run('args' => \@ARGV);
     print $out;
     exit $code;
 }
 
 sub run {
-    my $args = \@_;
+    my %params = @_;
     my $opts = {};
 
     #Parse config file if we are missing api url/key or user
@@ -116,7 +118,7 @@ sub run {
         $opts = TestRail::Utils::parseConfig($homedir);
     }
 
-    GetOptionsFromArray($args,
+    GetOptionsFromArray($params{'args'},
         'apiurl=s'        => \$opts->{'apiurl'},
         'password=s'      => \$opts->{'password'},
         'user=s'          => \$opts->{'user'},
@@ -131,18 +133,18 @@ sub run {
         't|case-type=s@'  => \$opts->{'case-types'},
         'e|encoding=s'    => \$opts->{'encoding'},
         'h|help'          => \$opts->{'help'},
-        'mock'            => \$opts->{'mock'}
     );
 
     if ($opts->{help}) { return ('',TestRail::Utils::help()); }
 
+    $opts->{'browser'} = $params{'browser'};
     $opts->{'hostname'} = hostname;
 
     TestRail::Utils::interrogateUser($opts,qw{apiurl user password project run lockname});
 
     my $tr = TestRail::Utils::getHandle($opts);
 
-    my $ret = TestRail::Utils::pickAndLockTest($opts,$tr);
+    my $ret = TestRail::Utils::Lock::pickAndLockTest($opts,$tr);
 
     return ('Could not lock case.', 255) if !$ret;
 

+ 7 - 10
bin/testrail-report

@@ -12,13 +12,14 @@
   prove -PTestRail='apiurl=http://some.testlink.install/,user=someUser,password=somePassword,project=TestProject,run=TestRun,plan=TestPlan,configs=Config1:Config2:Config3,version=0.014' sometest.t
 
   require `which testrail-report`;
-  TestRail::Bin::Report::run(@args);
+  TestRail::Bin::Report::run('args' => @args);
 
 =head1 DESCRIPTION
 
 testrail-report - report raw TAP results to a TestRail install
 
 Can be used as the modulino TestRail::Bin::Report.
+Has a single 'run' function which accepts a hash with the 'args' parameter being the array of arguments.
 
 =head2 PARAMETERS:
 
@@ -127,13 +128,13 @@ if (!caller()) {
 
 #Main loop------------
 sub run {
-    my $args = \@_;
+    my %params = @_;
     my %opts;
 
     print "testrail-report\n----------------------\n";
 
     #parse switches
-    GetOptionsFromArray($args,
+    GetOptionsFromArray($params{'args'},
         'run=s'          => \$opts{run},
         'apiurl=s'       => \$opts{apiurl},
         'password=s'     => \$opts{password},
@@ -150,10 +151,10 @@ sub run {
         'autoclose'      => \$opts{autoclose},
         'e|encoding=s'   => \$opts{encoding},
         'help'           => \$opts{help},
-        'mock'           => \$opts{mock}
     );
 
     if ($opts{help}) { return ('',TestRail::Utils::help()); }
+    $opts{'browser'} = $params{'browser'};
 
     #Parse config file if we are missing api url/key or user
     my $homedir = my_home() || '.';
@@ -162,7 +163,7 @@ sub run {
     }
 
     #If argument is passed use it instead of stdin
-    my $file = $args->[0];
+    my $file = $params{'args'}->[0];
     die "No Such File $file" if ($file && !-e $file);
 
     die "ERROR: Interactive mode not allowed when piping input.  See --help for options." if ( !$opts{run} || !$opts{apiurl} || !$opts{password} || !$opts{user} || !$opts{project} );
@@ -173,11 +174,7 @@ sub run {
 
     $opts{result_options} = {'version' => $opts{version}} if $opts{version};
 
-    if ($opts{'mock'}) {
-        require 't/lib/Test/LWP/UserAgent/TestRailMock.pm'; ## no critic
-        $opts{'browser'} = $Test::LWP::UserAgent::TestRailMock::mockObject;
-        $opts{'debug'} = 1;
-    }
+    $opts{'debug'} = 1 if $opts{'browser'};
 
     my $tap;
     foreach my $phil (@files) {

+ 7 - 5
bin/testrail-runs

@@ -7,7 +7,7 @@
   testrail-runs [OPTIONS] | xargs prove -PTestrail=...
 
   require `which testrail-runs`;
-  TestRail::Bin::Run::run(@args);
+  TestRail::Bin::Run::run('args' => \@args);
 
 =head1 DESCRIPTION
 
@@ -15,6 +15,7 @@ testrail-runs - list runs in a TestRail project matching the provided filters.
 Groups by plan for runs which are children of a plan.
 
 Can be used as the modulino TestRail::Bin::Runs.
+Has a single 'run' function which accepts a hash with the 'args' parameter being the array of arguments.
 
 =head1 PARAMETERS:
 
@@ -83,13 +84,13 @@ use Getopt::Long qw{GetOptionsFromArray};
 use File::HomeDir qw{my_home};
 
 if (!caller()) {
-    my ($out,$code) = run(@ARGV);
+    my ($out,$code) = run('args' => \@ARGV);
     print $out;
     exit $code;
 }
 
 sub run {
-    my $args = \@_;
+    my %params = @_;
     my $opts = {};
 
     # Parse config file
@@ -98,7 +99,7 @@ sub run {
         $opts = TestRail::Utils::parseConfig($homedir);
     }
 
-    GetOptionsFromArray($args,
+    GetOptionsFromArray($params{'args'},
         'apiurl=s'     => \$opts->{'apiurl'},
         'password=s'   => \$opts->{'password'},
         'user=s'       => \$opts->{'user'},
@@ -109,11 +110,12 @@ sub run {
         'l|lifo'       => \$opts->{'lifo'},
         'm|milesort'   => \$opts->{'milesort'},
         'h|help'       => \$opts->{'help'},
-        'mock'         => \$opts->{'mock'}
     );
 
     if ($opts->{help}) { return ('',TestRail::Utils::help()); }
 
+    $opts->{'browser'} = $params{'browser'};
+
     TestRail::Utils::interrogateUser($opts,qw{apiurl user password project});
 
     my $tr = TestRail::Utils::getHandle($opts);

+ 7 - 5
bin/testrail-tests

@@ -7,13 +7,14 @@
   testrail-tests [OPTIONS] | xargs prove -PTestrail=...
 
   require `which testrail-tests`;
-  TestRail::Bin::Test::run(@args);
+  TestRail::Bin::Test::run('args' => \@args);
 
 =head1 DESCRIPTION
 
 testrail-tests - list tests in a run matching the provided filters.
 
 Can be used as the modulino TestRail::Bin::Tests.
+Has a single 'run' function which accepts a hash with the 'args' parameter being the array of arguments.
 
 =head1 PARAMETERS:
 
@@ -99,13 +100,13 @@ use Getopt::Long qw{GetOptionsFromArray};
 use File::HomeDir qw{my_home};
 
 if (!caller()) {
-    my ($out,$code) = run(@ARGV);
+    my ($out,$code) = run('args' => \@ARGV);
     print $out;
     exit $code;
 }
 
 sub run {
-    my $args = \@_;
+    my %params = @_;
     my $opts ={};
 
     #Parse config file if we are missing api url/key or user
@@ -114,7 +115,7 @@ sub run {
         $opts = TestRail::Utils::parseConfig($homedir);
     }
 
-    GetOptionsFromArray($args,
+    GetOptionsFromArray($params{'args'},
         'apiurl=s'        => \$opts->{'apiurl'},
         'password=s'      => \$opts->{'password'},
         'user=s'          => \$opts->{'user'},
@@ -131,11 +132,12 @@ sub run {
         'e|encoding=s'    => \$opts->{'encoding'},
         'extension=s'     => \$opts->{'extension'},
         'h|help'          => \$opts->{'help'},
-        'mock'            => \$opts->{'mock'}
     );
 
     if ($opts->{help}) { return ('',TestRail::Utils::help()); }
 
+    $opts->{'browser'} = $params{'browser'};
+
     TestRail::Utils::interrogateUser($opts,qw{apiurl user password project run});
 
     my $tr = TestRail::Utils::getHandle($opts);

TEMPAT SAMPAH
dist/TestRail-API-0.032.tar.gz


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

@@ -62,10 +62,12 @@ sub make_parser {
     $args->{'sections'}  = \@sections if scalar(@sections);
     $args->{'autoclose'} = $ENV{'TESTRAIL_AUTOCLOSE'};
 
-    #for Testability of plugin
+    #for Testability of plugin XXX probably some of the last remaining grotiness
     if ($ENV{'TESTRAIL_MOCKED'}) {
         use lib 't/lib'; #Unit tests will always run from the main dir during make test
-        require 't/lib/Test/LWP/UserAgent/TestRailMock.pm' unless defined $Test::LWP::UserAgent::TestRailMock::mockObject; ## no critic
+        if (!defined $Test::LWP::UserAgent::TestRailMock::mockObject) {
+            require 't/lib/Test/LWP/UserAgent/TestRailMock.pm'; ## no critic
+        }
         $args->{'debug'} = 1;
         $args->{'browser'} = $Test::LWP::UserAgent::TestRailMock::mockObject;
     }

+ 5 - 5
lib/TestRail/Utils.pm

@@ -8,6 +8,7 @@ use warnings;
 
 use Carp qw{confess cluck};
 use Pod::Perldoc 3.20; #Make sure we have ToMan on some unices
+use TestRail::API;
 
 use IO::Interactive::Tiny ();
 use Term::ANSIColor 2.01 qw(colorstrip);
@@ -223,12 +224,11 @@ Has a special 'mock' hash key that can only be used by those testing this distri
 sub getHandle {
     my $opts = shift;
 
-    $opts->{'debug'} = 1 if ($opts->{'mock'});
+    $opts->{'debug'} = 1 if ($opts->{'browser'});
+
     my $tr = TestRail::API->new($opts->{apiurl},$opts->{user},$opts->{password},$opts->{'encoding'},$opts->{'debug'});
-    if ($opts->{'mock'}) {
-        use lib 't/lib'; #Unit tests will always run from the main dir during make test
-        require 't/lib/Test/LWP/UserAgent/TestRailMock.pm' unless defined $Test::LWP::UserAgent::TestRailMock::mockObject; ## no critic
-        $tr->{'browser'} = $Test::LWP::UserAgent::TestRailMock::mockObject;
+    if ($opts->{'browser'}) {
+        $tr->{'browser'} = $opts->{'browser'};
         $tr->{'debug'} = 0;
     }
     return $tr;

+ 7 - 5
t/TestRail-Utils.t

@@ -10,20 +10,23 @@ use warnings;
 use FindBin;
 use lib "$FindBin::Bin/lib";
 
-use Test::More 'tests' => 26;
+use Test::More 'tests' => 27;
 use Test::Fatal;
 
 use TestRail::API;
 use TestRail::Utils;
 use Test::LWP::UserAgent::TestRailMock;
+use IO::CaptureOutput qw{capture};
 
 use File::Basename qw{dirname};
 
 my ($apiurl,$user,$password);
 
 #check help output
-
-is(TestRail::Utils::help(),0,"Help works OK");
+my $out;
+my $code = capture { TestRail::Utils::help() } \$out;
+is($code,0,"Help works OK");
+like($out,qr/bogus bogus/i,"Displays POD OK");
 
 #check the binary output mode
 is(exception {($apiurl,$password,$user) = TestRail::Utils::parseConfig(dirname(__FILE__),1)}, undef, "No exceptions thrown by parseConfig in array mode");
@@ -31,7 +34,6 @@ is($apiurl,'http://hokum.bogus',"APIURL parse OK");
 is($user,'zippy',"USER parse OK");
 is($password, 'happy', 'PASSWORD parse OK');
 
-my $out;
 is(exception {$out = TestRail::Utils::parseConfig(dirname(__FILE__))}, undef, "No exceptions thrown by parseConfig default mode");
 is($out->{apiurl},'http://hokum.bogus',"APIURL parse OK");
 is($out->{user},'zippy',"USER parse OK");
@@ -79,7 +81,7 @@ my $login_opts = {
     'apiurl'   => 'http://testrail.local',
     'user'     => 'teodesian@cpan.org',
     'password' => 'fake',
-    'mock'     => 1
+    'browser'  => $Test::LWP::UserAgent::TestRailMock::mockObject
 };
 my $tr = TestRail::Utils::getHandle($login_opts);
 

+ 6 - 3
t/testrail-bulk-mark-results.t

@@ -8,16 +8,19 @@ use IO::CaptureOutput qw{capture};
 use lib $FindBin::Bin.'/../bin';
 require 'testrail-bulk-mark-results';
 
+use lib $FindBin::Bin.'/lib';
+use Test::LWP::UserAgent::TestRailMock;
+
 #check plan mode
-my @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j },"CRUSH ALL HUMANS", '-r', "SEND T-1000 INFILTRATION UNITS BACK IN TIME", qw{--mock blocked}, "Build was bad.");
-my ($out,$code) = TestRail::Bin::BulkMarkResults::run(@args);
+my @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j },"CRUSH ALL HUMANS", '-r', "SEND T-1000 INFILTRATION UNITS BACK IN TIME", 'blocked', "Build was bad.");
+my ($out,$code) = TestRail::Bin::BulkMarkResults::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
 is($code, 0, "Exit code OK running against normal run");
 chomp $out;
 like($out,qr/set the status of 1 cases to blocked/,"Sets test correctly in single run mode");
 
 @args = qw{--help};
 $0 = $FindBin::Bin.'/../bin/testrail-bulk-mark-results';
-(undef,$code) = capture {TestRail::Bin::BulkMarkResults::run(@args)} \$out, \$out;
+(undef,$code) = capture {TestRail::Bin::BulkMarkResults::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)} \$out, \$out;
 is($code, 0, "Exit code OK asking for help");
 like($out,qr/encoding of arguments/i,"Help output OK");
 

+ 10 - 7
t/testrail-cases.t

@@ -6,29 +6,32 @@ use FindBin;
 use lib $FindBin::Bin.'/../bin';
 require 'testrail-cases';
 
+use lib $FindBin::Bin.'/lib';
+use Test::LWP::UserAgent::TestRailMock;
+
 use Test::More "tests" => 6;
 use IO::CaptureOutput qw{capture};
 
 #check plan mode
-my @args = (qw{-j TestProject -t}, 'HAMBURGER-IZE HUMANITY', qw{-d t --mock --test --extension .test});
-my ($out,$code) = TestRail::Bin::Cases::run(@args);
+my @args = (qw{-j TestProject -t}, 'HAMBURGER-IZE HUMANITY', qw{-d t --test --extension .test});
+my ($out,$code) = TestRail::Bin::Cases::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
 is($code, 0, "Exit code OK running add, update, orphans");
 chomp $out;
 like($out,qr/fake\.test/,"Shows existing tests by default");
 
-@args = (qw{-j TestProject -t}, 'HAMBURGER-IZE HUMANITY', qw{-d t --mock  -o --extension .test});
-($out,$code) = TestRail::Bin::Cases::run(@args);
+@args = (qw{-j TestProject -t}, 'HAMBURGER-IZE HUMANITY', qw{-d t -o --extension .test});
+($out,$code) = TestRail::Bin::Cases::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
 chomp $out;
 like($out,qr/nothere\.test/,"Shows orphan tests");
 
-@args = (qw{-j TestProject -t}, 'HAMBURGER-IZE HUMANITY', qw{-d t --mock  -m --extension .test});
-($out,$code) = TestRail::Bin::Cases::run(@args);
+@args = (qw{-j TestProject -t}, 'HAMBURGER-IZE HUMANITY', qw{-d t -m --extension .test});
+($out,$code) = TestRail::Bin::Cases::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
 chomp $out;
 like($out,qr/t\/skipall\.test/,"Shows missing tests");
 
 #Verify no-match returns non path
 @args = qw{--help};
 $0 = $FindBin::Bin.'/../bin/testrail-cases';
-(undef,$code) = capture {TestRail::Bin::Cases::run(@args)} \$out, \$out;
+(undef,$code) = capture {TestRail::Bin::Cases::run('args' => \@args)} \$out, \$out;
 is($code, 0, "Exit code OK asking for help");
 like($out,qr/encoding of arguments/i,"Help output OK");

+ 10 - 4
t/testrail-lock.t

@@ -1,19 +1,25 @@
 use strict;
 use warnings;
 
-use Test::More "tests" => 2;
+use Test::More "tests" => 4;
 use FindBin;
 use IO::CaptureOutput qw{capture};
 
 use lib $FindBin::Bin.'/../bin';
 require 'testrail-lock';
 
-#VERY rudimentray checking
+use lib $FindBin::Bin.'/lib';
+use Test::LWP::UserAgent::TestRailMock;
+
 my @args = qw{--help};
 $0 = $FindBin::Bin.'/../bin/testrail-lock';
 my $out;
-my (undef,$code) = capture {TestRail::Bin::Lock::run(@args)} \$out, \$out;
+my (undef,$code) = capture {TestRail::Bin::Lock::run('args' => \@args)} \$out, \$out;
 is($code, 0, "Exit code OK asking for help");
 like($out,qr/encoding of arguments/i,"Help output OK");
 
-
+@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j },"CRUSH ALL HUMANS", '-r', "SEND T-1000 INFILTRATION UNITS BACK IN TIME", qw{--lockname locked});
+($out,$code) = TestRail::Bin::Lock::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
+is($code, 255, "Exit code bad when no case could be locked");
+chomp $out;
+like($out,qr/could not lock case/i,"Output is as expected");

+ 18 - 15
t/testrail-report.t

@@ -8,56 +8,59 @@ require 'testrail-report';
 use Test::More 'tests' => 16;
 use IO::CaptureOutput qw{capture};
 
-my @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake --project}, "CRUSH ALL HUMANS", '--run', "SEND T-1000 INFILTRATION UNITS BACK IN TIME", qw{--mock t/test_multiple_files.tap});
+use lib $FindBin::Bin.'/lib';
+use Test::LWP::UserAgent::TestRailMock;
+
+my @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake --project}, "CRUSH ALL HUMANS", '--run', "SEND T-1000 INFILTRATION UNITS BACK IN TIME", qw{ t/test_multiple_files.tap});
 my $out;
-my (undef,$code) = capture {TestRail::Bin::Report::run(@args)} \$out, \$out;
+my (undef,$code) = capture {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)} \$out, \$out;
 is($code, 0, "Exit code OK reported with multiple files");
 my $matches = () = $out =~ m/Reporting result of case/ig;
 is($matches,2,"Attempts to upload multiple times");
 
-@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake --project}, "CRUSH ALL HUMANS", '--run', "SEND T-1000 INFILTRATION UNITS BACK IN TIME", qw{--case-ok --mock t/test_multiple_files.tap});
-(undef,$code) = capture {TestRail::Bin::Report::run(@args)} \$out, \$out;
+@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake --project}, "CRUSH ALL HUMANS", '--run', "SEND T-1000 INFILTRATION UNITS BACK IN TIME", qw{--case-ok  t/test_multiple_files.tap});
+(undef,$code) = capture {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)} \$out, \$out;
 is($code, 0, "Exit code OK reported with multiple files (case-ok mode)");
 $matches = () = $out =~ m/Reporting result of case/ig;
 is($matches,4,"Attempts to upload multiple times (case-ok mode)");
 
 #Test version, case-ok
-@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake --project TestProject --run TestingSuite --case-ok --version 1.0.14 --mock t/test_subtest.tap});
-(undef,$code) = capture {TestRail::Bin::Report::run(@args)} \$out, \$out;
+@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake --project TestProject --run TestingSuite --case-ok --version 1.0.14  t/test_subtest.tap});
+(undef,$code) = capture {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)} \$out, \$out;
 is($code, 0, "Exit code OK reported with subtests (case-ok mode)");
 $matches = () = $out =~ m/Reporting result of case/ig;
 is($matches,2,"Attempts to upload do not do subtests (case-ok mode)");
 
 #Test plans/configs
-@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake --project TestProject --run}, "Executing the great plan", qw{--plan GosPlan --config testConfig --case-ok --mock t/test_subtest.tap});
-(undef,$code) = capture {TestRail::Bin::Report::run(@args)} \$out, \$out;
+@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake --project TestProject --run}, "Executing the great plan", qw{--plan GosPlan --config testConfig --case-ok  t/test_subtest.tap});
+(undef,$code) = capture {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)} \$out, \$out;
 is($code, 0, "Exit code OK reported with plans");
 $matches = () = $out =~ m/Reporting result of case.*OK/ig;
 is($matches,2,"Attempts to to plans work");
 
 #Test that spawn works
-@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake --project TestProject --run TestingSuite2 --testsuite_id 9 --case-ok --mock t/test_subtest.tap});
-(undef,$code) = capture {TestRail::Bin::Report::run(@args)} \$out, \$out;
+@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake --project TestProject --run TestingSuite2 --testsuite_id 9 --case-ok  t/test_subtest.tap});
+(undef,$code) = capture {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)} \$out, \$out;
 is($code, 0, "Exit code OK reported with spawn");
 $matches = () = $out =~ m/Reporting result of case.*OK/ig;
 is($matches,2,"Attempts to spawn work: testsuite_id");
 
 #Test that spawn works w/sections
-@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake --project TestProject --run TestingSuite2 --testsuite}, "HAMBURGER-IZE HUMANITY", qw{--case-ok --section}, "CARBON LIQUEFACTION", qw{--mock t/test_subtest.tap});
-(undef,$code) = capture {TestRail::Bin::Report::run(@args)} \$out, \$out;
+@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake --project TestProject --run TestingSuite2 --testsuite}, "HAMBURGER-IZE HUMANITY", qw{--case-ok --section}, "CARBON LIQUEFACTION", qw{ t/test_subtest.tap});
+(undef,$code) = capture {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)} \$out, \$out;
 is($code, 0, "Exit code OK reported with spawn");
 $matches = () = $out =~ m/with specified sections/ig;
 is($matches,1,"Attempts to spawn work: testsuite name");
 
 #Test that the autoclose option works
-@args = (qw{--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});
-(undef,$code) = capture {TestRail::Bin::Report::run(@args)} \$out, \$out;
+@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake --project TestProject --run FinalRun --plan FinalPlan --config testConfig --case-ok --autoclose  t/fake.tap});
+(undef,$code) = capture {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)} \$out, \$out;
 is($code, 0, "Exit code OK when doing autoclose");
 like($out,qr/closing plan/i,"Run closure reported to user");
 
 #Test that help works
 @args = qw{--help};
 $0 = $FindBin::Bin.'/../bin/testrail-report';
-(undef,$code) = capture {TestRail::Bin::Report::run(@args)} \$out, \$out;
+(undef,$code) = capture {TestRail::Bin::Report::run('args' => \@args)} \$out, \$out;
 is($code, 0, "Exit code OK asking for help");
 like($out,qr/encoding of arguments/i,"Help output OK");

+ 14 - 12
t/testrail-runs.t

@@ -6,41 +6,43 @@ use FindBin;
 use lib $FindBin::Bin.'/../bin';
 require 'testrail-runs';
 
+use lib $FindBin::Bin.'/lib';
+use Test::LWP::UserAgent::TestRailMock;
+
 use Test::More 'tests' => 12;
 use IO::CaptureOutput qw{capture};
 
 #check status filters
-my @args = qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject --mock};
-my ($out,$code) = TestRail::Bin::Runs::run(@args);
+my @args = qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject };
+my ($out,$code) = TestRail::Bin::Runs::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
 is($code, 0, "Exit code OK looking for runs with passes");
 chomp $out;
 like($out,qr/^OtherOtherSuite\nTestingSuite\nFinalRun\nlockRun\nClosedRun$/,"Gets run correctly looking for passes");
 
 #check LIFO sort
-@args = qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject --lifo --mock};
-($out,$code) = TestRail::Bin::Runs::run(@args);
+@args = qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject --lifo };
+($out,$code) = TestRail::Bin::Runs::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
 is($code, 0, "Exit code OK looking for runs with passes");
 chomp $out;
 like($out,qr/^lockRun\nClosedRun\nTestingSuite\nFinalRun\nOtherOtherSuite$/,"LIFO sort works");
 
 #check milesort
-@args = qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject --milesort --mock};
-($out,$code) = TestRail::Bin::Runs::run(@args);
+@args = qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject --milesort };
+($out,$code) = TestRail::Bin::Runs::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
 is($code, 0, "Exit code OK looking for runs with passes");
 chomp $out;
 like($out,qr/^TestingSuite\nFinalRun\nlockRun\nClosedRun\nOtherOtherSuite$/,"milesort works");
 
-
 #check status filters
-@args = qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject --mock --status passed};
-($out,$code) = TestRail::Bin::Runs::run(@args);
+@args = qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject  --status passed};
+($out,$code) = TestRail::Bin::Runs::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
 is($code, 255, "Exit code OK looking for runs with passes, which should fail to return results");
 chomp $out;
 like($out,qr/no runs found/i,"Gets no runs correctly looking for passes");
 
 #TODO check configs for real next time
-@args = qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject --mock --config testConfig --config eee};
-($out,$code) = TestRail::Bin::Runs::run(@args);
+@args = qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject  --config testConfig --config eee};
+($out,$code) = TestRail::Bin::Runs::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
 is($code, 255, "Exit code OK looking for runs with passes");
 chomp $out;
 like($out,qr/no runs found/i,"Gets no run correctly when filtering by unassigned config");
@@ -48,6 +50,6 @@ like($out,qr/no runs found/i,"Gets no run correctly when filtering by unassigned
 #Verify no-match returns non path
 @args = qw{--help};
 $0 = $FindBin::Bin.'/../bin/testrail-runs';
-(undef,$code) = capture {TestRail::Bin::Runs::run(@args)} \$out, \$out;
+(undef,$code) = capture {TestRail::Bin::Runs::run('args' => \@args)} \$out, \$out;
 is($code, 0, "Exit code OK asking for help");
 like($out,qr/encoding of arguments/i,"Help output OK");

+ 30 - 27
t/testrail-tests.t

@@ -9,16 +9,19 @@ use IO::CaptureOutput qw{capture};
 use lib $FindBin::Bin.'/../bin';
 require 'testrail-tests';
 
+use lib $FindBin::Bin.'/lib';
+use Test::LWP::UserAgent::TestRailMock;
+
 #check plan mode
-my @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{-m t --config testConfig --mock --no-recurse});
-my ($out,$code) = TestRail::Bin::Tests::run(@args);
+my @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{-m t --config testConfig  --no-recurse});
+my ($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
 is($code, 0, "Exit code OK running plan mode, no recurse");
 chomp $out;
 like($out,qr/skipall\.test$/,"Gets test correctly in plan mode, no recurse");
 
 #check no-match
-@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{--no-match t --config testConfig --mock});
-($out,$code) = TestRail::Bin::Tests::run(@args);
+@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{--no-match t --config testConfig });
+($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
 is($code, 0, "Exit code OK running plan mode, no match");
 chomp $out;
 unlike($out,qr/skipall\.test/,"Omits test correctly in plan mode, recurse, no-match");
@@ -26,71 +29,71 @@ unlike($out,qr/NOT SO SEARED AFTER ARR/,"Omits non-file test correctly in plan m
 like($out,qr/faker\.test/,"Omits non-file test correctly in plan mode, recurse, no-match");
 
 #check no-match, no recurse
-@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{--no-match t --config testConfig --mock --no-recurse});
-($out,$code) = TestRail::Bin::Tests::run(@args);
+@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{--no-match t --config testConfig  --no-recurse});
+($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
 is($code, 0, "Exit code OK running plan mode, no match, no recurse");
 chomp $out;
 unlike($out,qr/skipall\.test/,"Omits test correctly in plan mode, no recurse, no-match");
 unlike($out,qr/NOT SO SEARED AFTER ARR/,"Omits non-file test correctly in plan mode, no recurse, no-match");
 like($out,qr/faker\.test/,"Omits non-file test correctly in plan mode, no recurse, no-match");
 
-@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{--config testConfig -m t --mock});
-($out,$code) = TestRail::Bin::Tests::run(@args);
+@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{--config testConfig -m t });
+($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
 is($code, 0, "Exit code OK running plan mode, recurse");
 chomp $out;
 like($out,qr/skipall\.test$/,"Gets test correctly in plan mode, recurse");
 
 #check non plan mode
-@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject  -r TestingSuite -m t --mock --no-recurse});
-($out,$code) = TestRail::Bin::Tests::run(@args);
+@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject  -r TestingSuite -m t  --no-recurse});
+($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
 is($code, 0, "Exit code OK running no plan mode, no recurse");
 chomp $out;
 like($out,qr/skipall\.test$/,"Gets test correctly in no plan mode, no recurse");
 
-@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject  -r TestingSuite -m t --mock});
-($out,$code) = TestRail::Bin::Tests::run(@args);
+@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject  -r TestingSuite -m t });
+($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
 is($code, 0, "Exit code OK running no plan mode, recurse");
 chomp $out;
 like($out,qr/skipall\.test$/,"Gets test correctly in no plan mode, recurse");
 
 #Negative case, filtering by config
-@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{-m t --mock --config testPlatform1});
-isnt(exception {TestRail::Bin::Tests::run(@args)}, undef, "Exit code not OK when passing invalid configs for plan");
+@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{-m t  --config testPlatform1});
+isnt(exception {TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)}, undef, "Exit code not OK when passing invalid configs for plan");
 
 #check assignedto filters
-@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{--mock --config testConfig --assignedto teodesian});
-($out,$code) = TestRail::Bin::Tests::run(@args);
+@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{ --config testConfig --assignedto teodesian});
+($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
 is($code, 0, "Exit code OK when filtering by assignment");
 like($out,qr/skipall\.test$/,"Gets test correctly when filtering by assignment");
 
-@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{--mock --config testConfig --assignedto billy});
-($out,$code) = TestRail::Bin::Tests::run(@args);
+@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{ --config testConfig --assignedto billy});
+($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
 is($code, 255, "Exit code OK when filtering by assignment");
 chomp $out;
 is($out,"","Gets no tests correctly when filtering by wrong assignment");
 
 #check status filters
-@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{-m t --mock --config testConfig --status passed});
-($out,$code) = TestRail::Bin::Tests::run(@args);
+@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{-m t  --config testConfig --status passed});
+($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
 is($code, 0, "Exit code OK when filtering by status");
 like($out,qr/skipall\.test$/,"Gets test correctly when filtering by status");
 
-@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{--mock --config testConfig --status failed});
-($out,$code) = TestRail::Bin::Tests::run(@args);
+@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject -p GosPlan -r}, "Executing the great plan", qw{ --config testConfig --status failed});
+($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
 is($code, 255, "Exit code OK when filtering by status");
 chomp $out;
 is($out,"","Gets no tests correctly when filtering by wrong status");
 
 #Verify no-match returns non path
-@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject  -r TestingSuite --mock});
-($out,$code) = TestRail::Bin::Tests::run(@args);
+@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject  -r TestingSuite });
+($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
 is($code, 0, "Exit code OK running no plan mode, no-match");
 chomp $out;
 like($out,qr/\nskipall\.test$/,"Gets test correctly in no plan mode, no-match");
 
 #Verify no-match returns non path
-@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject  -r TestingSuite --orphans t --mock});
-($out,$code) = TestRail::Bin::Tests::run(@args);
+@args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake -j TestProject  -r TestingSuite --orphans t });
+($out,$code) = TestRail::Bin::Tests::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
 is($code, 0, "Exit code OK running no plan mode, no recurse");
 chomp $out;
 like($out,qr/NOT SO SEARED AFTER ARR/,"Gets test correctly in orphan mode");
@@ -98,6 +101,6 @@ like($out,qr/NOT SO SEARED AFTER ARR/,"Gets test correctly in orphan mode");
 #Verify no-match returns non path
 @args = qw{--help};
 $0 = $FindBin::Bin.'/../bin/testrail-tests';
-(undef,$code) = capture {TestRail::Bin::Tests::run(@args)} \$out, \$out;
+(undef,$code) = capture {TestRail::Bin::Tests::run('args' => \@args)} \$out, \$out;
 is($code, 0, "Exit code OK asking for help");
 like($out,qr/encoding of arguments/i,"Help output OK");