TestRail-Utils-Lock.t 3.3 KB

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