TestRail-Utils-Find.t 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. use strict;
  2. use warnings;
  3. use FindBin;
  4. use lib "$FindBin::Bin/lib";
  5. use Test::More 'tests' => 28;
  6. use Test::Fatal;
  7. use Test::Deep;
  8. use File::Basename qw{dirname};
  9. use TestRail::Utils;
  10. use TestRail::Utils::Lock;
  11. use Test::LWP::UserAgent::TestRailMock;
  12. use File::Basename qw{basename};
  13. #FindRuns tests
  14. my $opts = {
  15. 'project' => 'TestProject'
  16. };
  17. my ($apiurl,$login,$pw) = ('http://testrail.local','bogus','bogus');
  18. my $tr = new TestRail::API($apiurl,$login,$pw,undef,1);
  19. #Mock if necesary
  20. $tr->{'debug'} = 0;
  21. $tr->{'browser'} = $Test::LWP::UserAgent::TestRailMock::mockObject;
  22. my $runs = TestRail::Utils::Find::findRuns($opts,$tr);
  23. is(ref $runs, 'ARRAY', "FindRuns returns ARRAYREF");
  24. is(scalar(@$runs),4,"All runs for project found when no other options are passed");
  25. @$runs = map {$_->{'name'}} @$runs;
  26. my @expected = qw{OtherOtherSuite TestingSuite FinalRun lockRun};
  27. cmp_deeply($runs,\@expected,"Tests ordered FIFO by creation date correctly");
  28. $opts->{'lifo'} = 1;
  29. $runs = TestRail::Utils::Find::findRuns($opts,$tr);
  30. @$runs = map {$_->{'name'}} @$runs;
  31. @expected = qw{lockRun TestingSuite FinalRun OtherOtherSuite};
  32. cmp_deeply($runs,\@expected,"Tests ordered LIFO by creation date correctly");
  33. $opts->{'milesort'} = 1;
  34. $runs = TestRail::Utils::Find::findRuns($opts,$tr);
  35. @$runs = map {$_->{'name'}} @$runs;
  36. @expected = qw{OtherOtherSuite TestingSuite FinalRun lockRun};
  37. cmp_deeply($runs,\@expected,"Tests ordered LIFO by milestone date correctly");
  38. delete $opts->{'lifo'};
  39. $runs = TestRail::Utils::Find::findRuns($opts,$tr);
  40. @$runs = map {$_->{'name'}} @$runs;
  41. @expected = qw{TestingSuite FinalRun lockRun OtherOtherSuite};
  42. cmp_deeply($runs,\@expected,"Tests ordered LIFO by milestone date correctly");
  43. delete $opts->{'milesort'};
  44. $opts->{'configs'} = ['eee', 'testConfig'];
  45. $runs = TestRail::Utils::Find::findRuns($opts,$tr);
  46. @$runs = map {$_->{'name'}} @$runs;
  47. is(scalar(@$runs),0,"Filtering runs by configurations works");
  48. $opts->{'configs'} = ['testConfig'];
  49. $runs = TestRail::Utils::Find::findRuns($opts,$tr);
  50. @$runs = map {$_->{'name'}} @$runs;
  51. is(scalar(@$runs),3,"Filtering runs by configurations works");
  52. delete $opts->{'configs'};
  53. $opts->{'statuses'} = ['passed'];
  54. $runs = TestRail::Utils::Find::findRuns($opts,$tr);
  55. is(scalar(@$runs),0,"No passing runs can be found in projects without them");
  56. $opts->{'statuses'} = ['retest'];
  57. $runs = TestRail::Utils::Find::findRuns($opts,$tr);
  58. is(scalar(@$runs),1,"Failed runs can be found in projects with them");
  59. #Test testrail-tests
  60. $opts = {
  61. 'project' => 'TestProject',
  62. 'plan' => 'GosPlan',
  63. 'run' => 'Executing the great plan',
  64. 'match' => $FindBin::Bin,
  65. 'configs' => ['testConfig'],
  66. 'no-recurse' => 1,
  67. 'names-only' => 1
  68. };
  69. my ($cases) = TestRail::Utils::Find::getTests($opts,$tr);
  70. my @tests = TestRail::Utils::Find::findTests($opts,@$cases);
  71. @expected = ("$FindBin::Bin/skipall.test");
  72. cmp_deeply(\@tests,\@expected,"findTests: match, no-recurse, plan mode, names-only");
  73. delete $opts->{'names-only'};
  74. @tests = TestRail::Utils::Find::findTests($opts,@$cases);
  75. @tests = map {$_->{'full_title'}} @tests;
  76. cmp_deeply(\@tests,\@expected,"findTests: match, no-recurse, plan mode");
  77. delete $opts->{'match'};
  78. $opts->{'no-match'} = $FindBin::Bin;
  79. $opts->{'names-only'} = 1;
  80. $opts->{'extension'} = '.test';
  81. ($cases) = TestRail::Utils::Find::getTests($opts,$tr);
  82. @tests = TestRail::Utils::Find::findTests($opts,@$cases);
  83. is(scalar(grep {$_ eq 'skipall.test'} @tests),0,"Tests in tree are not returned in no-match mode");
  84. is(scalar(grep {$_ eq 'NOT SO SEARED AFTER ALL'} @tests),0,"Tests not in tree that do exist are not returned in no-match mode");
  85. is(scalar(grep {$_ eq $FindBin::Bin.'/faker.test'} @tests),1,"Orphan Tests in tree ARE returned in no-match mode");
  86. is(scalar(@tests),6,"Correct number of non-existant cases shown (no-match, names-only)");
  87. $opts->{'configs'} = ['testPlatform1'];
  88. isnt(exception { TestRail::Utils::Find::getTests($opts,$tr) } , undef,"Correct number of non-existant cases shown (no-match, names-only)");
  89. $opts->{'configs'} = ['testConfig'];
  90. delete $opts->{'names-only'};
  91. @tests = TestRail::Utils::Find::findTests($opts,@$cases);
  92. my @filtered_tests = grep {defined $_} map {$_->{'full_title'}} @tests;
  93. is(scalar(@filtered_tests),0,"Full titles not returned in no-match mode");
  94. is(scalar(@tests),6,"Correct number of nonexistant cases shown in no-match mode");
  95. delete $opts->{'no-recurse'};
  96. $opts->{'names-only'} = 1;
  97. ($cases) = TestRail::Utils::Find::getTests($opts,$tr);
  98. @tests = TestRail::Utils::Find::findTests($opts,@$cases);
  99. is(scalar(@tests),10,"Correct number of non-existant cases shown (no-match, names-only, recurse)");
  100. #mutual excl
  101. $opts->{'match'} = $FindBin::Bin;
  102. ($cases) = TestRail::Utils::Find::getTests($opts,$tr);
  103. isnt(exception {TestRail::Utils::Find::findTests($opts,@$cases)},undef,"match and no-match are mutually exclusive");
  104. delete $opts->{'no-match'};
  105. delete $opts->{'plan'};
  106. $opts->{'run'} = 'TestingSuite';
  107. ($cases) = TestRail::Utils::Find::getTests($opts,$tr);
  108. @tests = TestRail::Utils::Find::findTests($opts,@$cases);
  109. is(scalar(@tests),1,"Correct number of non-existant cases shown (match, plain run)");
  110. is(scalar(grep {$_ eq "$FindBin::Bin/skipall.test"} @tests),1,"Tests in tree are returned in match, plain run mode");
  111. #Now that we've made sure configs are ignored...
  112. $opts->{'plan'} = 'GosPlan';
  113. $opts->{'run'} = 'Executing the great plan';
  114. $opts->{'users'} = ['teodesian'];
  115. ($cases) = TestRail::Utils::Find::getTests($opts,$tr);
  116. @tests = TestRail::Utils::Find::findTests($opts,@$cases);
  117. is(scalar(@tests),1,"Correct number of cases shown (match, plan run, assignedto pos)");
  118. is(scalar(grep {$_ eq "$FindBin::Bin/skipall.test"} @tests),1,"Tests in tree are returned filtered by assignee");
  119. $opts->{'users'} = ['billy'];
  120. ($cases) = TestRail::Utils::Find::getTests($opts,$tr);
  121. @tests = TestRail::Utils::Find::findTests($opts,@$cases);
  122. is(scalar(@tests),0,"Correct number of cases shown (match, plan run, assignedto neg)");
  123. delete $opts->{'users'};
  124. $opts->{'statuses'} = ['passed'];
  125. ($cases) = TestRail::Utils::Find::getTests($opts,$tr);
  126. @tests = TestRail::Utils::Find::findTests($opts,@$cases);
  127. is(scalar(@tests),1,"Correct number of cases shown (match, plan run, passed)");
  128. $opts->{'statuses'} = ['failed'];
  129. delete $opts->{'match'};
  130. ($cases) = TestRail::Utils::Find::getTests($opts,$tr);
  131. @tests = TestRail::Utils::Find::findTests($opts,@$cases);
  132. is(scalar(@tests),0,"Correct number of cases shown (match, plan run, failed)");