testrail-replay.t 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. use strict;
  2. use warnings;
  3. use FindBin;
  4. use lib $FindBin::Bin.'/../bin';
  5. require 'testrail-replay';
  6. use Test::More 'tests' => 6;
  7. use Capture::Tiny qw{capture_merged};
  8. use Test::Fatal;
  9. use Test::MockModule qw{strict};
  10. my $utilmock = Test::MockModule->new('TestRail::Utils');
  11. $utilmock->redefine('getHandle', sub { bless({},"TestRail::API") } );
  12. my $apimock = Test::MockModule->new('TestRail::API');
  13. $apimock->redefine('new', sub{ return bless({},shift) });
  14. $apimock->redefine('getProjectByName', sub { { id => 666 } });
  15. $apimock->redefine('getRunByName', sub { { id => 333 } });
  16. $apimock->redefine('getPlanByName', sub { { id => 222, config => 'BogusConfig' } } );
  17. $apimock->redefine('getChildRuns', sub { { [{ id => 111 }] } });
  18. $apimock->redefine('statusNamesToIds', sub { shift; shift eq 'failed' ? [5] : [4] });
  19. $apimock->redefine('getTests', sub {
  20. my ($self,$run_id) = @_;
  21. return [
  22. {
  23. 'id' => 666,
  24. 'title' => 'fake.test',
  25. 'run_id' => $run_id
  26. }
  27. ];
  28. });
  29. $apimock->redefine('getTestResults', sub {
  30. return [
  31. {
  32. 'elapsed' => '1s',
  33. 'status_id' => 5
  34. },
  35. {
  36. 'elapsed' => '2s',
  37. 'status_id' => 4,
  38. 'comment' => 'zippy'
  39. }
  40. ];
  41. });
  42. #check doing things over all projects/plans/runs
  43. my @args = qw{--apiurl http://testrail.local --user test@fake.fake -password fake argument1 };
  44. my ($out, $code);
  45. my $captured = capture_merged { ($out,$code) = TestRail::Bin::Replay::run('args' => \@args) };
  46. subtest "Happy path" => sub {
  47. like($captured, qr/fake\.test \.\.\. ok/, "Expected output stream");
  48. like($out, qr/Done/,"Expected termination string");
  49. is($code,0,"OK Exit code");
  50. };
  51. @args = qw{--apiurl http://testrail.local --user test@fake.fake -password fake --plan argument1 };
  52. $captured = capture_merged { ($out,$code) = TestRail::Bin::Replay::run('args' => \@args) };
  53. subtest "Happy path - plan mode" => sub {
  54. like($captured, qr/fake\.test \.\.\. ok/, "Expected output stream");
  55. like($out, qr/Done/,"Expected termination string");
  56. is($code,0,"OK Exit code");
  57. };
  58. $apimock->redefine('getTestResults', sub {
  59. return [
  60. {
  61. 'elapsed' => '1s',
  62. 'status_id' => 5
  63. },
  64. {
  65. 'elapsed' => '2s',
  66. 'status_id' => 1,
  67. 'comment' => 'zippy'
  68. }
  69. ];
  70. });
  71. @args = qw{--apiurl http://testrail.local --user test@fake.fake -password fake --wait --plan argument1 };
  72. $captured = capture_merged { ($out,$code) = TestRail::Bin::Replay::run('args' => \@args) };
  73. subtest "Happy path - wait mode" => sub {
  74. like($captured, qr/fake\.test \.\.\. ok/, "Expected output stream");
  75. like($out, qr/Done/,"Expected termination string");
  76. is($code,0,"OK Exit code");
  77. };
  78. #Check help output
  79. @args = qw{--help};
  80. $0 = $FindBin::Bin.'/../bin/testrail-replay';
  81. ($out,(undef,$code)) = capture_merged {TestRail::Bin::Replay::run('args' => \@args)};
  82. is($code, 0, "Exit code OK asking for help");
  83. like($out,qr/encoding of arguments/i,"Help output OK");
  84. #Make sure that the binary itself processes args correctly
  85. $out = `$^X $0 --help`;
  86. like($out,qr/encoding of arguments/i,"Appears we can run binary successfully");