Test-Rail-Parser.t 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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' => 48;
  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. $fcontents = "ok 1 - STORAGE TANKS SEARED
  74. # whee
  75. not ok 2 - NOT SO SEARED AFTER ARR
  76. # Failed test 'NOT SO SEARED AFTER ARR'
  77. # at t/fake.test line 10.
  78. # Looks like you failed 1 test of 2.
  79. ";
  80. is($tap->{'raw_output'},$fcontents,"Full raw content uploaded in non step results mode");
  81. #Check that time run is being uploaded
  82. my $timeResults = $tap->{'tr_opts'}->{'testrail'}->getTestResults(1);
  83. if ( ( reftype($timeResults) || 'undef') eq 'ARRAY') {
  84. is( $timeResults->[0]->{'elapsed'}, '2s', "Plugin correctly sets elapsed time");
  85. } else {
  86. fail("Could not get test results to check elapsed time!");
  87. }
  88. #Check the time formatting routine.
  89. is(Test::Rail::Parser::_compute_elapsed(0,0),undef,"Elapsed computation correct at second boundary");
  90. is(Test::Rail::Parser::_compute_elapsed(0,61),'1m 1s',"Elapsed computation correct at minute boundary");
  91. is(Test::Rail::Parser::_compute_elapsed(0,3661),'1h 1m 1s',"Elapsed computation correct at hour boundary");
  92. is(Test::Rail::Parser::_compute_elapsed(0,86461),'24h 1m 1s',"Elapsed computation correct at day boundary");
  93. #Time for non case_per_ok mode
  94. undef $tap;
  95. $res = exception {
  96. $tap = Test::Rail::Parser->new({
  97. 'source' => 't/faker.test',
  98. 'apiurl' => $apiurl,
  99. 'user' => $login,
  100. 'pass' => $pw,
  101. 'debug' => $debug,
  102. 'browser' => $browser,
  103. 'run' => 'OtherOtherSuite',
  104. 'project' => 'TestProject',
  105. 'merge' => 1,
  106. 'step_results' => 'step_results'
  107. });
  108. };
  109. is($res,undef,"TR Parser doesn't explode on instantiation");
  110. isa_ok($tap,"Test::Rail::Parser");
  111. if (!$res) {
  112. $tap->run();
  113. is($tap->{'errors'},0,"No errors encountered uploading case results");
  114. }
  115. #Default mode
  116. undef $tap;
  117. $res = exception {
  118. $tap = Test::Rail::Parser->new({
  119. 'source' => 't/faker.test',
  120. 'apiurl' => $apiurl,
  121. 'user' => $login,
  122. 'pass' => $pw,
  123. 'debug' => $debug,
  124. 'browser' => $browser,
  125. 'run' => 'OtherOtherSuite',
  126. 'project' => 'TestProject',
  127. 'merge' => 1
  128. });
  129. };
  130. is($res,undef,"TR Parser doesn't explode on instantiation");
  131. isa_ok($tap,"Test::Rail::Parser");
  132. if (!$res) {
  133. $tap->run();
  134. is($tap->{'errors'},0,"No errors encountered uploading case results");
  135. }
  136. #Default mode
  137. undef $tap;
  138. $fcontents = "
  139. fake.test ..
  140. 1..2
  141. ok 1 - STORAGE TANKS SEARED
  142. #Subtest NOT SO SEARED AFTER ARR
  143. ok 1 - STROGGIFY POPULATION CENTERS
  144. not ok 2 - STROGGIFY POPULATION CENTERS
  145. #goo
  146. not ok 2 - NOT SO SEARED AFTER ARR
  147. ";
  148. $res = exception {
  149. $tap = Test::Rail::Parser->new({
  150. 'tap' => $fcontents,
  151. 'apiurl' => $apiurl,
  152. 'user' => $login,
  153. 'pass' => $pw,
  154. 'debug' => $debug,
  155. 'browser' => $browser,
  156. 'run' => 'TestingSuite',
  157. 'project' => 'TestProject',
  158. 'case_per_ok' => 1,
  159. 'merge' => 1
  160. });
  161. };
  162. is($res,undef,"TR Parser doesn't explode on instantiation");
  163. isa_ok($tap,"Test::Rail::Parser");
  164. if (!$res) {
  165. $tap->run();
  166. is($tap->{'errors'},0,"No errors encountered uploading case results");
  167. }
  168. #skip/todo in case_per_ok
  169. undef $tap;
  170. $res = exception {
  171. $tap = Test::Rail::Parser->new({
  172. 'source' => 't/skip.test',
  173. 'apiurl' => $apiurl,
  174. 'user' => $login,
  175. 'pass' => $pw,
  176. 'debug' => $debug,
  177. 'browser' => $browser,
  178. 'run' => 'TestingSuite',
  179. 'project' => 'TestProject',
  180. 'case_per_ok' => 1,
  181. 'merge' => 1
  182. });
  183. };
  184. is($res,undef,"TR Parser doesn't explode on instantiation");
  185. isa_ok($tap,"Test::Rail::Parser");
  186. if (!$res) {
  187. $tap->run();
  188. is($tap->{'errors'},0,"No errors encountered uploading case results");
  189. }
  190. #Default mode skip (skip_all)
  191. undef $tap;
  192. $res = exception {
  193. $tap = Test::Rail::Parser->new({
  194. 'source' => 't/skipall.test',
  195. 'apiurl' => $apiurl,
  196. 'user' => $login,
  197. 'pass' => $pw,
  198. 'debug' => $debug,
  199. 'browser' => $browser,
  200. 'run' => 'TestingSuite',
  201. 'project' => 'TestProject',
  202. 'merge' => 1
  203. });
  204. };
  205. is($res,undef,"TR Parser doesn't explode on instantiation");
  206. isa_ok($tap,"Test::Rail::Parser");
  207. if (!$res) {
  208. $tap->run();
  209. is($tap->{'errors'},0,"No errors encountered uploading case results");
  210. }
  211. #Ok, let's test the plan, config, and spawn bits.
  212. undef $tap;
  213. $res = exception {
  214. $tap = Test::Rail::Parser->new({
  215. 'source' => 't/skipall.test',
  216. 'apiurl' => $apiurl,
  217. 'user' => $login,
  218. 'pass' => $pw,
  219. 'debug' => $debug,
  220. 'browser' => $browser,
  221. 'run' => 'hoo hoo I do not exist',
  222. 'plan' => 'mah dubz plan',
  223. 'configs' => ['testPlatform1'],
  224. 'project' => 'TestProject',
  225. 'merge' => 1
  226. });
  227. };
  228. isnt($res,undef,"TR Parser explodes on instantiation when asking for run not in plan");
  229. undef $tap;
  230. $res = exception {
  231. $tap = Test::Rail::Parser->new({
  232. 'source' => 't/skipall.test',
  233. 'apiurl' => $apiurl,
  234. 'user' => $login,
  235. 'pass' => $pw,
  236. 'debug' => $debug,
  237. 'browser' => $browser,
  238. 'run' => 'TestingSuite',
  239. 'plan' => 'mah dubz plan',
  240. 'configs' => ['testConfig'],
  241. 'project' => 'TestProject',
  242. 'merge' => 1
  243. });
  244. };
  245. is($res,undef,"TR Parser doesn't explode on instantiation looking for existing run in plan");
  246. isa_ok($tap,"Test::Rail::Parser");
  247. if (!$res) {
  248. $tap->run();
  249. is($tap->{'errors'},0,"No errors encountered uploading case results");
  250. }
  251. #Now, test spawning.
  252. undef $tap;
  253. $res = exception {
  254. $tap = Test::Rail::Parser->new({
  255. 'source' => 't/skipall.test',
  256. 'apiurl' => $apiurl,
  257. 'user' => $login,
  258. 'pass' => $pw,
  259. 'debug' => $debug,
  260. 'browser' => $browser,
  261. 'run' => 'TestingSuite2',
  262. 'plan' => 'mah dubz plan',
  263. 'configs' => ['testPlatform1'],
  264. 'project' => 'TestProject',
  265. 'spawn' => 9,
  266. 'merge' => 1
  267. });
  268. };
  269. is($res,undef,"TR Parser doesn't explode on instantiation when spawning run in plan");
  270. isa_ok($tap,"Test::Rail::Parser");
  271. if (!$res) {
  272. $tap->run();
  273. is($tap->{'errors'},0,"No errors encountered uploading case results");
  274. }
  275. #Test spawning of builds not in plans.
  276. #Now, test spawning.
  277. undef $tap;
  278. $res = exception {
  279. $tap = Test::Rail::Parser->new({
  280. 'source' => 't/skipall.test',
  281. 'apiurl' => $apiurl,
  282. 'user' => $login,
  283. 'pass' => $pw,
  284. 'debug' => $debug,
  285. 'browser' => $browser,
  286. 'run' => 'TestingSuite2',
  287. 'project' => 'TestProject',
  288. 'spawn' => 9,
  289. 'merge' => 1
  290. });
  291. };
  292. is($res,undef,"TR Parser doesn't explode on instantiation when spawning run in plan");
  293. isa_ok($tap,"Test::Rail::Parser");
  294. if (!$res) {
  295. $tap->run();
  296. is($tap->{'errors'},0,"No errors encountered uploading case results");
  297. }
  298. #Test spawning of plans and runs.
  299. undef $tap;
  300. $res = exception {
  301. $tap = Test::Rail::Parser->new({
  302. 'source' => 't/skipall.test',
  303. 'apiurl' => $apiurl,
  304. 'user' => $login,
  305. 'pass' => $pw,
  306. 'debug' => $debug,
  307. 'browser' => $browser,
  308. 'run' => 'BogoRun',
  309. 'plan' => 'BogoPlan',
  310. 'project' => 'TestProject',
  311. 'spawn' => 9,
  312. 'merge' => 1
  313. });
  314. };
  315. is($res,undef,"TR Parser doesn't explode on instantiation when spawning run in plan");
  316. isa_ok($tap,"Test::Rail::Parser");
  317. if (!$res) {
  318. $tap->run();
  319. is($tap->{'errors'},0,"No errors encountered uploading case results");
  320. }
  321. #Verify that case_per_ok and step_results are mutually exclusive, and die.
  322. undef $tap;
  323. $res = exception {
  324. $tap = Test::Rail::Parser->new({
  325. 'source' => 't/skipall.test',
  326. 'apiurl' => $apiurl,
  327. 'user' => $login,
  328. 'pass' => $pw,
  329. 'debug' => $debug,
  330. 'browser' => $browser,
  331. 'run' => 'BogoRun',
  332. 'plan' => 'BogoPlan',
  333. 'project' => 'TestProject',
  334. 'spawn' => 9,
  335. 'merge' => 1,
  336. 'case_per_ok' => 1,
  337. 'step_results' => 'sr_step_results'
  338. });
  339. };
  340. isnt($res,undef,"TR Parser explodes on instantiation when mutually exclusive options are passed");
  341. #Check that per-section spawn works
  342. undef $tap;
  343. $res = exception {
  344. $tap = Test::Rail::Parser->new({
  345. 'source' => 't/fake.test',
  346. 'apiurl' => $apiurl,
  347. 'user' => $login,
  348. 'pass' => $pw,
  349. 'debug' => $debug,
  350. 'browser' => $browser,
  351. 'run' => 'BogoRun',
  352. 'project' => 'TestProject',
  353. 'merge' => 1,
  354. 'spawn' => 9,
  355. 'sections' => ['fake.test'],
  356. 'case_per_ok' => 1
  357. });
  358. };
  359. is($res,undef,"TR Parser doesn't explode on instantiation");
  360. isa_ok($tap,"Test::Rail::Parser");
  361. if (!$res) {
  362. $tap->run();
  363. is($tap->{'errors'},0,"No errors encountered uploading case results");
  364. }
  365. #Check that per-section spawn works
  366. undef $tap;
  367. $res = exception {
  368. $tap = Test::Rail::Parser->new({
  369. 'source' => 't/fake.test',
  370. 'apiurl' => $apiurl,
  371. 'user' => $login,
  372. 'pass' => $pw,
  373. 'debug' => $debug,
  374. 'browser' => $browser,
  375. 'run' => 'BogoRun',
  376. 'plan' => 'BogoPlan',
  377. 'project' => 'TestProject',
  378. 'merge' => 1,
  379. 'spawn' => 9,
  380. 'sections' => ['fake.test'],
  381. 'case_per_ok' => 1
  382. });
  383. };
  384. is($res,undef,"TR Parser doesn't explode on instantiation");
  385. isa_ok($tap,"Test::Rail::Parser");
  386. if (!$res) {
  387. $tap->run();
  388. is($tap->{'errors'},0,"No errors encountered uploading case results");
  389. }
  390. undef $tap;
  391. $res = exception {
  392. $tap = Test::Rail::Parser->new({
  393. 'source' => 't/fake.test',
  394. 'apiurl' => $apiurl,
  395. 'user' => $login,
  396. 'pass' => $pw,
  397. 'debug' => $debug,
  398. 'browser' => $browser,
  399. 'run' => 'BogoRun',
  400. 'project' => 'TestProject',
  401. 'merge' => 1,
  402. 'spawn' => 9,
  403. 'sections' => ['potzrebie'],
  404. 'case_per_ok' => 1
  405. });
  406. };
  407. isnt($res,undef,"TR Parser explodes on instantiation with invalid section");
  408. 0;