TestRail-Utils-Lock.t 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #Mock if necesary
  26. $tr->{'debug'} = 0;
  27. $tr->{'browser'} = Test::LWP::UserAgent::TestRailMock::lockMockStep0();
  28. my $ret = TestRail::Utils::Lock::pickAndLockTest($opts,$tr);
  29. is($ret,0,"Verify that no tests are locked in match mode, as they all are in a subdir, and recurse is off");
  30. delete $opts->{'no-recurse'};
  31. $ret = TestRail::Utils::Lock::pickAndLockTest($opts,$tr);
  32. is(basename( $ret->{'path'} ), 'lockmealso.test' , "Verify the highest priority test is chosen first");
  33. $tr->{'browser'} = Test::LWP::UserAgent::TestRailMock::lockMockStep1();
  34. $ret = TestRail::Utils::Lock::pickAndLockTest($opts,$tr);
  35. is(basename( $ret->{'path'} ), 'lockme.test' , "Verify the highest priority test of type automated is chosen");
  36. $tr->{'browser'} = Test::LWP::UserAgent::TestRailMock::lockMockStep2();
  37. $ret = TestRail::Utils::Lock::pickAndLockTest($opts,$tr);
  38. is(basename( $ret->{'path'} ), 'lockmetoo.test' , "Verify that the highest priority test that exists in the tree is chosen");
  39. $tr->{'browser'} = Test::LWP::UserAgent::TestRailMock::lockMockStep3();
  40. $ret = TestRail::Utils::Lock::pickAndLockTest($opts,$tr);
  41. 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");
  42. $tr->{'browser'} = Test::LWP::UserAgent::TestRailMock::lockMockStep4();
  43. #Simulate lock collision
  44. my ($lockStatusID) = $tr->statusNamesToIds('locked');
  45. my ($project,$plan,$run) = TestRail::Utils::getRunInformation($tr,$opts);
  46. is(TestRail::Utils::Lock::lockTest($tr->getTestByName($run->{'id'},'lockme.test'),$lockStatusID,'race.bannon',$tr),0,"False returned when race condition is simulated");
  47. $tr->{'browser'} = Test::LWP::UserAgent::TestRailMock::lockMockStep5();
  48. #Test with a second set of options, verify that no-match and type filtering works
  49. delete $opts->{'match'};
  50. $opts->{'case-types'} = ['Other'];
  51. $ret = TestRail::Utils::Lock::pickAndLockTest($opts,$tr);
  52. is($ret->{'path'},'sortalockme.test',"Test which is here but the other type is locked when ommitting match");
  53. $tr->{'browser'} = Test::LWP::UserAgent::TestRailMock::lockMockStep6();
  54. $ret = TestRail::Utils::Lock::pickAndLockTest($opts,$tr);
  55. is($ret->{'path'},'dontlockme_alsonothere.test',"Test which is not here but the other type is locked when omitting match");
  56. $tr->{'browser'} = Test::LWP::UserAgent::TestRailMock::lockMockStep7();
  57. $ret = TestRail::Utils::Lock::pickAndLockTest($opts,$tr);
  58. is($ret,0,"No tests are locked, as they are not the right type");
  59. #Make sure we only grab retest/untested
  60. delete $opts->{'case-types'};
  61. $ret = TestRail::Utils::Lock::pickAndLockTest($opts,$tr);
  62. is($ret->{'path'},'dontlockme_nothere.test',"Wrong type test which is not here gets locked after we remove all restrictions");
  63. $tr->{'browser'} = Test::LWP::UserAgent::TestRailMock::lockMockStep8();
  64. $ret = TestRail::Utils::Lock::pickAndLockTest($opts,$tr);
  65. is($ret,0,"No tests are locked, as none are untested or retest");