Test-Rail-Parser.t 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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' => 58;
  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. is($tap->{'global_status'},5, "Test global result is FAIL when one subtest fails");
  115. }
  116. #Default mode
  117. undef $tap;
  118. $res = exception {
  119. $tap = Test::Rail::Parser->new({
  120. 'source' => 't/faker.test',
  121. 'apiurl' => $apiurl,
  122. 'user' => $login,
  123. 'pass' => $pw,
  124. 'debug' => $debug,
  125. 'browser' => $browser,
  126. 'run' => 'OtherOtherSuite',
  127. 'project' => 'TestProject',
  128. 'merge' => 1
  129. });
  130. };
  131. is($res,undef,"TR Parser doesn't explode on instantiation");
  132. isa_ok($tap,"Test::Rail::Parser");
  133. if (!$res) {
  134. $tap->run();
  135. is($tap->{'errors'},0,"No errors encountered uploading case results");
  136. }
  137. #Default mode
  138. undef $tap;
  139. $fcontents = "
  140. fake.test ..
  141. 1..2
  142. ok 1 - STORAGE TANKS SEARED
  143. #Subtest NOT SO SEARED AFTER ARR
  144. ok 1 - STROGGIFY POPULATION CENTERS
  145. not ok 2 - STROGGIFY POPULATION CENTERS
  146. #goo
  147. not ok 2 - NOT SO SEARED AFTER ARR
  148. ";
  149. $res = exception {
  150. $tap = Test::Rail::Parser->new({
  151. 'tap' => $fcontents,
  152. 'apiurl' => $apiurl,
  153. 'user' => $login,
  154. 'pass' => $pw,
  155. 'debug' => $debug,
  156. 'browser' => $browser,
  157. 'run' => 'TestingSuite',
  158. 'project' => 'TestProject',
  159. 'case_per_ok' => 1,
  160. 'merge' => 1
  161. });
  162. };
  163. is($res,undef,"TR Parser doesn't explode on instantiation");
  164. isa_ok($tap,"Test::Rail::Parser");
  165. if (!$res) {
  166. $tap->run();
  167. is($tap->{'errors'},0,"No errors encountered uploading case results");
  168. }
  169. #skip/todo in case_per_ok
  170. undef $tap;
  171. $res = exception {
  172. $tap = Test::Rail::Parser->new({
  173. 'source' => 't/skip.test',
  174. 'apiurl' => $apiurl,
  175. 'user' => $login,
  176. 'pass' => $pw,
  177. 'debug' => $debug,
  178. 'browser' => $browser,
  179. 'run' => 'TestingSuite',
  180. 'project' => 'TestProject',
  181. 'case_per_ok' => 1,
  182. 'merge' => 1
  183. });
  184. };
  185. is($res,undef,"TR Parser doesn't explode on instantiation");
  186. isa_ok($tap,"Test::Rail::Parser");
  187. if (!$res) {
  188. $tap->run();
  189. is($tap->{'errors'},0,"No errors encountered uploading case results");
  190. }
  191. #Default mode skip (skip_all)
  192. undef $tap;
  193. $res = exception {
  194. $tap = Test::Rail::Parser->new({
  195. 'source' => 't/skipall.test',
  196. 'apiurl' => $apiurl,
  197. 'user' => $login,
  198. 'pass' => $pw,
  199. 'debug' => $debug,
  200. 'browser' => $browser,
  201. 'run' => 'TestingSuite',
  202. 'project' => 'TestProject',
  203. 'merge' => 1
  204. });
  205. };
  206. is($res,undef,"TR Parser doesn't explode on instantiation");
  207. isa_ok($tap,"Test::Rail::Parser");
  208. if (!$res) {
  209. $tap->run();
  210. is($tap->{'errors'},0,"No errors encountered uploading case results");
  211. is($tap->{'global_status'},6, "Test global result is SKIP on skip all");
  212. }
  213. #Ok, let's test the plan, config, and spawn bits.
  214. undef $tap;
  215. $res = exception {
  216. $tap = Test::Rail::Parser->new({
  217. 'source' => 't/skipall.test',
  218. 'apiurl' => $apiurl,
  219. 'user' => $login,
  220. 'pass' => $pw,
  221. 'debug' => $debug,
  222. 'browser' => $browser,
  223. 'run' => 'hoo hoo I do not exist',
  224. 'plan' => 'mah dubz plan',
  225. 'configs' => ['testPlatform1'],
  226. 'project' => 'TestProject',
  227. 'merge' => 1
  228. });
  229. };
  230. isnt($res,undef,"TR Parser explodes on instantiation when asking for run not in plan");
  231. undef $tap;
  232. $res = exception {
  233. $tap = Test::Rail::Parser->new({
  234. 'source' => 't/skipall.test',
  235. 'apiurl' => $apiurl,
  236. 'user' => $login,
  237. 'pass' => $pw,
  238. 'debug' => $debug,
  239. 'browser' => $browser,
  240. 'run' => 'TestingSuite',
  241. 'plan' => 'mah dubz plan',
  242. 'configs' => ['testConfig'],
  243. 'project' => 'TestProject',
  244. 'merge' => 1
  245. });
  246. };
  247. is($res,undef,"TR Parser doesn't explode on instantiation looking for existing run in plan");
  248. isa_ok($tap,"Test::Rail::Parser");
  249. if (!$res) {
  250. $tap->run();
  251. is($tap->{'errors'},0,"No errors encountered uploading case results");
  252. }
  253. #Now, test spawning.
  254. undef $tap;
  255. $res = exception {
  256. $tap = Test::Rail::Parser->new({
  257. 'source' => 't/skipall.test',
  258. 'apiurl' => $apiurl,
  259. 'user' => $login,
  260. 'pass' => $pw,
  261. 'debug' => $debug,
  262. 'browser' => $browser,
  263. 'run' => 'TestingSuite2',
  264. 'plan' => 'mah dubz plan',
  265. 'configs' => ['testPlatform1'],
  266. 'project' => 'TestProject',
  267. 'spawn' => 9,
  268. 'merge' => 1
  269. });
  270. };
  271. is($res,undef,"TR Parser doesn't explode on instantiation when spawning run in plan");
  272. isa_ok($tap,"Test::Rail::Parser");
  273. if (!$res) {
  274. $tap->run();
  275. is($tap->{'errors'},0,"No errors encountered uploading case results");
  276. }
  277. #Test spawning of builds not in plans.
  278. #Now, test spawning.
  279. undef $tap;
  280. $res = exception {
  281. $tap = Test::Rail::Parser->new({
  282. 'source' => 't/skipall.test',
  283. 'apiurl' => $apiurl,
  284. 'user' => $login,
  285. 'pass' => $pw,
  286. 'debug' => $debug,
  287. 'browser' => $browser,
  288. 'run' => 'TestingSuite2',
  289. 'project' => 'TestProject',
  290. 'spawn' => 9,
  291. 'merge' => 1
  292. });
  293. };
  294. is($res,undef,"TR Parser doesn't explode on instantiation when spawning run in plan");
  295. isa_ok($tap,"Test::Rail::Parser");
  296. if (!$res) {
  297. $tap->run();
  298. is($tap->{'errors'},0,"No errors encountered uploading case results");
  299. }
  300. #Test spawning of plans and runs.
  301. undef $tap;
  302. $res = exception {
  303. $tap = Test::Rail::Parser->new({
  304. 'source' => 't/skipall.test',
  305. 'apiurl' => $apiurl,
  306. 'user' => $login,
  307. 'pass' => $pw,
  308. 'debug' => $debug,
  309. 'browser' => $browser,
  310. 'run' => 'BogoRun',
  311. 'plan' => 'BogoPlan',
  312. 'project' => 'TestProject',
  313. 'spawn' => 9,
  314. 'merge' => 1
  315. });
  316. };
  317. is($res,undef,"TR Parser doesn't explode on instantiation when spawning run in plan");
  318. isa_ok($tap,"Test::Rail::Parser");
  319. if (!$res) {
  320. $tap->run();
  321. is($tap->{'errors'},0,"No errors encountered uploading case results");
  322. }
  323. #Verify that case_per_ok and step_results are mutually exclusive, and die.
  324. undef $tap;
  325. $res = exception {
  326. $tap = Test::Rail::Parser->new({
  327. 'source' => 't/skipall.test',
  328. 'apiurl' => $apiurl,
  329. 'user' => $login,
  330. 'pass' => $pw,
  331. 'debug' => $debug,
  332. 'browser' => $browser,
  333. 'run' => 'BogoRun',
  334. 'plan' => 'BogoPlan',
  335. 'project' => 'TestProject',
  336. 'spawn' => 9,
  337. 'merge' => 1,
  338. 'case_per_ok' => 1,
  339. 'step_results' => 'sr_step_results'
  340. });
  341. };
  342. isnt($res,undef,"TR Parser explodes on instantiation when mutually exclusive options are passed");
  343. #Check that per-section spawn works
  344. undef $tap;
  345. $res = exception {
  346. $tap = Test::Rail::Parser->new({
  347. 'source' => 't/fake.test',
  348. 'apiurl' => $apiurl,
  349. 'user' => $login,
  350. 'pass' => $pw,
  351. 'debug' => $debug,
  352. 'browser' => $browser,
  353. 'run' => 'BogoRun',
  354. 'project' => 'TestProject',
  355. 'merge' => 1,
  356. 'spawn' => 9,
  357. 'sections' => ['fake.test'],
  358. 'case_per_ok' => 1
  359. });
  360. };
  361. is($res,undef,"TR Parser doesn't explode on instantiation");
  362. isa_ok($tap,"Test::Rail::Parser");
  363. if (!$res) {
  364. $tap->run();
  365. is($tap->{'errors'},0,"No errors encountered uploading case results");
  366. }
  367. #Check that per-section spawn works
  368. undef $tap;
  369. $res = exception {
  370. $tap = Test::Rail::Parser->new({
  371. 'source' => 't/fake.test',
  372. 'apiurl' => $apiurl,
  373. 'user' => $login,
  374. 'pass' => $pw,
  375. 'debug' => $debug,
  376. 'browser' => $browser,
  377. 'run' => 'BogoRun',
  378. 'plan' => 'BogoPlan',
  379. 'project' => 'TestProject',
  380. 'merge' => 1,
  381. 'spawn' => 9,
  382. 'sections' => ['fake.test'],
  383. 'case_per_ok' => 1
  384. });
  385. };
  386. is($res,undef,"TR Parser doesn't explode on instantiation");
  387. isa_ok($tap,"Test::Rail::Parser");
  388. if (!$res) {
  389. $tap->run();
  390. is($tap->{'errors'},0,"No errors encountered uploading case results");
  391. }
  392. undef $tap;
  393. $res = exception {
  394. $tap = Test::Rail::Parser->new({
  395. 'source' => 't/fake.test',
  396. 'apiurl' => $apiurl,
  397. 'user' => $login,
  398. 'pass' => $pw,
  399. 'debug' => $debug,
  400. 'browser' => $browser,
  401. 'run' => 'BogoRun',
  402. 'project' => 'TestProject',
  403. 'merge' => 1,
  404. 'spawn' => 9,
  405. 'sections' => ['potzrebie'],
  406. 'case_per_ok' => 1
  407. });
  408. };
  409. isnt($res,undef,"TR Parser explodes on instantiation with invalid section");
  410. undef $tap;
  411. $res = exception {
  412. $tap = Test::Rail::Parser->new({
  413. 'source' => 't/notests.test',
  414. 'apiurl' => $apiurl,
  415. 'user' => $login,
  416. 'pass' => $pw,
  417. 'debug' => $debug,
  418. 'browser' => $browser,
  419. 'run' => 'BogoRun',
  420. 'project' => 'TestProject',
  421. 'merge' => 1,
  422. 'spawn' => 9,
  423. });
  424. };
  425. is($res,undef,"TR Parser doesn't explode on instantiation");
  426. isa_ok($tap,"Test::Rail::Parser");
  427. if (!$res) {
  428. $tap->run();
  429. is($tap->{'errors'},0,"No errors encountered uploading case results");
  430. is($tap->{'global_status'},4, "Test global result is RETEST on env fail");
  431. }
  432. undef $tap;
  433. $res = exception {
  434. $tap = Test::Rail::Parser->new({
  435. 'source' => 't/pass.test',
  436. 'apiurl' => $apiurl,
  437. 'user' => $login,
  438. 'pass' => $pw,
  439. 'debug' => $debug,
  440. 'browser' => $browser,
  441. 'run' => 'BogoRun',
  442. 'project' => 'TestProject',
  443. 'merge' => 1,
  444. 'spawn' => 9,
  445. });
  446. };
  447. is($res,undef,"TR Parser doesn't explode on instantiation");
  448. isa_ok($tap,"Test::Rail::Parser");
  449. if (!$res) {
  450. $tap->run();
  451. is($tap->{'errors'},0,"No errors encountered uploading case results");
  452. is($tap->{'global_status'},1, "Test global result is PASS on ok test");
  453. }
  454. 0;