TestRail-Utils-Lock.t 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. use strict;
  2. use warnings;
  3. use FindBin;
  4. use lib "$FindBin::Bin/lib";
  5. use Test::More 'tests' => 11;
  6. use Test::Fatal;
  7. use File::Basename qw{dirname};
  8. use TestRail::Utils;
  9. use TestRail::Utils::Lock;
  10. use Test::LWP::UserAgent::TestRailMock;
  11. use Sys::Hostname qw{hostname};
  12. use File::Basename qw{basename};
  13. my $opts = {
  14. 'project' => 'TestProject',
  15. 'run' => 'lockRun',
  16. 'case-types' => ['Automated'],
  17. 'lockname' => 'locked',
  18. 'match' => 't',
  19. 'no-recurse' => 1,
  20. 'hostname' => hostname(),
  21. 'mock' => 1
  22. };
  23. my ($apiurl,$login,$pw) = ('http://hokum.bogus','bogus','bogus');
  24. my $tr = new TestRail::API($apiurl,$login,$pw,undef,1);
  25. $tr->{'debug'} = 0;
  26. $tr->{'browser'} = Test::LWP::UserAgent::TestRailMock::lockMockStep0();
  27. my $ret = TestRail::Utils::Lock::pickAndLockTest($opts,$tr);
  28. is($ret,0,"Verify that no tests are locked in match mode, as they all are in a subdir, and recurse is off");
  29. delete $opts->{'no-recurse'};
  30. $ret = TestRail::Utils::Lock::pickAndLockTest($opts,$tr);
  31. is(basename( $ret->{'path'} ), 'lockmealso.test' , "Verify the highest priority test is chosen first");
  32. $tr->{'browser'} = Test::LWP::UserAgent::TestRailMock::lockMockStep1();
  33. $ret = TestRail::Utils::Lock::pickAndLockTest($opts,$tr);
  34. is(basename( $ret->{'path'} ), 'lockme.test' , "Verify the highest priority test of type automated is chosen");
  35. $tr->{'browser'} = Test::LWP::UserAgent::TestRailMock::lockMockStep2();
  36. $ret = TestRail::Utils::Lock::pickAndLockTest($opts,$tr);
  37. is(basename( $ret->{'path'} ), 'lockmetoo.test' , "Verify that the highest priority test that exists in the tree is chosen");
  38. $tr->{'browser'} = Test::LWP::UserAgent::TestRailMock::lockMockStep3();
  39. $ret = TestRail::Utils::Lock::pickAndLockTest($opts,$tr);
  40. is($ret,0,"Verify that no tests are locked, as they either are of the wrong type or do not exist in the match tree");
  41. $tr->{'browser'} = Test::LWP::UserAgent::TestRailMock::lockMockStep4();
  42. #Simulate lock collision
  43. my ($lockStatusID) = $tr->statusNamesToIds('locked');
  44. my ($project,$plan,$run) = TestRail::Utils::getRunInformation($tr,$opts);
  45. is(TestRail::Utils::Lock::lockTest($tr->getTestByName($run->{'id'},'lockme.test'),$lockStatusID,'race.bannon',$tr),0,"False returned when race condition is simulated");
  46. $tr->{'browser'} = Test::LWP::UserAgent::TestRailMock::lockMockStep5();
  47. #Test with a second set of options, verify that no-match and type filtering works
  48. delete $opts->{'match'};
  49. $opts->{'case-types'} = ['Other'];
  50. $ret = TestRail::Utils::Lock::pickAndLockTest($opts,$tr);
  51. is($ret->{'path'},'sortalockme.test',"Test which is here but the other type is locked when ommitting match");
  52. $tr->{'browser'} = Test::LWP::UserAgent::TestRailMock::lockMockStep6();
  53. $ret = TestRail::Utils::Lock::pickAndLockTest($opts,$tr);
  54. is($ret->{'path'},'dontlockme_alsonothere.test',"Test which is not here but the other type is locked when omitting match");
  55. $tr->{'browser'} = Test::LWP::UserAgent::TestRailMock::lockMockStep7();
  56. $ret = TestRail::Utils::Lock::pickAndLockTest($opts,$tr);
  57. is($ret,0,"No tests are locked, as they are not the right type");
  58. #Make sure we only grab retest/untested
  59. delete $opts->{'case-types'};
  60. $ret = TestRail::Utils::Lock::pickAndLockTest($opts,$tr);
  61. is($ret->{'path'},'dontlockme_nothere.test',"Wrong type test which is not here gets locked after we remove all restrictions");
  62. $tr->{'browser'} = Test::LWP::UserAgent::TestRailMock::lockMockStep8();
  63. $ret = TestRail::Utils::Lock::pickAndLockTest($opts,$tr);
  64. is($ret,0,"No tests are locked, as none are untested or retest");