TestRail-Utils.t 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. =head1 POD TEST
  2. Bogus bogus
  3. =cut
  4. use strict;
  5. use warnings;
  6. use FindBin;
  7. use lib "$FindBin::Bin/lib";
  8. use Test::More 'tests' => 27;
  9. use Test::Fatal;
  10. use TestRail::API;
  11. use TestRail::Utils;
  12. use Test::LWP::UserAgent::TestRailMock;
  13. use Capture::Tiny qw{capture_merged};
  14. use File::Basename qw{dirname};
  15. my ($apiurl,$user,$password);
  16. #check help output
  17. my ($out,($code)) = capture_merged { TestRail::Utils::help() };
  18. is($code,0,"Help works OK");
  19. like($out,qr/bogus bogus/i,"Displays POD OK");
  20. #check the binary output mode
  21. is(exception {capture_merged { ($apiurl,$password,$user) = TestRail::Utils::parseConfig(dirname(__FILE__),1) }}, undef, "No exceptions thrown by parseConfig in array mode");
  22. is($apiurl,'http://hokum.bogus',"APIURL parse OK");
  23. is($user,'zippy',"USER parse OK");
  24. is($password, 'happy', 'PASSWORD parse OK');
  25. is(exception {capture_merged { $out = TestRail::Utils::parseConfig(dirname(__FILE__))}}, undef, "No exceptions thrown by parseConfig default mode");
  26. is($out->{apiurl},'http://hokum.bogus',"APIURL parse OK");
  27. is($out->{user},'zippy',"USER parse OK");
  28. is($out->{password}, 'happy', 'PASSWORD parse OK');
  29. #Handle both the case where we do in sequence or in paralell and mash together logs
  30. my @files;
  31. my $fcontents = '';
  32. open(my $fh,'<','t/test_multiple_files.tap') or die("couldn't open our own test files!!!");
  33. while (<$fh>) {
  34. if (TestRail::Utils::getFilenameFromTapLine($_)) {
  35. push(@files,$fcontents) if $fcontents;
  36. $fcontents = '';
  37. }
  38. $fcontents .= $_;
  39. }
  40. close($fh);
  41. push(@files,$fcontents);
  42. is(scalar(@files),2,"Detects # of filenames correctly in TAP");
  43. $fcontents = '';
  44. @files = ();
  45. open($fh,'<','t/seq_multiple_files.tap') or die("couldn't open our own test files!!!");
  46. while (<$fh>) {
  47. if (TestRail::Utils::getFilenameFromTapLine($_)) {
  48. push(@files,$fcontents) if $fcontents;
  49. $fcontents = '';
  50. }
  51. $fcontents .= $_;
  52. }
  53. close($fh);
  54. push(@files,$fcontents);
  55. is(scalar(@files),7,"Detects # of filenames correctly in TAP");
  56. #Test the actual TAP parsing
  57. @files = TestRail::Utils::TAP2TestFiles('t/test_multiple_files.tap');
  58. is(scalar(@files),2,"TAP correctly parsed into right number of bins");
  59. @files = TestRail::Utils::TAP2TestFiles('t/seq_multiple_files.tap');
  60. is(scalar(@files),7,"TAP correctly parsed into right number of bins");
  61. #Test getRunInformation
  62. my $login_opts = {
  63. 'apiurl' => 'http://testrail.local',
  64. 'user' => 'teodesian@cpan.org',
  65. 'password' => 'fake',
  66. 'browser' => $Test::LWP::UserAgent::TestRailMock::mockObject
  67. };
  68. my $tr = TestRail::Utils::getHandle($login_opts);
  69. #Plan mode, no milestone
  70. my $opts = {
  71. 'run' => 'TestingSuite',
  72. 'plan' => 'mah dubz plan',
  73. 'configs' => ['testConfig'],
  74. 'project' => 'TestProject'
  75. };
  76. my ($project, $plan, $run, $milestone) = TestRail::Utils::getRunInformation($tr,$opts);
  77. is($project->{'id'}, 10, "getRunInformation gets project correctly");
  78. is($plan->{'id'}, 24, "getRunInformation gets plan correctly");
  79. is($run->{'id'}, 1, "getRunInformation gets run correctly");
  80. is($milestone, undef, "getRunInformation returns undef when no milestone set for plan");
  81. #Plan mode, no such run
  82. $opts->{'run'} = 'hoo hoo I do not exist';
  83. like(exception { TestRail::Utils::getRunInformation($tr,$opts) }, qr/no such run/i, "Attempt to find nonexistant run in plan is fatal");
  84. #Plan mode, no such plan
  85. $opts->{'plan'} = 'hoo hoo I do not exist';
  86. like(exception { TestRail::Utils::getRunInformation($tr,$opts) }, qr/no such plan/i, "Attempt to find nonexistant plan is fatal");
  87. #No such project
  88. $opts->{'project'} = 'hoo hoo I do not exist';
  89. like(exception { TestRail::Utils::getRunInformation($tr,$opts) }, qr/no such project/i, "Attempt to find nonexistant project is fatal");
  90. #Run mode, no milestone
  91. $opts->{'run'} = 'TestingSuite';
  92. $opts->{'configs'} = undef;
  93. $opts->{'plan'} = undef;
  94. $opts->{'project'} = 'TestProject';
  95. ($project, $plan, $run, $milestone) = TestRail::Utils::getRunInformation($tr,$opts);
  96. is($project->{'id'}, 10, "getRunInformation gets project correctly [run mode]");
  97. is($plan->{'id'}, undef, "getRunInformation gets plan correctly [run mode]");
  98. is($run->{'id'}, 1, "getRunInformation gets run correctly [run mode]");
  99. is($milestone, undef, "getRunInformation returns undef when no milestone set for run");
  100. #Run mode, milestone
  101. $opts->{'run'} = 'OtherOtherSuite';
  102. ($project, $plan, $run, $milestone) = TestRail::Utils::getRunInformation($tr,$opts);
  103. is($milestone->{'id'},8,"Milestone acquired correctly in run mode");
  104. #plan mode, milestone
  105. $opts->{'project'} = "TestProject";
  106. $opts->{'plan'} = 'GosPlan';
  107. $opts->{'run'} = "Executing the great plan";
  108. $opts->{'configs'} = ["testConfig"];
  109. ($project, $plan, $run, $milestone) = TestRail::Utils::getRunInformation($tr,$opts);
  110. is($milestone->{'id'},8,"Milestone acquired correctly in plan mode");
  111. #Regrettably, I have yet to find a way to print to stdin without eval, so userInput will remain untested.