ile>: The report that is generated at the end of the run (I<mktest.rpt>).
=item
B<jsnfile>: The json that will be send to the Perl5CoreSmokeDB (I<mktest.jsn>).
=item
B<lfile>: Absolute location of
e Test::Smoke::App::Options;
use Test::Smoke::App::SmokePerl;
use File::Copy;
use File::Spec;
use JSON;
use Path::Tiny ();
use POSIX ();
my $app = Test::Smoke::App::SmokePerl->new(
Test::Smoke::
File::Spec->catfile($app->option('ddir'), $app->option('jsnfile'));
die "Could not locate mktest.json" unless -f $jsnfile;
my $log_file = compose_log_file_name($adir, $jsnfile);
my $localtime = POSI
my ($adir, $jsnfile) = @_;
my $utf8_encoded_json_text = Path::Tiny::path($jsnfile)->slurp_utf8;
my $config = decode_json($utf8_encoded_json_text);
my $SHA = $config->{sysinfo}->{git_id}
],
general_options => [
adir(),
commit_sha(),
jsonreport(),
max_reports(),
smokedb_url(),
],
special_options
re the JSON report in.',
);
}
sub jsonreport {
return $opt->new(
name => 'jsonreport',
option => '=s',
default => undef,
helptext => "Name of json repor
port',
option => '!',
default => $default,
helptext => "Create the report/json files.",
);
}
sub rptfile {
return $opt->new(
name => 'rptfile',
option
package Test::Smoke::Util::LoadAJSON;
use warnings;
use strict;
our $VERSION = '0.04';
=head1 NAME
Test::Smoke::Util::LoadAJSON - A Cpanel::JSON::XS/JSON:PP/JSON::XS Factory Class
=head1 SYNOPSIS
use Test::Smoke::Util::LoadAJSON;
my $json = Test::Smoke::Util::LoadAJSON->new->utf8->pretty->encode(\%data);
=head1 DESCRIPTION
This is purely a fallback factory class that helps keep our
h a clean perl 5.14+ install that have L<JSON::PP> but not
JSON. Also people that installed L<JSON::XS> on a pre-5.14 system.
Also checks for C<$ENV{PERL_JSON_BACKEND}> to force either of the two.
=
('smokedb_url') >>
=back
=cut
sub run {
my $self = shift;
$self->check_for_report_and_json;
if ($self->option('mail')) {
$self->{_mailer} = Test::Smoke::Mailer->new(
}
}
=head2 $sendrpt->check_for_report_and_json()
Check for the '.rpt' and the '.jsn' file, return true if both exist.
=cut
sub check_for_report_and_json {
my $self = shift;
my $rptfile =
$self->log_info("Regenerate report and json.");
$self->regen_report_and_json();
}
return 1;
}
=head2 $sendrpt->regen_report_and_json()
Create a reporter object and generate the
--sha <commit-sha> Commit SHA for the smoke (repeat for more reports)
--jsonreport <filename> The actual json-file to re-post
Override the config:
--adir <dir> Archive directory
the json files from the archive.
=cut
sub pick_reports {
my $self = shift;
if (my $jsonreport = $self->option('jsonreport')) {
die("Cannot find '$jsonreport'") unless -f $jsonrepor
t;
if ($jsonreport =~ m{^ / }x) {
$self->poster->ddir('');
}
else {
$self->poster->ddir(curdir());
}
return ($jsonreport);
}
my
=> $self->ua_timeout) : () ),
);
return $self;
}
=head2 $poster->_post_data()
Post the json to CoreSmokeDB using HTTP::Tiny.
=cut
sub _post_data {
my $self = shift;
$self->log_in
$self->poster);
$self->log_debug("Report data: %s", my $json = $self->get_json);
my $form_data = sprintf("json=%s", uri_escape($json));
my $response = $self->ua->request(
POST =>
onse->{content});
return $response->{content};
}
=head2 $poster->_post_data_api()
Post the json to CoreSmokeDB using HTTP::Tiny, using the API-function.
=cut
sub _post_data_api {
my $self
string(),
%extra_args
);
return $self;
}
=head2 $poster->_post_data()
Post the json to CoreSmokeDB using LWP::UserAgent.
=cut
sub _post_data {
my $self = shift;
$self->lo
$self->log_debug("Report data: %s", my $json = $self->get_json);
my $response = $self->ua->post(
$self->smokedb_url,
{ json => $json }
);
if ( !$response->is_success )
elf->poster);
$self->log_debug("Report data: %s", my $json = $self->get_json);
my $post_data = sprintf(qq/{"report_data": %s}/, $json);
require HTTP::Request;
require HTTP::Headers;
t::Smoke;
require Test::Smoke::PostQueue;
use File::Spec::Functions;
use Test::Smoke::Util::LoadAJSON;
=head1 NAME
Test::Smoke::Poster::Base - Base class for the posters to CoreSmokeDB.
=head1 DES
Named.
=over
=item smokedb_url => $some_url
=item ddir => $smoke_directory
=item jsnfile => $json_file (mktest.jsn)
=item v => $verbosity
=back
=head3 Returns
An instance of the class.
=head
et_json()
=head3 Arguments
None.
=head3 Returns
The json string that was stored in C<< $ddir/$jsnfile >>.
=head3 Exceptions
File I/O.
=cut
sub get_json {
my $self = shift;
my $json_fi
,
verbose => $self->v
);
return $self;
}
=head2 $poster->_post_data()
Post the json to CoreSmokeDB using L<curl(1)>.
=cut
sub _post_data {
my $self = shift;
$self->log_in
$self->poster);
$self->log_debug("Report data: %s", my $json = $self->get_json);
my $form_data = sprintf("json=%s", uri_escape($json));
my ($fh, $filename) = tempfile('curl-tsrepostXXXXXX
oreSmokeDB] %s", $response);
return $response;
}
=head2 $poster->_post_data_api()
Post the json to CoreSmokeDB API-function using L<curl(1)>.
=cut
sub _post_data_api {
my $self = shift;
;
use Cwd;
use Encode qw( decode encode );
use File::Spec::Functions;
use Test::Smoke::Util::LoadAJSON;
use POSIX qw( strftime );
use System::Info;
use Test::Smoke::Util qw(
grepccmsg grepnonfatal
end_log send_out user_note/, grep m/^_/ => keys %rpt;
my $json = JSON->new->utf8(1)->pretty(1)->encode(\%rpt);
# write the json to file:
my $jsn_file = catfile($self->{ddir}, $self->{jsn
$json;
close $jsn;
$self->log_info("Write to '%s': ok", $jsn_file);
}
else {
$self->log_warn("Error creating '%s': %s", $jsn_file, $!);
}
return $self->{_json}