Test-Rail-Parser.t 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. use Scalar::Util qw{reftype};
  5. use TestRail::API;
  6. use Test::LWP::UserAgent::TestRailMock;
  7. use Test::Rail::Parser;
  8. use Test::More 'tests' => 26;
  9. use Test::Fatal qw{exception};
  10. #Same song and dance as in TestRail-API.t
  11. my $apiurl = $ENV{'TESTRAIL_API_URL'};
  12. my $login = $ENV{'TESTRAIL_USER'};
  13. my $pw = $ENV{'TESTRAIL_PASSWORD'};
  14. my $is_mock = (!$apiurl && !$login && !$pw);
  15. ($apiurl,$login,$pw) = ('http://testrail.local','teodesian@cpan.org','fake') if $is_mock;
  16. my ($debug,$browser);
  17. $debug = 1;
  18. if ($is_mock) {
  19. $browser = $Test::LWP::UserAgent::TestRailMock::mockObject;
  20. }
  21. #test exceptions...
  22. #TODO
  23. #case_per_ok mode
  24. my $fcontents = "
  25. fake.test ..
  26. 1..2
  27. ok 1 - STORAGE TANKS SEARED
  28. #goo
  29. not ok 2 - NOT SO SEARED AFTER ARR
  30. ";
  31. my $tap;
  32. my $res = exception {
  33. $tap = Test::Rail::Parser->new({
  34. 'tap' => $fcontents,
  35. 'apiurl' => $apiurl,
  36. 'user' => $login,
  37. 'pass' => $pw,
  38. 'debug' => $debug,
  39. 'browser' => $browser,
  40. 'run' => 'TestingSuite',
  41. 'project' => 'TestProject',
  42. 'merge' => 1,
  43. 'case_per_ok' => 1
  44. });
  45. };
  46. is($res,undef,"TR Parser doesn't explode on instantiation");
  47. isa_ok($tap,"Test::Rail::Parser");
  48. if (!$res) {
  49. $tap->run();
  50. is($tap->{'errors'},0,"No errors encountered uploading case results");
  51. }
  52. undef $tap;
  53. $res = exception {
  54. $tap = Test::Rail::Parser->new({
  55. 'source' => 't/fake.test',
  56. 'apiurl' => $apiurl,
  57. 'user' => $login,
  58. 'pass' => $pw,
  59. 'debug' => $debug,
  60. 'browser' => $browser,
  61. 'run' => 'TestingSuite',
  62. 'project' => 'TestProject',
  63. 'merge' => 1,
  64. 'case_per_ok' => 1
  65. });
  66. };
  67. is($res,undef,"TR Parser doesn't explode on instantiation");
  68. isa_ok($tap,"Test::Rail::Parser");
  69. if (!$res) {
  70. $tap->run();
  71. is($tap->{'errors'},0,"No errors encountered uploading case results");
  72. }
  73. #Check that time run is being uploaded
  74. my $timeResults = $tap->{'tr_opts'}->{'testrail'}->getTestResults(1);
  75. if ( ( reftype($timeResults) || 'undef') eq 'ARRAY') {
  76. is( $timeResults->[0]->{'elapsed'}, '2s', "Plugin correctly sets elapsed time");
  77. } else {
  78. fail("Could not get test results to check elapsed time!");
  79. }
  80. #Check the time formatting routine.
  81. is(Test::Rail::Parser::_compute_elapsed(0,0),undef,"Elapsed computation correct at second boundary");
  82. is(Test::Rail::Parser::_compute_elapsed(0,61),'1m 1s',"Elapsed computation correct at minute boundary");
  83. is(Test::Rail::Parser::_compute_elapsed(0,3661),'1h 1m 1s',"Elapsed computation correct at hour boundary");
  84. is(Test::Rail::Parser::_compute_elapsed(0,86461),'24h 1m 1s',"Elapsed computation correct at day boundary");
  85. #Time for non case_per_ok mode
  86. undef $tap;
  87. $res = exception {
  88. $tap = Test::Rail::Parser->new({
  89. 'source' => 't/faker.test',
  90. 'apiurl' => $apiurl,
  91. 'user' => $login,
  92. 'pass' => $pw,
  93. 'debug' => $debug,
  94. 'browser' => $browser,
  95. 'run' => 'OtherOtherSuite',
  96. 'project' => 'TestProject',
  97. 'merge' => 1,
  98. 'step_results' => 'step_results'
  99. });
  100. };
  101. is($res,undef,"TR Parser doesn't explode on instantiation");
  102. isa_ok($tap,"Test::Rail::Parser");
  103. if (!$res) {
  104. $tap->run();
  105. is($tap->{'errors'},0,"No errors encountered uploading case results");
  106. }
  107. #Default mode
  108. undef $tap;
  109. $res = exception {
  110. $tap = Test::Rail::Parser->new({
  111. 'source' => 't/faker.test',
  112. 'apiurl' => $apiurl,
  113. 'user' => $login,
  114. 'pass' => $pw,
  115. 'debug' => $debug,
  116. 'browser' => $browser,
  117. 'run' => 'OtherOtherSuite',
  118. 'project' => 'TestProject',
  119. 'merge' => 1
  120. });
  121. };
  122. is($res,undef,"TR Parser doesn't explode on instantiation");
  123. isa_ok($tap,"Test::Rail::Parser");
  124. if (!$res) {
  125. $tap->run();
  126. is($tap->{'errors'},0,"No errors encountered uploading case results");
  127. }
  128. #Default mode
  129. undef $tap;
  130. $fcontents = "
  131. fake.test ..
  132. 1..2
  133. ok 1 - STORAGE TANKS SEARED
  134. #Subtest NOT SO SEARED AFTER ARR
  135. ok 1 - STROGGIFY POPULATION CENTERS
  136. not ok 2 - STROGGIFY POPULATION CENTERS
  137. #goo
  138. not ok 2 - NOT SO SEARED AFTER ARR
  139. ";
  140. $res = exception {
  141. $tap = Test::Rail::Parser->new({
  142. 'tap' => $fcontents,
  143. 'apiurl' => $apiurl,
  144. 'user' => $login,
  145. 'pass' => $pw,
  146. 'debug' => $debug,
  147. 'browser' => $browser,
  148. 'run' => 'TestingSuite',
  149. 'project' => 'TestProject',
  150. 'case_per_ok' => 1,
  151. 'merge' => 1
  152. });
  153. };
  154. is($res,undef,"TR Parser doesn't explode on instantiation");
  155. isa_ok($tap,"Test::Rail::Parser");
  156. if (!$res) {
  157. $tap->run();
  158. is($tap->{'errors'},0,"No errors encountered uploading case results");
  159. }
  160. #skip/todo in case_per_ok
  161. undef $tap;
  162. $res = exception {
  163. $tap = Test::Rail::Parser->new({
  164. 'source' => 't/skip.test',
  165. 'apiurl' => $apiurl,
  166. 'user' => $login,
  167. 'pass' => $pw,
  168. 'debug' => $debug,
  169. 'browser' => $browser,
  170. 'run' => 'TestingSuite',
  171. 'project' => 'TestProject',
  172. 'case_per_ok' => 1,
  173. 'merge' => 1
  174. });
  175. };
  176. is($res,undef,"TR Parser doesn't explode on instantiation");
  177. isa_ok($tap,"Test::Rail::Parser");
  178. if (!$res) {
  179. $tap->run();
  180. is($tap->{'errors'},0,"No errors encountered uploading case results");
  181. }
  182. #Default mode skip (skip_all)
  183. undef $tap;
  184. $res = exception {
  185. $tap = Test::Rail::Parser->new({
  186. 'source' => 't/skipall.test',
  187. 'apiurl' => $apiurl,
  188. 'user' => $login,
  189. 'pass' => $pw,
  190. 'debug' => $debug,
  191. 'browser' => $browser,
  192. 'run' => 'TestingSuite',
  193. 'project' => 'TestProject',
  194. 'merge' => 1
  195. });
  196. };
  197. is($res,undef,"TR Parser doesn't explode on instantiation");
  198. isa_ok($tap,"Test::Rail::Parser");
  199. if (!$res) {
  200. $tap->run();
  201. is($tap->{'errors'},0,"No errors encountered uploading case results");
  202. }
  203. 0;