TestRail.pm 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # ABSTRACT: Upload your TAP results to TestRail in realtime
  2. # PODNAME: App::Prove::Plugin::TestRail
  3. package App::Prove::Plugin::TestRail;
  4. use strict;
  5. use warnings;
  6. use utf8;
  7. =head1 SYNOPSIS
  8. `prove -PTestRail='http://some.testlink.install/,someUser,somePassword,TestProject,TestRun' sometest.t`
  9. =cut
  10. =head1 DESCRIPTION
  11. Prove plugin to upload test results to TestRail installations.
  12. Accepts input in the standard Prove plugin fashion (-Ppluginname=value,value,value...), but will also parse a config file.
  13. If ~/.testrailrc exists, it will be parsed for any of these values in a newline separated key=value list. Example:
  14. apiurl=http://some.testrail.install
  15. user=someGuy
  16. password=superS3cret
  17. project=TestProject
  18. run=TestRun
  19. case_per_ok=0
  20. step_results=sr_sys_name
  21. Be aware that if you do so, it will look for any unsatisfied arguments in the order of their appearance above.
  22. =head1 OVERRIDDEN METHODS
  23. =head2 load(parser)
  24. Shoves the arguments passed to the prove plugin into $ENV so that Test::Rail::Parser can get at them.
  25. Not the most elegant solution, but I see no other clear path to get those variables downrange to it's constructor.
  26. =cut
  27. sub load {
  28. my ($class, $p) = @_;
  29. my ($apiurl,$password,$user,$project,$run,$case_per_ok,$step_results) = _parseConfig();
  30. my $app = $p->{app_prove};
  31. my $args = $p->{'args'};
  32. $apiurl //= shift @$args;
  33. $user //= shift @$args;
  34. $password //= shift @$args;
  35. $project //= shift @$args;
  36. $run //= shift @$args;
  37. $case_per_ok //= shift @$args;
  38. $step_results //= shift @$args;
  39. $app->harness('Test::Rail::Harness');
  40. $app->merge(1);
  41. #XXX I can't figure out for the life of me any other way to pass this data. #YOLO
  42. $ENV{'TESTRAIL_APIURL'} = $apiurl;
  43. $ENV{'TESTRAIL_USER'} = $user;
  44. $ENV{'TESTRAIL_PASS'} = $password;
  45. $ENV{'TESTRAIL_PROJ'} = $project;
  46. $ENV{'TESTRAIL_RUN'} = $run;
  47. $ENV{'TESTRAIL_CASEOK'} = $case_per_ok;
  48. $ENV{'TESTRAIL_STEPS'} = $step_results;
  49. return $class;
  50. }
  51. sub _parseConfig {
  52. my $results = {};
  53. my $arr =[];
  54. open(my $fh, '<', $ENV{"HOME"} . '/.testrailrc') or return (undef,undef,undef);#couldn't open!
  55. while (<$fh>) {
  56. chomp;
  57. @$arr = split(/=/,$_);
  58. if (scalar(@$arr) != 2) {
  59. warn("Could not parse $_ in tlreport config\n");
  60. next;
  61. }
  62. $results->{lc($arr->[0])} = $arr->[1];
  63. }
  64. close($fh);
  65. return ($results->{'apiurl'},$results->{'password'},$results->{'user'},$results->{'project'},$results->{'run'},$results->{'case_per_ok'},$results->{'step_results'});
  66. }
  67. 1;
  68. __END__
  69. =head1 SEE ALSO
  70. L<TestRail::API>
  71. L<Test::Rail::Parser>
  72. L<App::Prove>
  73. =head1 SPECIAL THANKS
  74. Thanks to cPanel Inc, for graciously funding the creation of this module.