TestRail.pm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. use File::HomeDir qw{my_home};
  8. use TestRail::Utils;
  9. =head1 SYNOPSIS
  10. `prove -PTestRail='apiurl=http://some.testlink.install/,user=someUser,password=somePassword,project=TestProject,run=TestRun,plan=TestPlan,configs=Config1:Config2:Config3,version=0.014' sometest.t`
  11. =cut
  12. =head1 DESCRIPTION
  13. Prove plugin to upload test results to TestRail installations.
  14. Accepts input in the standard Prove plugin fashion (-Ppluginname='key=value,key=value,key=value...'), but will also parse a config file.
  15. When fed in prove plugin style, key=value input is expected.
  16. If \$HOME/.testrailrc exists, it will be parsed for any of these values in a newline separated key=value list. Example:
  17. apiurl=http://some.testrail.install
  18. user=someGuy
  19. password=superS3cret
  20. project=TestProject
  21. run=TestRun
  22. plan=GosPlan
  23. configs=config1:config2:config3: ... :configN
  24. version=xx.xx.xx.xx
  25. case_per_ok=0
  26. step_results=sr_sys_name
  27. lockname=internal_lock_name
  28. testsuite_id=123
  29. testsuite=blahblah #don't do this it's mutually exclusive with testuite_id
  30. sections=section1:section2:section3: ... :sectionN
  31. autoclose=0
  32. encoding=UTF-8
  33. Note that passing configurations as filters for runs inside of plans are separated by colons.
  34. Values passed in via query string will override values in \$HOME/.testrailrc.
  35. If your system has no concept of user homes, it will look in the current directory for .testrailrc.
  36. See the documentation for the constructor of L<Test::Rail::Parser> as to why you might want to pass the aforementioned options.
  37. =head1 CAVEATS
  38. When running prove in multiple job mode (-j), or when breaking out test jobs into multiple prove processes, auto-spawn of plans & runs can race.
  39. Be sure to extend your harness to make sure these things are already created if you do either of these things.
  40. =head1 OVERRIDDEN METHODS
  41. =head2 load(parser)
  42. Shoves the arguments passed to the prove plugin into $ENV so that Test::Rail::Parser can get at them.
  43. Not the most elegant solution, but I see no other clear path to get those variables downrange to it's constructor.
  44. =cut
  45. sub load {
  46. my ($class, $p) = @_;
  47. my $app = $p->{app_prove};
  48. my $args = $p->{'args'};
  49. my $params = {};
  50. #Only attempt parse if we aren't mocking and the homedir exists
  51. my $homedir = my_home() || '.';
  52. $params = TestRail::Utils::parseConfig($homedir) if -e $homedir && !$ENV{'TESTRAIL_MOCKED'};
  53. my @kvp = ();
  54. my ($key,$value);
  55. foreach my $arg (@$args) {
  56. @kvp = split(/=/,$arg);
  57. if (scalar(@kvp) < 2) {
  58. print "Unrecognized Argument '$arg' to App::Prove::Plugin::Testrail, ignoring\n";
  59. next;
  60. }
  61. $key = shift @kvp;
  62. $value = join('',@kvp);
  63. $params->{$key} = $value;
  64. }
  65. $app->harness('Test::Rail::Harness');
  66. $app->merge(1);
  67. #XXX I can't figure out for the life of me any other way to pass this data. #YOLO
  68. $ENV{'TESTRAIL_APIURL'} = $params->{apiurl};
  69. $ENV{'TESTRAIL_USER'} = $params->{user};
  70. $ENV{'TESTRAIL_PASS'} = $params->{password};
  71. $ENV{'TESTRAIL_PROJ'} = $params->{project};
  72. $ENV{'TESTRAIL_RUN'} = $params->{run};
  73. $ENV{'TESTRAIL_PLAN'} = $params->{plan};
  74. $ENV{'TESTRAIL_CONFIGS'} = $params->{configs};
  75. $ENV{'TESTRAIL_VERSION'} = $params->{version};
  76. $ENV{'TESTRAIL_CASEOK'} = $params->{case_per_ok};
  77. $ENV{'TESTRAIL_STEPS'} = $params->{step_results};
  78. $ENV{'TESTRAIL_SPAWN'} = $params->{testsuite_id};
  79. $ENV{'TESTRAIL_TESTSUITE'} = $params->{testsuite};
  80. $ENV{'TESTRAIL_SECTIONS'} = $params->{sections};
  81. $ENV{'TESTRAIL_AUTOCLOSE'} = $params->{autoclose};
  82. $ENV{'TESTRAIL_ENCODING'} = $params->{encoding};
  83. return $class;
  84. }
  85. 1;
  86. __END__
  87. =head1 SEE ALSO
  88. L<TestRail::API>
  89. L<Test::Rail::Parser>
  90. L<App::Prove>
  91. L<File::HomeDir> for the finding of .testrailrc
  92. =head1 SPECIAL THANKS
  93. Thanks to cPanel Inc, for graciously funding the creation of this module.