TestRail-Utils.t 4.6 KB

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