TestRail-Utils.t 4.5 KB

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