| 1 | #!/usr/bin/perl | ||||||||||||
| 2 | # ABSTRACT: Lock a test in a TestRail, and return the test name if successful. | ||||||||||||
| 3 | # PODNAME: TestRail::Bin::Lock | ||||||||||||
| 4 | |||||||||||||
| 5 | package TestRail::Bin::Lock; | ||||||||||||
| 6 | 1 | $TestRail::Bin::Lock::VERSION = '0.052'; | |||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 2 | ▶ | use utf8; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 2 | ▶ | use TestRail::Utils; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 2 | ▶ | use TestRail::Utils::Lock; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | 2 | ▶ | use Getopt::Long qw{GetOptionsFromArray}; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 2 | ▶ | use File::HomeDir qw{my_home}; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 2 | ▶ | use Sys::Hostname qw{hostname}; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | |||||||||||||
| 18 | 1 | ▶ | if ( !caller() ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 19 | 1 | my ( $out, $code ) = run( 'args' => \@ARGV ); | |||||||||||
| 20 | 1 | print $out; | |||||||||||
| 21 | 1 | exit $code; | |||||||||||
| 22 | } | ||||||||||||
| 23 | |||||||||||||
| 24 | 3 | ▶ | sub run { | ||||||||||
|
Subroutine
run: called CC=5 SCAR=16.6
| |||||||||||||
| 25 | 3 | my %params = @_; | |||||||||||
| 26 | 3 | my $opts = {}; | |||||||||||
| 27 | |||||||||||||
| 28 | #Parse config file if we are missing api url/key or user | ||||||||||||
| 29 | 3 | ▶ | my $homedir = my_home() || '.'; | ||||||||||
|
Condition50%1/2
my_home() || '.'
MC/DC0%0/1
my_home() || '.'
my_home()
Truth table50%1/2
A
A= my_home()
| |||||||||||||
| 30 | 3 | ▶ | if ( -e $homedir . '/.testrailrc' ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 31 | 0 | $opts = TestRail::Utils::parseConfig($homedir); | |||||||||||
| 32 | } | ||||||||||||
| 33 | |||||||||||||
| 34 | GetOptionsFromArray( | ||||||||||||
| 35 | $params{'args'}, | ||||||||||||
| 36 | 'apiurl=s' => \$opts->{'apiurl'}, | ||||||||||||
| 37 | 'password=s' => \$opts->{'password'}, | ||||||||||||
| 38 | 'user=s' => \$opts->{'user'}, | ||||||||||||
| 39 | 'l|lockname=s' => \$opts->{'lockname'}, | ||||||||||||
| 40 | 'j|project=s' => \$opts->{'project'}, | ||||||||||||
| 41 | 'p|plan=s' => \$opts->{'plan'}, | ||||||||||||
| 42 | 'r|run=s' => \$opts->{'run'}, | ||||||||||||
| 43 | 'c|config=s@' => \$opts->{'configs'}, | ||||||||||||
| 44 | 'm|match=s' => \$opts->{'match'}, | ||||||||||||
| 45 | 'no-match=s' => \$opts->{'no-match'}, | ||||||||||||
| 46 | 'n|no-recurse' => \$opts->{'no-recurse'}, | ||||||||||||
| 47 | 't|case-type=s@' => \$opts->{'case-types'}, | ||||||||||||
| 48 | 'e|encoding=s' => \$opts->{'encoding'}, | ||||||||||||
| 49 | 3 | 'h|help' => \$opts->{'help'}, | |||||||||||
| 50 | ); | ||||||||||||
| 51 | |||||||||||||
| 52 | 3 | ▶ | if ( $opts->{help} ) { return ( '', TestRail::Utils::help() ); } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 53 | |||||||||||||
| 54 | 1 | $opts->{'browser'} = $params{'browser'}; | |||||||||||
| 55 | 1 | $opts->{'hostname'} = hostname; | |||||||||||
| 56 | |||||||||||||
| 57 | 1 | TestRail::Utils::interrogateUser( $opts, | |||||||||||
| 58 | qw{apiurl user password project run lockname} ); | ||||||||||||
| 59 | |||||||||||||
| 60 | 1 | my $tr = TestRail::Utils::getHandle($opts); | |||||||||||
| 61 | |||||||||||||
| 62 | 1 | my $ret = TestRail::Utils::Lock::pickAndLockTest( $opts, $tr ); | |||||||||||
| 63 | |||||||||||||
| 64 | 1 | ▶ | return ( 'Could not lock case.', 255 ) if !$ret; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 65 | |||||||||||||
| 66 | 0 | return ( $ret->{'path'} . "\n", 0 ); | |||||||||||
| 67 | } | ||||||||||||
| 68 | |||||||||||||
| 69 | 1; | ||||||||||||
| 70 | |||||||||||||
| 71 | =pod | ||||||||||||
| 72 | |||||||||||||
| 73 | =encoding UTF-8 | ||||||||||||
| 74 | |||||||||||||
| 75 | =head1 NAME | ||||||||||||
| 76 | |||||||||||||
| 77 | TestRail::Bin::Lock - Lock a test in a TestRail, and return the test name if successful. | ||||||||||||
| 78 | |||||||||||||
| 79 | =head1 VERSION | ||||||||||||
| 80 | |||||||||||||
| 81 | version 0.052 | ||||||||||||
| 82 | |||||||||||||
| 83 | =head1 SYNOPSIS | ||||||||||||
| 84 | |||||||||||||
| 85 | # Lock a group of tests and execute them | ||||||||||||
| 86 | testrail-tests [OPTIONS] | xargs testrail-lock [OPTIONS] | xargs prove -PTestrail=... | ||||||||||||
| 87 | |||||||||||||
| 88 | require `which testrail-lock`; | ||||||||||||
| 89 | TestRail::Bin::Lock::run('args' => \@args); | ||||||||||||
| 90 | |||||||||||||
| 91 | =head1 DESCRIPTION | ||||||||||||
| 92 | |||||||||||||
| 93 | testrail-lock - pick an untested/retest test in TestRail, lock it, and return the test name if successful. | ||||||||||||
| 94 | |||||||||||||
| 95 | 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. | ||||||||||||
| 96 | 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. | ||||||||||||
| 97 | Results, however have a history of results set, so we use that fact to detect if a locking collision occurred (race condition) and fail to return a result when another process locked during our attempt to lock. | ||||||||||||
| 98 | |||||||||||||
| 99 | Will respect test priority when making the choice of what test to lock. | ||||||||||||
| 100 | |||||||||||||
| 101 | Can also be used as the modulino TestRail::Bin::Lock. | ||||||||||||
| 102 | Has a single 'run' function which accepts a hash with the 'args' parameter being the array of arguments. | ||||||||||||
| 103 | |||||||||||||
| 104 | =head1 PARAMETERS: | ||||||||||||
| 105 | |||||||||||||
| 106 | =head2 MANDATORY PARAMETERS | ||||||||||||
| 107 | |||||||||||||
| 108 | =over 4 | ||||||||||||
| 109 | |||||||||||||
| 110 | --apiurl : full URL to get to TestRail index document | ||||||||||||
| 111 | |||||||||||||
| 112 | --password : Your TestRail Password, or a valid API key (TestRail 4.2 and above). | ||||||||||||
| 113 | |||||||||||||
| 114 | --user : Your TestRail User Name. | ||||||||||||
| 115 | |||||||||||||
| 116 | -j --project : desired project name. | ||||||||||||
| 117 | |||||||||||||
| 118 | -r --run : desired run name. | ||||||||||||
| 119 | |||||||||||||
| 120 | -l --lockname : internal name of lock status. | ||||||||||||
| 121 | |||||||||||||
| 122 | =back | ||||||||||||
| 123 | |||||||||||||
| 124 | All mandatory options not passed with the above switches, or in your ~/.testrailrc will be prompted for. | ||||||||||||
| 125 | |||||||||||||
| 126 | =head2 SEMI-OPTIONAL PARAMETERS | ||||||||||||
| 127 | |||||||||||||
| 128 | =over 4 | ||||||||||||
| 129 | |||||||||||||
| 130 | -p --plan : desired plan name. Required if the run passed is a child of a plan. | ||||||||||||
| 131 | |||||||||||||
| 132 | -m --match : attempt to find filenames matching the test names in the provided directory. | ||||||||||||
| 133 | |||||||||||||
| 134 | --no-match : attempt to find filenames that do not match test names in the provided directory. | ||||||||||||
| 135 | |||||||||||||
| 136 | -n --no-recurse : if match (or no-match) passed, do not recurse subdirectories. | ||||||||||||
| 137 | |||||||||||||
| 138 | -t --case-type : Only attempt to lock cases of the specified type. May be passed multiple times. | ||||||||||||
| 139 | |||||||||||||
| 140 | -e --encoding : Character encoding of arguments. Defaults to UTF-8. See L<Encode::Supported> for supported encodings. | ||||||||||||
| 141 | |||||||||||||
| 142 | =back | ||||||||||||
| 143 | |||||||||||||
| 144 | =head2 OPTIONAL PARAMETERS | ||||||||||||
| 145 | |||||||||||||
| 146 | =over 4 | ||||||||||||
| 147 | |||||||||||||
| 148 | -c --config : configuration name to filter plans in run. Can be passed multiple times. | ||||||||||||
| 149 | |||||||||||||
| 150 | =back | ||||||||||||
| 151 | |||||||||||||
| 152 | =head1 CONFIGURATION FILE | ||||||||||||
| 153 | |||||||||||||
| 154 | 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. | ||||||||||||
| 155 | Valid Keys are the same as documented by L<App::Prove::Plugin::TestRail>. | ||||||||||||
| 156 | All options specified thereby are overridden by passing the command-line switches above. | ||||||||||||
| 157 | |||||||||||||
| 158 | =head1 MISCELLANEOUS OPTIONS: | ||||||||||||
| 159 | |||||||||||||
| 160 | =over 4 | ||||||||||||
| 161 | |||||||||||||
| 162 | --help : show this output | ||||||||||||
| 163 | |||||||||||||
| 164 | =back | ||||||||||||
| 165 | |||||||||||||
| 166 | =head1 SPECIAL THANKS | ||||||||||||
| 167 | |||||||||||||
| 168 | Thanks to cPanel Inc, for graciously funding the creation of this distribution. | ||||||||||||
| 169 | |||||||||||||
| 170 | =head1 AUTHOR | ||||||||||||
| 171 | |||||||||||||
| 172 | George S. Baugh <teodesian@cpan.org> | ||||||||||||
| 173 | |||||||||||||
| 174 | =head1 SOURCE | ||||||||||||
| 175 | |||||||||||||
| 176 | The development version is on github at L<https://github.com/teodesian/TestRail-Perl> | ||||||||||||
| 177 | and may be cloned from L<git://github.com/teodesian/TestRail-Perl.git> | ||||||||||||
| 178 | |||||||||||||
| 179 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 180 | |||||||||||||
| 181 | This software is copyright (c) 2022 by George S. Baugh. | ||||||||||||
| 182 | |||||||||||||
| 183 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 184 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 185 | |||||||||||||
| 186 | =cut | ||||||||||||
| 187 | |||||||||||||
| 188 | __END__ | ||||||||||||