testrail-report.t 3.6 KB

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