testrail-report.t 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 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. @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});
  16. ($out,(undef,$code)) = capture_merged {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)};
  17. is($code, 0, "Exit code OK reported with multiple files (case-ok mode)");
  18. $matches = () = $out =~ m/Reporting result of case/ig;
  19. is($matches,4,"Attempts to upload multiple times (case-ok mode)");
  20. #Test version, case-ok
  21. @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});
  22. ($out,(undef,$code)) = capture_merged {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)};
  23. is($code, 0, "Exit code OK reported with subtests (case-ok mode)");
  24. $matches = () = $out =~ m/Reporting result of case/ig;
  25. is($matches,2,"Attempts to upload do not do subtests (case-ok mode)");
  26. #Test plans/configs
  27. @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});
  28. ($out,(undef,$code)) = capture_merged {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)};
  29. is($code, 0, "Exit code OK reported with plans");
  30. $matches = () = $out =~ m/Reporting result of case.*OK/ig;
  31. is($matches,2,"Attempts to to plans work");
  32. #Test that spawn works
  33. @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});
  34. ($out,(undef,$code)) = capture_merged {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)};
  35. is($code, 0, "Exit code OK reported with spawn");
  36. $matches = () = $out =~ m/Reporting result of case.*OK/ig;
  37. is($matches,2,"Attempts to spawn work: testsuite_id");
  38. #Test that spawn works w/sections
  39. @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});
  40. ($out,(undef,$code)) = capture_merged {TestRail::Bin::Report::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args)};
  41. is($code, 0, "Exit code OK reported with spawn");
  42. $matches = () = $out =~ m/with specified sections/ig;
  43. is($matches,1,"Attempts to spawn work: testsuite name");
  44. #Test that the autoclose option works
  45. @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});
  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 when doing autoclose");
  48. like($out,qr/closing plan/i,"Run closure 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");