testrail-results.t 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. use strict;
  2. use warnings;
  3. use FindBin;
  4. use lib $FindBin::Bin.'/../bin';
  5. require 'testrail-results';
  6. use lib $FindBin::Bin.'/lib';
  7. use Test::LWP::UserAgent::TestRailMock;
  8. use Test::More 'tests' => 22;
  9. use Capture::Tiny qw{capture_merged};
  10. no warnings qw{redefine once};
  11. *TestRail::API::getTests = sub {
  12. my ($self,$run_id) = @_;
  13. return [
  14. {
  15. 'id' => 666,
  16. 'title' => 'fake.test',
  17. 'run_id' => $run_id
  18. }
  19. ];
  20. };
  21. *TestRail::API::getTestResults = sub {
  22. return [
  23. {
  24. 'elapsed' => '1s',
  25. 'status_id' => 5
  26. },
  27. {
  28. 'elapsed' => '2s',
  29. 'status_id' => 4,
  30. 'comment' => 'zippy'
  31. }
  32. ];
  33. };
  34. *TestRail::API::getPlanByID = sub {
  35. return {
  36. 'id' => 40000,
  37. 'name' => 'mah dubz plan',
  38. 'entries' => [{
  39. 'runs' => [
  40. {
  41. 'name' => 'planrun',
  42. 'id' => '999',
  43. 'plan_id' => 40000
  44. }
  45. ]
  46. }]
  47. };
  48. };
  49. use warnings;
  50. #check doing things over all projects/plans/runs
  51. my @args = qw{--apiurl http://testrail.local --user test@fake.fake --password fake t/fake.test };
  52. my ($out,$code) = TestRail::Bin::Results::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
  53. is($code, 0, "Exit code OK looking for results of fake.test");
  54. like($out,qr/fake\.test was present in 514 runs/,"Gets correct # of runs with test inside it");
  55. #check project filters
  56. @args = qw{--apiurl http://testrail.local --user test@fake.fake --password fake --project TestProject t/fake.test };
  57. ($out,$code) = TestRail::Bin::Results::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
  58. is($code, 0, "Exit code OK looking for results of fake.test");
  59. like($out,qr/fake\.test was present in 10 runs/,"Gets correct # of runs with test inside it when filtering by project name");
  60. #check plan filters
  61. @args = qw{--apiurl http://testrail.local --user test@fake.fake --password fake --plan };
  62. push(@args,'mah dubz plan', 't/fake.test');
  63. ($out,$code) = TestRail::Bin::Results::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
  64. is($code, 0, "Exit code OK looking for results of fake.test");
  65. like($out,qr/fake\.test was present in 257 runs/,"Gets correct # of runs with test inside it when filtering by plan name");
  66. #check run filters
  67. @args = qw{--apiurl http://testrail.local --user test@fake.fake --password fake --run FinalRun t/fake.test};
  68. ($out,$code) = TestRail::Bin::Results::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
  69. is($code, 0, "Exit code OK looking for results of fake.test");
  70. like($out,qr/fake\.test was present in 1 runs/,"Gets correct # of runs with test inside it when filtering by run name");
  71. #check pattern filters
  72. @args = qw{--apiurl http://testrail.local --user test@fake.fake --password fake --grep zippy t/fake.test};
  73. ($out,$code) = TestRail::Bin::Results::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
  74. is($code, 0, "Exit code OK looking for results of fake.test");
  75. like($out,qr/Retest: 514/,"Gets correct # & status of runs with test inside it when grepping");
  76. unlike($out,qr/Failed: 514/,"Gets correct # & status of runs with test inside it when grepping");
  77. @args = qw{--apiurl http://testrail.local --user test@fake.fake --password fake --json t/fake.test };
  78. ($out,$code) = TestRail::Bin::Results::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
  79. is($code, 0, "Exit code OK looking for results of fake.test in json mode");
  80. like($out,qr/num_runs/,"Gets # of runs with test inside it in json mode");
  81. #For making the test data to test the caching
  82. #open(my $fh, '>', "t/data/faketest_cache.json");
  83. #print $fh $out;
  84. #close($fh);
  85. #Check caching
  86. @args = qw{--apiurl http://testrail.local --user test@fake.fake --password fake --json --cachefile t/data/faketest_cache.json t/fake.test };
  87. ($out,$code) = TestRail::Bin::Results::run('browser' => $Test::LWP::UserAgent::TestRailMock::mockObject, 'args' => \@args);
  88. is($code, 0, "Exit code OK looking for results of fake.test in json mode");
  89. chomp $out;
  90. is($out,"{}","Caching mode works");
  91. #Check time parser
  92. is(TestRail::Bin::Results::_elapsed2secs('1s'),1,"elapsed2secs works : seconds");
  93. is(TestRail::Bin::Results::_elapsed2secs('1m'),60,"elapsed2secs works : minutes");
  94. is(TestRail::Bin::Results::_elapsed2secs('1h'),3600,"elapsed2secs works : hours");
  95. is(TestRail::Bin::Results::_elapsed2secs('1s1m1h'),3661,"elapsed2secs works :smh");
  96. #Check help output
  97. @args = qw{--help};
  98. $0 = $FindBin::Bin.'/../bin/testrail-runs';
  99. ($out,(undef,$code)) = capture_merged {TestRail::Bin::Results::run('args' => \@args)};
  100. is($code, 0, "Exit code OK asking for help");
  101. like($out,qr/encoding of arguments/i,"Help output OK");
  102. #Make sure that the binary itself processes args correctly
  103. $out = `$^X $0 --help`;
  104. like($out,qr/encoding of arguments/i,"Appears we can run binary successfully");