TestRail-Utils-Find.t 6.3 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::lockMockStep0();
  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. $cases = TestRail::Utils::Find::getTests($opts,$tr);
  81. @tests = TestRail::Utils::Find::findTests($opts,@$cases);
  82. is(scalar(grep {$_ eq 'skipall.test'} @tests),0,"Tests in tree are not returned in no-match mode");
  83. 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");
  84. is(scalar(grep {$_ eq $FindBin::Bin.'/faker.test'} @tests),1,"Orphan Tests in tree ARE returned in no-match mode");
  85. is(scalar(@tests),26,"Correct number of non-existant cases shown (no-match, names-only)");
  86. $opts->{'configs'} = ['testPlatform1'];
  87. isnt(exception { TestRail::Utils::Find::getTests($opts,$tr) } , undef,"Correct number of non-existant cases shown (no-match, names-only)");
  88. $opts->{'configs'} = ['testConfig'];
  89. delete $opts->{'names-only'};
  90. @tests = TestRail::Utils::Find::findTests($opts,@$cases);
  91. my @filtered_tests = grep {defined $_} map {$_->{'full_title'}} @tests;
  92. is(scalar(@filtered_tests),0,"Full titles not returned in no-match mode");
  93. is(scalar(@tests),26,"Correct number of nonexistant cases shown in no-match mode");
  94. delete $opts->{'no-recurse'};
  95. $opts->{'names-only'} = 1;
  96. $cases = TestRail::Utils::Find::getTests($opts,$tr);
  97. @tests = TestRail::Utils::Find::findTests($opts,@$cases);
  98. is(scalar(@tests),30,"Correct number of non-existant cases shown (no-match, names-only, recurse)");
  99. #mutual excl
  100. $opts->{'match'} = $FindBin::Bin;
  101. $cases = TestRail::Utils::Find::getTests($opts,$tr);
  102. isnt(exception {TestRail::Utils::Find::findTests($opts,@$cases)},undef,"match and no-match are mutually exclusive");
  103. delete $opts->{'no-match'};
  104. delete $opts->{'plan'};
  105. $opts->{'run'} = 'TestingSuite';
  106. $cases = TestRail::Utils::Find::getTests($opts,$tr);
  107. @tests = TestRail::Utils::Find::findTests($opts,@$cases);
  108. is(scalar(@tests),1,"Correct number of non-existant cases shown (match, plain run)");
  109. is(scalar(grep {$_ eq "$FindBin::Bin/skipall.test"} @tests),1,"Tests in tree are returned in match, plain run mode");
  110. #Now that we've made sure configs are ignored...
  111. $opts->{'plan'} = 'GosPlan';
  112. $opts->{'run'} = 'Executing the great plan';
  113. $opts->{'users'} = ['teodesian'];
  114. $cases = TestRail::Utils::Find::getTests($opts,$tr);
  115. @tests = TestRail::Utils::Find::findTests($opts,@$cases);
  116. is(scalar(@tests),1,"Correct number of cases shown (match, plan run, assignedto pos)");
  117. is(scalar(grep {$_ eq "$FindBin::Bin/skipall.test"} @tests),1,"Tests in tree are returned filtered by assignee");
  118. $opts->{'users'} = ['billy'];
  119. $cases = TestRail::Utils::Find::getTests($opts,$tr);
  120. @tests = TestRail::Utils::Find::findTests($opts,@$cases);
  121. is(scalar(@tests),0,"Correct number of cases shown (match, plan run, assignedto neg)");
  122. delete $opts->{'users'};
  123. $opts->{'statuses'} = ['passed'];
  124. $cases = TestRail::Utils::Find::getTests($opts,$tr);
  125. @tests = TestRail::Utils::Find::findTests($opts,@$cases);
  126. is(scalar(@tests),1,"Correct number of cases shown (match, plan run, passed)");
  127. $opts->{'statuses'} = ['failed'];
  128. delete $opts->{'match'};
  129. $cases = TestRail::Utils::Find::getTests($opts,$tr);
  130. @tests = TestRail::Utils::Find::findTests($opts,@$cases);
  131. is(scalar(@tests),0,"Correct number of cases shown (match, plan run, failed)");