Test-Rail-Parser.t 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. use FindBin;
  5. use lib "$FindBin::Bin/lib";
  6. use Scalar::Util qw{reftype};
  7. use TestRail::API;
  8. use Test::LWP::UserAgent::TestRailMock;
  9. use Test::Rail::Parser;
  10. use Test::More 'tests' => 78;
  11. use Test::Fatal qw{exception};
  12. #Same song and dance as in TestRail-API.t
  13. my $apiurl = $ENV{'TESTRAIL_API_URL'};
  14. my $login = $ENV{'TESTRAIL_USER'};
  15. my $pw = $ENV{'TESTRAIL_PASSWORD'};
  16. my $is_mock = (!$apiurl && !$login && !$pw);
  17. ($apiurl,$login,$pw) = ('http://testrail.local','teodesian@cpan.org','fake') if $is_mock;
  18. my ($debug,$browser);
  19. $debug = 1;
  20. if ($is_mock) {
  21. $browser = $Test::LWP::UserAgent::TestRailMock::mockObject;
  22. }
  23. #test exceptions...
  24. #TODO
  25. #case_per_ok mode
  26. my $fcontents = "
  27. fake.test ..
  28. 1..2
  29. ok 1 - STORAGE TANKS SEARED
  30. #goo
  31. not ok 2 - NOT SO SEARED AFTER ARR
  32. ";
  33. my $tap;
  34. my $res = exception {
  35. $tap = Test::Rail::Parser->new({
  36. 'tap' => $fcontents,
  37. 'apiurl' => $apiurl,
  38. 'user' => $login,
  39. 'pass' => $pw,
  40. 'debug' => $debug,
  41. 'browser' => $browser,
  42. 'run' => 'TestingSuite',
  43. 'project' => 'TestProject',
  44. 'merge' => 1,
  45. 'case_per_ok' => 1
  46. });
  47. };
  48. is($res,undef,"TR Parser doesn't explode on instantiation");
  49. isa_ok($tap,"Test::Rail::Parser");
  50. if (!$res) {
  51. $tap->run();
  52. is($tap->{'errors'},0,"No errors encountered uploading case results");
  53. }
  54. undef $tap;
  55. $res = exception {
  56. $tap = Test::Rail::Parser->new({
  57. 'source' => 't/fake.test',
  58. 'apiurl' => $apiurl,
  59. 'user' => $login,
  60. 'pass' => $pw,
  61. 'debug' => $debug,
  62. 'browser' => $browser,
  63. 'run' => 'TestingSuite',
  64. 'project' => 'TestProject',
  65. 'merge' => 1,
  66. 'case_per_ok' => 1
  67. });
  68. };
  69. is($res,undef,"TR Parser doesn't explode on instantiation");
  70. isa_ok($tap,"Test::Rail::Parser");
  71. if (!$res) {
  72. $tap->run();
  73. is($tap->{'errors'},0,"No errors encountered uploading case results");
  74. }
  75. $fcontents = "ok 1 - STORAGE TANKS SEARED
  76. # whee
  77. not ok 2 - NOT SO SEARED AFTER ARR
  78. # Failed test 'NOT SO SEARED AFTER ARR'
  79. # at t/fake.test line 10.
  80. # Looks like you failed 1 test of 2.
  81. ";
  82. is($tap->{'raw_output'},$fcontents,"Full raw content uploaded in non step results mode");
  83. #Check that time run is being uploaded
  84. my $timeResults = $tap->{'tr_opts'}->{'testrail'}->getTestResults(1);
  85. if ( ( reftype($timeResults) || 'undef') eq 'ARRAY') {
  86. is( $timeResults->[0]->{'elapsed'}, '2s', "Plugin correctly sets elapsed time");
  87. } else {
  88. fail("Could not get test results to check elapsed time!");
  89. }
  90. #Check the time formatting routine.
  91. is(Test::Rail::Parser::_compute_elapsed(0,0),undef,"Elapsed computation correct at second boundary");
  92. is(Test::Rail::Parser::_compute_elapsed(0,61),'1m 1s',"Elapsed computation correct at minute boundary");
  93. is(Test::Rail::Parser::_compute_elapsed(0,3661),'1h 1m 1s',"Elapsed computation correct at hour boundary");
  94. is(Test::Rail::Parser::_compute_elapsed(0,86461),'24h 1m 1s',"Elapsed computation correct at day boundary");
  95. #Time for non case_per_ok mode
  96. undef $tap;
  97. $res = exception {
  98. $tap = Test::Rail::Parser->new({
  99. 'source' => 't/faker.test',
  100. 'apiurl' => $apiurl,
  101. 'user' => $login,
  102. 'pass' => $pw,
  103. 'debug' => $debug,
  104. 'browser' => $browser,
  105. 'run' => 'OtherOtherSuite',
  106. 'project' => 'TestProject',
  107. 'merge' => 1,
  108. 'step_results' => 'step_results'
  109. });
  110. };
  111. is($res,undef,"TR Parser doesn't explode on instantiation");
  112. isa_ok($tap,"Test::Rail::Parser");
  113. if (!$res) {
  114. $tap->run();
  115. is($tap->{'errors'},0,"No errors encountered uploading case results");
  116. is($tap->{'global_status'},5, "Test global result is FAIL when one subtest fails even if there are TODO passes");
  117. }
  118. #Default mode
  119. undef $tap;
  120. $res = exception {
  121. $tap = Test::Rail::Parser->new({
  122. 'source' => 't/faker.test',
  123. 'apiurl' => $apiurl,
  124. 'user' => $login,
  125. 'pass' => $pw,
  126. 'debug' => $debug,
  127. 'browser' => $browser,
  128. 'run' => 'OtherOtherSuite',
  129. 'project' => 'TestProject',
  130. 'merge' => 1
  131. });
  132. };
  133. is($res,undef,"TR Parser doesn't explode on instantiation");
  134. isa_ok($tap,"Test::Rail::Parser");
  135. if (!$res) {
  136. $tap->run();
  137. is($tap->{'errors'},0,"No errors encountered uploading case results");
  138. }
  139. #Default mode
  140. undef $tap;
  141. $fcontents = "
  142. fake.test ..
  143. 1..2
  144. ok 1 - STORAGE TANKS SEARED
  145. #Subtest NOT SO SEARED AFTER ARR
  146. ok 1 - STROGGIFY POPULATION CENTERS
  147. not ok 2 - STROGGIFY POPULATION CENTERS
  148. #goo
  149. not ok 2 - NOT SO SEARED AFTER ARR
  150. ";
  151. $res = exception {
  152. $tap = Test::Rail::Parser->new({
  153. 'tap' => $fcontents,
  154. 'apiurl' => $apiurl,
  155. 'user' => $login,
  156. 'pass' => $pw,
  157. 'debug' => $debug,
  158. 'browser' => $browser,
  159. 'run' => 'TestingSuite',
  160. 'project' => 'TestProject',
  161. 'case_per_ok' => 1,
  162. 'merge' => 1
  163. });
  164. };
  165. is($res,undef,"TR Parser doesn't explode on instantiation");
  166. isa_ok($tap,"Test::Rail::Parser");
  167. if (!$res) {
  168. $tap->run();
  169. is($tap->{'errors'},0,"No errors encountered uploading case results");
  170. }
  171. #skip/todo in case_per_ok
  172. undef $tap;
  173. $res = exception {
  174. $tap = Test::Rail::Parser->new({
  175. 'source' => 't/skip.test',
  176. 'apiurl' => $apiurl,
  177. 'user' => $login,
  178. 'pass' => $pw,
  179. 'debug' => $debug,
  180. 'browser' => $browser,
  181. 'run' => 'TestingSuite',
  182. 'project' => 'TestProject',
  183. 'case_per_ok' => 1,
  184. 'merge' => 1
  185. });
  186. };
  187. is($res,undef,"TR Parser doesn't explode on instantiation");
  188. isa_ok($tap,"Test::Rail::Parser");
  189. if (!$res) {
  190. $tap->run();
  191. is($tap->{'errors'},0,"No errors encountered uploading case results");
  192. }
  193. #Default mode skip (skip_all)
  194. undef $tap;
  195. $res = exception {
  196. $tap = Test::Rail::Parser->new({
  197. 'source' => 't/skipall.test',
  198. 'apiurl' => $apiurl,
  199. 'user' => $login,
  200. 'pass' => $pw,
  201. 'debug' => $debug,
  202. 'browser' => $browser,
  203. 'run' => 'TestingSuite',
  204. 'project' => 'TestProject',
  205. 'merge' => 1
  206. });
  207. };
  208. is($res,undef,"TR Parser doesn't explode on instantiation");
  209. isa_ok($tap,"Test::Rail::Parser");
  210. if (!$res) {
  211. $tap->run();
  212. is($tap->{'errors'},0,"No errors encountered uploading case results");
  213. is($tap->{'global_status'},6, "Test global result is SKIP on skip all");
  214. }
  215. #Ok, let's test the plan, config, and spawn bits.
  216. undef $tap;
  217. $res = exception {
  218. $tap = Test::Rail::Parser->new({
  219. 'source' => 't/skipall.test',
  220. 'apiurl' => $apiurl,
  221. 'user' => $login,
  222. 'pass' => $pw,
  223. 'debug' => $debug,
  224. 'browser' => $browser,
  225. 'run' => 'hoo hoo I do not exist',
  226. 'plan' => 'mah dubz plan',
  227. 'configs' => ['testPlatform1'],
  228. 'project' => 'TestProject',
  229. 'merge' => 1
  230. });
  231. };
  232. isnt($res,undef,"TR Parser explodes on instantiation when asking for run not in plan");
  233. undef $tap;
  234. $res = exception {
  235. $tap = Test::Rail::Parser->new({
  236. 'source' => 't/skipall.test',
  237. 'apiurl' => $apiurl,
  238. 'user' => $login,
  239. 'pass' => $pw,
  240. 'debug' => $debug,
  241. 'browser' => $browser,
  242. 'run' => 'TestingSuite',
  243. 'plan' => 'mah dubz plan',
  244. 'configs' => ['testConfig'],
  245. 'project' => 'TestProject',
  246. 'merge' => 1
  247. });
  248. };
  249. is($res,undef,"TR Parser doesn't explode on instantiation looking for existing run in plan");
  250. isa_ok($tap,"Test::Rail::Parser");
  251. if (!$res) {
  252. $tap->run();
  253. is($tap->{'errors'},0,"No errors encountered uploading case results");
  254. }
  255. #Now, test spawning.
  256. undef $tap;
  257. $res = exception {
  258. $tap = Test::Rail::Parser->new({
  259. 'source' => 't/skipall.test',
  260. 'apiurl' => $apiurl,
  261. 'user' => $login,
  262. 'pass' => $pw,
  263. 'debug' => $debug,
  264. 'browser' => $browser,
  265. 'run' => 'TestingSuite2',
  266. 'plan' => 'mah dubz plan',
  267. 'configs' => ['testPlatform1'],
  268. 'project' => 'TestProject',
  269. 'testsuite_id' => 9,
  270. 'merge' => 1
  271. });
  272. };
  273. is($res,undef,"TR Parser doesn't explode on instantiation when spawning run in plan");
  274. isa_ok($tap,"Test::Rail::Parser");
  275. if (!$res) {
  276. $tap->run();
  277. is($tap->{'errors'},0,"No errors encountered uploading case results");
  278. }
  279. #Test spawning of builds not in plans.
  280. #Now, test spawning.
  281. undef $tap;
  282. $res = exception {
  283. $tap = Test::Rail::Parser->new({
  284. 'source' => 't/skipall.test',
  285. 'apiurl' => $apiurl,
  286. 'user' => $login,
  287. 'pass' => $pw,
  288. 'debug' => $debug,
  289. 'browser' => $browser,
  290. 'run' => 'TestingSuite2',
  291. 'project' => 'TestProject',
  292. 'testsuite' => 'HAMBURGER-IZE HUMANITY',
  293. 'merge' => 1
  294. });
  295. };
  296. is($res,undef,"TR Parser doesn't explode on instantiation when spawning run in plan");
  297. isa_ok($tap,"Test::Rail::Parser");
  298. if (!$res) {
  299. $tap->run();
  300. is($tap->{'errors'},0,"No errors encountered uploading case results");
  301. }
  302. #Test spawning of plans and runs.
  303. undef $tap;
  304. $res = exception {
  305. $tap = Test::Rail::Parser->new({
  306. 'source' => 't/skipall.test',
  307. 'apiurl' => $apiurl,
  308. 'user' => $login,
  309. 'pass' => $pw,
  310. 'debug' => $debug,
  311. 'browser' => $browser,
  312. 'run' => 'BogoRun',
  313. 'plan' => 'BogoPlan',
  314. 'project' => 'TestProject',
  315. 'testsuite_id' => 9,
  316. 'merge' => 1
  317. });
  318. };
  319. is($res,undef,"TR Parser doesn't explode on instantiation when spawning run in plan");
  320. isa_ok($tap,"Test::Rail::Parser");
  321. if (!$res) {
  322. $tap->run();
  323. is($tap->{'errors'},0,"No errors encountered uploading case results");
  324. }
  325. #Verify that case_per_ok and step_results are mutually exclusive, and die.
  326. undef $tap;
  327. $res = exception {
  328. $tap = Test::Rail::Parser->new({
  329. 'source' => 't/skipall.test',
  330. 'apiurl' => $apiurl,
  331. 'user' => $login,
  332. 'pass' => $pw,
  333. 'debug' => $debug,
  334. 'browser' => $browser,
  335. 'run' => 'BogoRun',
  336. 'plan' => 'BogoPlan',
  337. 'project' => 'TestProject',
  338. 'testsuite_id' => 9,
  339. 'merge' => 1,
  340. 'case_per_ok' => 1,
  341. 'step_results' => 'sr_step_results'
  342. });
  343. };
  344. isnt($res,undef,"TR Parser explodes on instantiation when mutually exclusive options are passed");
  345. #Check that per-section spawn works
  346. undef $tap;
  347. $res = exception {
  348. $tap = Test::Rail::Parser->new({
  349. 'source' => 't/fake.test',
  350. 'apiurl' => $apiurl,
  351. 'user' => $login,
  352. 'pass' => $pw,
  353. 'debug' => $debug,
  354. 'browser' => $browser,
  355. 'run' => 'BogoRun',
  356. 'project' => 'TestProject',
  357. 'merge' => 1,
  358. 'testsuite_id' => 9,
  359. 'sections' => ['fake.test'],
  360. 'case_per_ok' => 1
  361. });
  362. };
  363. is($res,undef,"TR Parser doesn't explode on instantiation");
  364. isa_ok($tap,"Test::Rail::Parser");
  365. if (!$res) {
  366. $tap->run();
  367. is($tap->{'errors'},0,"No errors encountered uploading case results");
  368. }
  369. #Check that per-section spawn works
  370. undef $tap;
  371. $res = exception {
  372. $tap = Test::Rail::Parser->new({
  373. 'source' => 't/fake.test',
  374. 'apiurl' => $apiurl,
  375. 'user' => $login,
  376. 'pass' => $pw,
  377. 'debug' => $debug,
  378. 'browser' => $browser,
  379. 'run' => 'BogoRun',
  380. 'plan' => 'BogoPlan',
  381. 'project' => 'TestProject',
  382. 'merge' => 1,
  383. 'testsuite_id' => 9,
  384. 'sections' => ['fake.test'],
  385. 'case_per_ok' => 1
  386. });
  387. };
  388. is($res,undef,"TR Parser doesn't explode on instantiation");
  389. isa_ok($tap,"Test::Rail::Parser");
  390. if (!$res) {
  391. $tap->run();
  392. is($tap->{'errors'},0,"No errors encountered uploading case results");
  393. }
  394. undef $tap;
  395. $res = exception {
  396. $tap = Test::Rail::Parser->new({
  397. 'source' => 't/fake.test',
  398. 'apiurl' => $apiurl,
  399. 'user' => $login,
  400. 'pass' => $pw,
  401. 'debug' => $debug,
  402. 'browser' => $browser,
  403. 'run' => 'BogoRun',
  404. 'project' => 'TestProject',
  405. 'merge' => 1,
  406. 'testsuite_id' => 9,
  407. 'sections' => ['potzrebie'],
  408. 'case_per_ok' => 1
  409. });
  410. };
  411. isnt($res,undef,"TR Parser explodes on instantiation with invalid section");
  412. undef $tap;
  413. $res = exception {
  414. $tap = Test::Rail::Parser->new({
  415. 'source' => 't/notests.test',
  416. 'apiurl' => $apiurl,
  417. 'user' => $login,
  418. 'pass' => $pw,
  419. 'debug' => $debug,
  420. 'browser' => $browser,
  421. 'run' => 'BogoRun',
  422. 'project' => 'TestProject',
  423. 'merge' => 1,
  424. 'testsuite_id' => 9,
  425. });
  426. };
  427. is($res,undef,"TR Parser doesn't explode on instantiation");
  428. isa_ok($tap,"Test::Rail::Parser");
  429. if (!$res) {
  430. $tap->run();
  431. is($tap->{'errors'},0,"No errors encountered uploading case results");
  432. is($tap->{'global_status'},4, "Test global result is RETEST on env fail");
  433. }
  434. undef $tap;
  435. $res = exception {
  436. $tap = Test::Rail::Parser->new({
  437. 'source' => 't/pass.test',
  438. 'apiurl' => $apiurl,
  439. 'user' => $login,
  440. 'pass' => $pw,
  441. 'debug' => $debug,
  442. 'browser' => $browser,
  443. 'run' => 'BogoRun',
  444. 'project' => 'TestProject',
  445. 'merge' => 1,
  446. 'testsuite_id' => 9,
  447. });
  448. };
  449. is($res,undef,"TR Parser doesn't explode on instantiation");
  450. isa_ok($tap,"Test::Rail::Parser");
  451. if (!$res) {
  452. $tap->run();
  453. is($tap->{'errors'},0,"No errors encountered uploading case results");
  454. is($tap->{'global_status'},1, "Test global result is PASS on ok test");
  455. }
  456. undef $tap;
  457. $res = exception {
  458. $tap = Test::Rail::Parser->new({
  459. 'source' => 't/todo_pass.test',
  460. 'apiurl' => $apiurl,
  461. 'user' => $login,
  462. 'pass' => $pw,
  463. 'debug' => $debug,
  464. 'browser' => $browser,
  465. 'run' => 'BogoRun',
  466. 'project' => 'TestProject',
  467. 'merge' => 1,
  468. 'testsuite_id' => 9,
  469. });
  470. };
  471. is($res,undef,"TR Parser doesn't explode on instantiation");
  472. isa_ok($tap,"Test::Rail::Parser");
  473. if (!$res) {
  474. $tap->run();
  475. is($tap->{'errors'},0,"No errors encountered uploading case results");
  476. is($tap->{'global_status'},8, "Test global result is TODO PASS on todo pass test");
  477. }
  478. #Check autoclose functionality against Run with all tests in run status.
  479. undef $tap;
  480. $res = exception {
  481. $tap = Test::Rail::Parser->new({
  482. 'source' => 't/skip.test',
  483. 'apiurl' => $apiurl,
  484. 'user' => $login,
  485. 'pass' => $pw,
  486. 'debug' => $debug,
  487. 'browser' => $browser,
  488. 'run' => 'FinalRun',
  489. 'project' => 'TestProject',
  490. 'merge' => 1,
  491. 'autoclose' => 1,
  492. 'testsuite_id' => 9,
  493. });
  494. };
  495. is($res,undef,"TR Parser doesn't explode on instantiation");
  496. isa_ok($tap,"Test::Rail::Parser");
  497. if (!$res) {
  498. $tap->run();
  499. is($tap->{'errors'},0,"No errors encountered uploading case results");
  500. is($tap->{'run_closed'},1, "Run closed by parser when all tests done");
  501. }
  502. #Check autoclose functionality against Run with not all tests in run status.
  503. undef $tap;
  504. $res = exception {
  505. $tap = Test::Rail::Parser->new({
  506. 'source' => 't/todo_pass.test',
  507. 'apiurl' => $apiurl,
  508. 'user' => $login,
  509. 'pass' => $pw,
  510. 'debug' => $debug,
  511. 'browser' => $browser,
  512. 'run' => 'BogoRun',
  513. 'project' => 'TestProject',
  514. 'merge' => 1,
  515. 'autoclose' => 1,
  516. 'testsuite_id' => 9,
  517. });
  518. };
  519. is($res,undef,"TR Parser doesn't explode on instantiation");
  520. isa_ok($tap,"Test::Rail::Parser");
  521. if (!$res) {
  522. $tap->run();
  523. is($tap->{'errors'},0,"No errors encountered uploading case results");
  524. is($tap->{'run_closed'},undef, "Run not closed by parser when results are outstanding");
  525. }
  526. #Check that autoclose works against plan wiht all tests in run status
  527. undef $tap;
  528. $res = exception {
  529. $tap = Test::Rail::Parser->new({
  530. 'source' => 't/fake.test',
  531. 'apiurl' => $apiurl,
  532. 'user' => $login,
  533. 'pass' => $pw,
  534. 'debug' => $debug,
  535. 'browser' => $browser,
  536. 'run' => 'FinalRun',
  537. 'plan' => 'FinalPlan',
  538. 'project' => 'TestProject',
  539. 'configs' => ['testConfig'],
  540. 'merge' => 1,
  541. 'autoclose' => 1,
  542. 'case_per_ok' => 1
  543. });
  544. };
  545. is($res,undef,"TR Parser doesn't explode on instantiation");
  546. isa_ok($tap,"Test::Rail::Parser");
  547. if (!$res) {
  548. $tap->run();
  549. is($tap->{'errors'},0,"No errors encountered uploading case results");
  550. is($tap->{'plan_closed'},1, "Plan closed by parser when all tests done");
  551. }
  552. #Check that autoclose works against plan wiht all tests not in run status
  553. undef $tap;
  554. $res = exception {
  555. $tap = Test::Rail::Parser->new({
  556. 'source' => 't/fake.test',
  557. 'apiurl' => $apiurl,
  558. 'user' => $login,
  559. 'pass' => $pw,
  560. 'debug' => $debug,
  561. 'browser' => $browser,
  562. 'run' => 'BogoRun',
  563. 'plan' => 'BogoPlan',
  564. 'project' => 'TestProject',
  565. 'testsuite_id' => 9,
  566. 'merge' => 1,
  567. 'autoclose' => 1,
  568. 'case_per_ok' => 1
  569. });
  570. };
  571. is($res,undef,"TR Parser doesn't explode on instantiation");
  572. isa_ok($tap,"Test::Rail::Parser");
  573. if (!$res) {
  574. $tap->run();
  575. is($tap->{'errors'},0,"No errors encountered uploading case results");
  576. is($tap->{'plan_closed'},undef, "Plan not closed by parser when results are outstanding");
  577. }