testrail-report.t 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. use strict;
  2. use warnings;
  3. use FindBin;
  4. use lib $FindBin::Bin.'/../bin';
  5. require 'testrail-report';
  6. use Test::More 'tests' => 16;
  7. use IO::CaptureOutput qw{capture};
  8. use lib $FindBin::Bin.'/lib';
  9. use Test::LWP::UserAgent::TestRailMock;
  10. 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});
  11. my $out;
  12. my (undef,$code) = capture {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)} \$out, \$out;
  13. is($code, 0, "Exit code OK reported with multiple files");
  14. my $matches = () = $out =~ m/Reporting result of case/ig;
  15. is($matches,2,"Attempts to upload multiple times");
  16. @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});
  17. (undef,$code) = capture {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)} \$out, \$out;
  18. is($code, 0, "Exit code OK reported with multiple files (case-ok mode)");
  19. $matches = () = $out =~ m/Reporting result of case/ig;
  20. is($matches,4,"Attempts to upload multiple times (case-ok mode)");
  21. #Test version, case-ok
  22. @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});
  23. (undef,$code) = capture {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)} \$out, \$out;
  24. is($code, 0, "Exit code OK reported with subtests (case-ok mode)");
  25. $matches = () = $out =~ m/Reporting result of case/ig;
  26. is($matches,2,"Attempts to upload do not do subtests (case-ok mode)");
  27. #Test plans/configs
  28. @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});
  29. (undef,$code) = capture {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)} \$out, \$out;
  30. is($code, 0, "Exit code OK reported with plans");
  31. $matches = () = $out =~ m/Reporting result of case.*OK/ig;
  32. is($matches,2,"Attempts to to plans work");
  33. #Test that spawn works
  34. @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});
  35. (undef,$code) = capture {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)} \$out, \$out;
  36. is($code, 0, "Exit code OK reported with spawn");
  37. $matches = () = $out =~ m/Reporting result of case.*OK/ig;
  38. is($matches,2,"Attempts to spawn work: testsuite_id");
  39. #Test that spawn works w/sections
  40. @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});
  41. (undef,$code) = capture {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)} \$out, \$out;
  42. is($code, 0, "Exit code OK reported with spawn");
  43. $matches = () = $out =~ m/with specified sections/ig;
  44. is($matches,1,"Attempts to spawn work: testsuite name");
  45. #Test that the autoclose option works
  46. @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});
  47. (undef,$code) = capture {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)} \$out, \$out;
  48. is($code, 0, "Exit code OK when doing autoclose");
  49. like($out,qr/closing plan/i,"Run closure reported to user");
  50. #Test that help works
  51. @args = qw{--help};
  52. $0 = $FindBin::Bin.'/../bin/testrail-report';
  53. (undef,$code) = capture {TestRail::Bin::Report::run('args' => \@args)} \$out, \$out;
  54. is($code, 0, "Exit code OK asking for help");
  55. like($out,qr/encoding of arguments/i,"Help output OK");