testrail-bulk-mark-results 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #!/usr/bin/perl
  2. # ABSTRACT: Bulk mark entire runs/plans (or groups of tests therein) as the provided status.
  3. # PODNAME: TestRail::Bin::BulkMarkResults
  4. =head1 USAGE
  5. testrail-bulk-mark-results [OPTIONS] status [reason]
  6. require `which testrail-bulk-mark-results`;
  7. TestRail::Bin::BulkMarkResults::run('args' => \@args);
  8. =head1 DESCRIPTION
  9. Sometimes it is useful to mark entire runs of tests when, for example, a prerequisite test in a sequence invalidates all further tests.
  10. For example, if a binary produced for test fails to run at all, more detailed testing will be impossible;
  11. it would save time to just mark everything as blocked.
  12. Can be used as the modulino TestRail::Bin::BulkMarkResults.
  13. Has a single 'run' function which accepts a hash with the 'args' parameter being the array of arguments.
  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. =back
  23. All mandatory options not passed with the above switches, or in your ~/.testrailrc will be prompted for.
  24. =head2 SEMI-OPTIONAL PARAMETERS
  25. =over 4
  26. -p --plan : desired plan name. Required if the run passed is a child of a plan.
  27. -e --encoding : Character encoding of arguments. Defaults to UTF-8. See L<Encode::Supported> for supported encodings.
  28. =back
  29. =head2 OPTIONAL PARAMETERS
  30. =over 4
  31. -c --config : configuration name to filter plans in run. Can be passed multiple times.
  32. -s --status : only mark tests already marked as [status] in testrail. Can be passed multiple times.
  33. -a --assignedto : only mark tests assigned to user. Can be passed multiple times.
  34. =back
  35. =head1 CONFIGURATION FILE
  36. 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.
  37. Valid Keys are the same as documented by L<App::Prove::Plugin::TestRail>.
  38. All options specified thereby are overridden by passing the command-line switches above.
  39. =head1 MISCELLANEOUS OPTIONS:
  40. =over 4
  41. --help : show this output
  42. =back
  43. =cut
  44. package TestRail::Bin::BulkMarkResults;
  45. use strict;
  46. use warnings;
  47. use utf8;
  48. use TestRail::API;
  49. use TestRail::Utils;
  50. use TestRail::Utils::Results;
  51. use Getopt::Long qw{GetOptionsFromArray};
  52. Getopt::Long::Configure('pass_through');
  53. use File::HomeDir qw{my_home};
  54. if (!caller()) {
  55. my ($out,$code) = run('args' => \@ARGV);
  56. print $out;
  57. exit $code;
  58. }
  59. sub run {
  60. my %params = @_;
  61. my $opts = {};
  62. # Parse config file
  63. my $homedir = my_home() || '.';
  64. if (-e $homedir . '/.testrailrc') {
  65. $opts = TestRail::Utils::parseConfig($homedir);
  66. }
  67. # Override configuration with switches
  68. GetOptionsFromArray($params{'args'},
  69. 'apiurl=s' => \$opts->{'apiurl'},
  70. 'password=s' => \$opts->{'password'},
  71. 'user=s' => \$opts->{'user'},
  72. 'status=s@' => \$opts->{'statuses'},
  73. 'j|project=s' => \$opts->{'project'},
  74. 'p|plan=s' => \$opts->{'plan'},
  75. 'r|run=s' => \$opts->{'run'},
  76. 'c|config=s@' => \$opts->{'configs'},
  77. 'a|assignedto=s@' => \$opts->{'users'},
  78. 'e|encoding=s' => \$opts->{'encoding'},
  79. 'h|help' => \$opts->{'help'},
  80. );
  81. if ($opts->{help}) { return ('',TestRail::Utils::help()); }
  82. $opts->{'browser'} = $params{'browser'};
  83. my $status = $params{'args'}->[0];
  84. my $reason = $params{'args'}->[1];
  85. die("No status to set provided.") unless $status;
  86. TestRail::Utils::interrogateUser($opts,qw{apiurl user password project run});
  87. my $tr = TestRail::Utils::getHandle($opts);
  88. $opts->{'set_status_to'} = $status;
  89. $opts->{'reason'} = $reason;
  90. my $results = TestRail::Utils::Results::bulkMarkResults($opts,$tr);
  91. return ("Successfully set the status of ".scalar(@$results)." cases to $status.\n",0) if $results;
  92. return ("Could find no cases to set results for.\n",255);
  93. }
  94. 1;
  95. __END__
  96. L<TestRail::API>
  97. L<File::HomeDir> for the finding of .testrailrc
  98. =head1 SPECIAL THANKS
  99. Thanks to cPanel Inc, for graciously funding the creation of this distribution.