testrail-replay.t 3.2 KB

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