Test-Rail-Parser.t 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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' => 40;
  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. #Ok, let's test the plan, config, and spawn bits.
  204. undef $tap;
  205. $res = exception {
  206. $tap = Test::Rail::Parser->new({
  207. 'source' => 't/skipall.test',
  208. 'apiurl' => $apiurl,
  209. 'user' => $login,
  210. 'pass' => $pw,
  211. 'debug' => $debug,
  212. 'browser' => $browser,
  213. 'run' => 'hoo hoo I do not exist',
  214. 'plan' => 'mah dubz plan',
  215. 'configs' => ['testPlatform1'],
  216. 'project' => 'TestProject',
  217. 'merge' => 1
  218. });
  219. };
  220. isnt($res,undef,"TR Parser explodes on instantiation when asking for run not in plan");
  221. undef $tap;
  222. $res = exception {
  223. $tap = Test::Rail::Parser->new({
  224. 'source' => 't/skipall.test',
  225. 'apiurl' => $apiurl,
  226. 'user' => $login,
  227. 'pass' => $pw,
  228. 'debug' => $debug,
  229. 'browser' => $browser,
  230. 'run' => 'TestingSuite',
  231. 'plan' => 'mah dubz plan',
  232. 'configs' => ['testPlatform1'],
  233. 'project' => 'TestProject',
  234. 'merge' => 1
  235. });
  236. };
  237. is($res,undef,"TR Parser doesn't explode on instantiation looking for existing run in plan");
  238. isa_ok($tap,"Test::Rail::Parser");
  239. if (!$res) {
  240. $tap->run();
  241. is($tap->{'errors'},0,"No errors encountered uploading case results");
  242. }
  243. #Now, test spawning.
  244. undef $tap;
  245. $res = exception {
  246. $tap = Test::Rail::Parser->new({
  247. 'source' => 't/skipall.test',
  248. 'apiurl' => $apiurl,
  249. 'user' => $login,
  250. 'pass' => $pw,
  251. 'debug' => $debug,
  252. 'browser' => $browser,
  253. 'run' => 'TestingSuite2',
  254. 'plan' => 'mah dubz plan',
  255. 'configs' => ['testPlatform1'],
  256. 'project' => 'TestProject',
  257. 'spawn' => 9,
  258. 'merge' => 1
  259. });
  260. };
  261. is($res,undef,"TR Parser doesn't explode on instantiation when spawning run in plan");
  262. isa_ok($tap,"Test::Rail::Parser");
  263. if (!$res) {
  264. $tap->run();
  265. is($tap->{'errors'},0,"No errors encountered uploading case results");
  266. }
  267. #Test spawning of builds not in plans.
  268. #Now, test spawning.
  269. undef $tap;
  270. $res = exception {
  271. $tap = Test::Rail::Parser->new({
  272. 'source' => 't/skipall.test',
  273. 'apiurl' => $apiurl,
  274. 'user' => $login,
  275. 'pass' => $pw,
  276. 'debug' => $debug,
  277. 'browser' => $browser,
  278. 'run' => 'TestingSuite2',
  279. 'project' => 'TestProject',
  280. 'spawn' => 9,
  281. 'merge' => 1
  282. });
  283. };
  284. is($res,undef,"TR Parser doesn't explode on instantiation when spawning run in plan");
  285. isa_ok($tap,"Test::Rail::Parser");
  286. if (!$res) {
  287. $tap->run();
  288. is($tap->{'errors'},0,"No errors encountered uploading case results");
  289. }
  290. #Test spawning of plans and runs.
  291. undef $tap;
  292. $res = exception {
  293. $tap = Test::Rail::Parser->new({
  294. 'source' => 't/skipall.test',
  295. 'apiurl' => $apiurl,
  296. 'user' => $login,
  297. 'pass' => $pw,
  298. 'debug' => $debug,
  299. 'browser' => $browser,
  300. 'run' => 'BogoRun',
  301. 'plan' => 'BogoPlan',
  302. 'project' => 'TestProject',
  303. 'spawn' => 9,
  304. 'merge' => 1
  305. });
  306. };
  307. is($res,undef,"TR Parser doesn't explode on instantiation when spawning run in plan");
  308. isa_ok($tap,"Test::Rail::Parser");
  309. if (!$res) {
  310. $tap->run();
  311. is($tap->{'errors'},0,"No errors encountered uploading case results");
  312. }
  313. #Verify that case_per_ok and step_results are mutually exclusive, and die.
  314. undef $tap;
  315. $res = exception {
  316. $tap = Test::Rail::Parser->new({
  317. 'source' => 't/skipall.test',
  318. 'apiurl' => $apiurl,
  319. 'user' => $login,
  320. 'pass' => $pw,
  321. 'debug' => $debug,
  322. 'browser' => $browser,
  323. 'run' => 'BogoRun',
  324. 'plan' => 'BogoPlan',
  325. 'project' => 'TestProject',
  326. 'spawn' => 9,
  327. 'merge' => 1,
  328. 'case_per_ok' => 1,
  329. 'step_results' => 'sr_step_results'
  330. });
  331. };
  332. isnt($res,undef,"TR Parser explodes on instantiation when mutually exclusive options are passed");
  333. 0;