TestRail-Utils.t 4.6 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 ($apiurl,$login,$pw) = ('http://testrail.local','teodesian@cpan.org','fake');
  56. my $debug = 1;
  57. my $browser = $Test::LWP::UserAgent::TestRailMock::mockObject;
  58. my $tr = TestRail::API->new($apiurl,$login,$pw,undef,1);
  59. $tr->{'browser'} = $browser;
  60. $tr->{'debug'} = 0;
  61. #Plan mode, no milestone
  62. my $opts = {
  63. 'run' => 'TestingSuite',
  64. 'plan' => 'mah dubz plan',
  65. 'configs' => ['testConfig'],
  66. 'project' => 'TestProject'
  67. };
  68. my ($project, $plan, $run, $milestone) = TestRail::Utils::getRunInformation($tr,$opts);
  69. is($project->{'id'}, 10, "getRunInformation gets project correctly");
  70. is($plan->{'id'}, 24, "getRunInformation gets plan correctly");
  71. is($run->{'id'}, 1, "getRunInformation gets run correctly");
  72. is($milestone, undef, "getRunInformation returns undef when no milestone set for plan");
  73. #Plan mode, no such run
  74. $opts->{'run'} = 'hoo hoo I do not exist';
  75. like(exception { TestRail::Utils::getRunInformation($tr,$opts) }, qr/no such run/i, "Attempt to find nonexistant run in plan is fatal");
  76. #Plan mode, no such plan
  77. $opts->{'plan'} = 'hoo hoo I do not exist';
  78. like(exception { TestRail::Utils::getRunInformation($tr,$opts) }, qr/no such plan/i, "Attempt to find nonexistant plan is fatal");
  79. #No such project
  80. $opts->{'project'} = 'hoo hoo I do not exist';
  81. like(exception { TestRail::Utils::getRunInformation($tr,$opts) }, qr/no such project/i, "Attempt to find nonexistant project is fatal");
  82. #Run mode, no milestone
  83. $opts->{'run'} = 'TestingSuite';
  84. $opts->{'configs'} = undef;
  85. $opts->{'plan'} = undef;
  86. $opts->{'project'} = 'TestProject';
  87. ($project, $plan, $run, $milestone) = TestRail::Utils::getRunInformation($tr,$opts);
  88. is($project->{'id'}, 10, "getRunInformation gets project correctly [run mode]");
  89. is($plan->{'id'}, undef, "getRunInformation gets plan correctly [run mode]");
  90. is($run->{'id'}, 1, "getRunInformation gets run correctly [run mode]");
  91. is($milestone, undef, "getRunInformation returns undef when no milestone set for run");
  92. #Run mode, milestone
  93. $opts->{'run'} = 'OtherOtherSuite';
  94. ($project, $plan, $run, $milestone) = TestRail::Utils::getRunInformation($tr,$opts);
  95. is($milestone->{'id'},8,"Milestone acquired correctly in run mode");
  96. #plan mode, milestone
  97. $opts->{'project'} = "TestProject";
  98. $opts->{'plan'} = 'GosPlan';
  99. $opts->{'run'} = "Executing the great plan";
  100. $opts->{'configs'} = ["testConfig"];
  101. ($project, $plan, $run, $milestone) = TestRail::Utils::getRunInformation($tr,$opts);
  102. is($milestone->{'id'},8,"Milestone acquired correctly in plan mode");
  103. #Regrettably, I have yet to find a way to print to stdin without eval, so userInput will remain untested.