TestRail-Utils.t 4.8 KB

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