testrail-lock 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #!/usr/bin/env perl
  2. # ABSTRACT: Lock a test in a TestRail, and return the test name if successful.
  3. # PODNAME: testrail-lock
  4. =head1 SYNOPSIS
  5. # Lock a group of tests and execute them
  6. testrail-tests [OPTIONS] | xargs testrail-lock [OPTIONS] | xargs prove -PTestrail=...
  7. =head1 DESCRIPTION
  8. testrail-lock - pick an untested/retest test in TestRail, lock it, and return the test name if successful.
  9. It is useful to lock the test in situations where you have multiple disconnected test running processes trying to allocate resources toward testing outstanding cases so that effort is not duplicated.
  10. This is accomplished via setting a special locking result on a test rather than simple assignment, as detecting lock conflicts is impossible then due to a lack of assignment history.
  11. Results, however have a history of results set, so we use that fact to detect if a locking collision occured (race condition) and fail to return a result when another process locked during our attempt to lock.
  12. Will respect test priority when making the choice of what test to lock.
  13. This obviously does not make sense with case_per_ok test upload; support for locking entire sections when in case_per_ok upload mode is not supported at this time.
  14. =head1 PARAMETERS:
  15. =head2 MANDATORY PARAMETERS
  16. =over 4
  17. --apiurl : full URL to get to TestRail index document
  18. --password : Your TestRail Password, or a valid API key (TestRail 4.2 and above).
  19. --user : Your TestRail User Name.
  20. -j --project : desired project name.
  21. -r --run : desired run name.
  22. -l --lockname : internal name of lock status.
  23. =back
  24. All mandatory options not passed with the above switches, or in your ~/.testrailrc will be prompted for.
  25. =head2 SEMI-OPTIONAL PARAMETERS
  26. =over 4
  27. -p --plan : desired plan name. Required if the run passed is a child of a plan.
  28. -e --encoding : Character encoding of arguments. Defaults to UTF-8. See L<Encode::Supported> for supported encodings.
  29. =back
  30. =head2 OPTIONAL PARAMETERS
  31. =over 4
  32. -c --config : configuration name to filter plans in run. Can be passed multiple times.
  33. =back
  34. =head1 CONFIGURATION FILE
  35. In your $HOME, (or the current directory, if your system has no concept of a home directory) put a file called .testrailrc with key=value syntax separated by newlines.
  36. Valid Keys are the same as documented by L<App::Prove::Plugin::TestRail>.
  37. All options specified thereby are overridden by passing the command-line switches above.
  38. =head1 MISCELLANEOUS OPTIONS:
  39. =over 4
  40. --mock : don't do any real HTTP requests. Used only by tests.
  41. --help : show this output
  42. =back
  43. =cut
  44. use strict;
  45. use warnings;
  46. use utf8;
  47. use TestRail::Utils;
  48. use Getopt::Long;
  49. use File::HomeDir qw{my_home};
  50. use Sys::Hostname qw{hostname};
  51. my $opts = {};
  52. #Parse config file if we are missing api url/key or user
  53. my $homedir = my_home() || '.';
  54. if (-e $homedir . '/.testrailrc') {
  55. $opts = TestRail::Utils::parseConfig($homedir);
  56. }
  57. GetOptions(
  58. 'apiurl=s' => \$opts->{'apiurl'},
  59. 'password=s' => \$opts->{'password'},
  60. 'user=s' => \$opts->{'user'},
  61. 'l|lockname=s' => \$opts->{'lockname'},
  62. 'j|project=s' => \$opts->{'project'},
  63. 'p|plan=s' => \$opts->{'plan'},
  64. 'r|run=s' => \$opts->{'run'},
  65. 'c|config=s@' => \$opts->{'configs'},
  66. 'mock' => \$opts->{'mock'},
  67. 'e|encoding=s' => \$opts->{'encoding'},
  68. 'h|help' => \$opts->{'help'}
  69. );
  70. if ($opts->{help}) { help(); }
  71. $opts->{'hostname'} = hostname;
  72. TestRail::Utils::interrogateUser($opts,qw{apiurl user password project run lockname});
  73. print TestRail::Utils::pickAndLockTest($opts)."\n";
  74. exit 0;
  75. __END__
  76. L<TestRail::API>
  77. L<File::HomeDir> for the finding of .testrailrc
  78. =head1 SPECIAL THANKS
  79. Thanks to cPanel Inc, for graciously funding the creation of this distribution.