TestRail-Utils.t 4.3 KB

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