testrail-report.t 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. use strict;
  2. use warnings;
  3. use FindBin;
  4. use lib $FindBin::Bin.'/../bin';
  5. require 'testrail-report';
  6. use Test::More 'tests' => 17;
  7. use Capture::Tiny qw{capture_merged};
  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,(undef,$code)) = capture_merged {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)};
  12. is($code, 0, "Exit code OK reported with multiple files");
  13. my $matches = () = $out =~ m/Reporting result of case/ig;
  14. is($matches,2,"Attempts to upload multiple times");
  15. #Test version, case-ok
  16. @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake --project TestProject --run TestingSuite --version 1.0.14 t/test_subtest.tap});
  17. ($out,(undef,$code)) = capture_merged {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)};
  18. is($code, 0, "Exit code OK reported with subtests (case-ok mode)");
  19. $matches = () = $out =~ m/Reporting result of case/ig;
  20. is($matches,1,"version can be uploaded");
  21. #Test plans/configs
  22. @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake --project TestProject --run}, "Executing the great plan", qw{--plan GosPlan --config testConfig t/test_subtest.tap});
  23. ($out,(undef,$code)) = capture_merged {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)};
  24. is($code, 0, "Exit code OK reported with plans");
  25. $matches = () = $out =~ m/Reporting result of case.*OK/ig;
  26. is($matches,1,"Attempts to to plans work");
  27. #Test that spawn works
  28. @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake --project TestProject --run TestingSuite2 --testsuite_id 9 t/test_subtest.tap});
  29. ($out,(undef,$code)) = capture_merged {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)};
  30. is($code, 0, "Exit code OK reported with spawn");
  31. $matches = () = $out =~ m/Reporting result of case.*OK/ig;
  32. is($matches,1,"Attempts to spawn work: testsuite_id");
  33. #Test that spawn works w/sections
  34. @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake --project TestProject --run TestingSuite2 --testsuite}, "HAMBURGER-IZE HUMANITY", qw{ --section}, "CARBON LIQUEFACTION", qw{ t/test_subtest.tap});
  35. ($out,(undef,$code)) = capture_merged {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)};
  36. is($code, 0, "Exit code OK reported with spawn");
  37. $matches = () = $out =~ m/with specified sections/ig;
  38. is($matches,1,"Attempts to spawn work: testsuite name");
  39. #Test that the autoclose option works
  40. @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake --project TestProject --run FinalRun --plan FinalPlan --config testConfig --autoclose t/fake.tap});
  41. ($out,(undef,$code)) = capture_merged {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)};
  42. is($code, 0, "Exit code OK when doing autoclose");
  43. like($out,qr/closing plan/i,"Run closure reported to user");
  44. #Test that the max_tries option works
  45. @args = (qw{--apiurl http://testrail.local --user test@fake.fake --password fake --project TestProject --run FinalRun --plan FinalPlan --config testConfig --max_tries 2 t/no_such_test.tap});
  46. ($out,(undef,$code)) = capture_merged {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)};
  47. is($code, 0, "Exit code OK ");
  48. like($out,qr/re-trying request/i,"Re-try attepmt reported to user");
  49. #Test that help works
  50. @args = qw{--help};
  51. $0 = $FindBin::Bin.'/../bin/testrail-report';
  52. ($out,(undef,$code)) = capture_merged {TestRail::Bin::Report::run('args' => \@args)};
  53. is($code, 0, "Exit code OK asking for help");
  54. like($out,qr/encoding of arguments/i,"Help output OK");
  55. #Make sure that the binary itself processes args correctly
  56. $out = `$^X $0 --help`;
  57. like($out,qr/encoding of arguments/i,"Appears we can run binary successfully");