TestRail.pm 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. =cut
  23. sub load {
  24. my ($class, $p) = @_;
  25. my ($apiurl,$password,$user,$project,$run,$case_per_ok,$step_results) = _parseConfig();
  26. my $app = $p->{app_prove};
  27. my $args = $p->{'args'};
  28. $apiurl //= shift @$args;
  29. $user //= shift @$args;
  30. $password //= shift @$args;
  31. $project //= shift @$args;
  32. $run //= shift @$args;
  33. $case_per_ok //= shift @$args;
  34. $step_results //= shift @$args;
  35. $app->harness('Test::Rail::Harness');
  36. $app->merge(1);
  37. #XXX I can't figure out for the life of me any other way to pass this data. #YOLO
  38. $ENV{'TESTRAIL_APIURL'} = $apiurl;
  39. $ENV{'TESTRAIL_USER'} = $user;
  40. $ENV{'TESTRAIL_PASS'} = $password;
  41. $ENV{'TESTRAIL_PROJ'} = $project;
  42. $ENV{'TESTRAIL_RUN'} = $run;
  43. $ENV{'TESTRAIL_CASEOK'} = $case_per_ok;
  44. $ENV{'TESTRAIL_STEPS'} = $step_results;
  45. }
  46. sub _parseConfig {
  47. my $results = {};
  48. my $arr =[];
  49. open(my $fh, '<', $ENV{"HOME"} . '/.testrailrc') or return (undef,undef,undef);#couldn't open!
  50. while (<$fh>) {
  51. chomp;
  52. @$arr = split(/=/,$_);
  53. if (scalar(@$arr) != 2) {
  54. warn("Could not parse $_ in tlreport config\n");
  55. next;
  56. }
  57. $results->{lc($arr->[0])} = $arr->[1];
  58. }
  59. close($fh);
  60. return ($results->{'apiurl'},$results->{'password'},$results->{'user'},$results->{'project'},$results->{'run'},$results->{'case_per_ok'},$results->{'step_results'});
  61. }
  62. 1;
  63. __END__
  64. =head1 SEE ALSO
  65. L<TestRail::API>
  66. L<Test::Rail::Parser>
  67. L<App::Prove>
  68. =head1 SPECIAL THANKS
  69. Thanks to cPanel Inc, for graciously funding the creation of this module.