mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-26 15:31:55 +00:00
Almost working pt-agent main process. Clean up HTTP::Micro. Add Percona/WebAPI/Util, and some basic Percona/WebAPI/Representation tests.
This commit is contained in:
@@ -11,7 +11,7 @@ use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
|
||||
use HTTPMicro;
|
||||
use HTTP::Micro;
|
||||
|
||||
local $EVAL_ERROR;
|
||||
eval { require HTTP::Tiny };
|
||||
@@ -22,12 +22,12 @@ if ( $EVAL_ERROR ) {
|
||||
# Need a simple URL that won't try to do chunking.
|
||||
for my $test_url ( "http://www.percona.com/robots.txt", "https://v.percona.com" ) {
|
||||
my $tiny = HTTP::Tiny->new(max_redirect => 0)->request('GET', $test_url);
|
||||
my $micro = HTTPMicro->new->request('GET', $test_url);
|
||||
my $micro = HTTP::Micro->new->request('GET', $test_url);
|
||||
|
||||
like(
|
||||
$micro->{content},
|
||||
qr/^\Q$tiny->{content}/,
|
||||
"HTTPMicro == HTTP::Tiny for $test_url"
|
||||
"HTTP::Micro == HTTP::Tiny for $test_url"
|
||||
);
|
||||
}
|
||||
|
36
t/lib/Percona/WebAPI/Representation.t
Normal file
36
t/lib/Percona/WebAPI/Representation.t
Normal file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
BEGIN {
|
||||
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
|
||||
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
|
||||
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
|
||||
};
|
||||
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
|
||||
use PerconaTest;
|
||||
use Percona::Toolkit;
|
||||
use Percona::WebAPI::Resource::Agent;
|
||||
use Percona::WebAPI::Representation;
|
||||
|
||||
my $agent = Percona::WebAPI::Resource::Agent->new(
|
||||
id => '123',
|
||||
hostname => 'pt',
|
||||
versions => {
|
||||
Perl => '5.10.1',
|
||||
},
|
||||
);
|
||||
|
||||
is(
|
||||
Percona::WebAPI::Representation::as_json($agent),
|
||||
q/{"versions":{"Perl":"5.10.1"},"id":"123","hostname":"pt"}/,
|
||||
"as_json"
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
done_testing;
|
50
t/lib/Percona/WebAPI/Util.t
Normal file
50
t/lib/Percona/WebAPI/Util.t
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
BEGIN {
|
||||
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
|
||||
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
|
||||
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
|
||||
};
|
||||
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
|
||||
use PerconaTest;
|
||||
use Percona::Toolkit;
|
||||
use Percona::WebAPI::Resource::Config;
|
||||
use Percona::WebAPI::Util qw(resource_diff);
|
||||
|
||||
my $x = Percona::WebAPI::Resource::Config->new(
|
||||
options => {
|
||||
'lib' => '/var/lib',
|
||||
'spool' => '/var/spool',
|
||||
},
|
||||
);
|
||||
|
||||
my $y = Percona::WebAPI::Resource::Config->new(
|
||||
options => {
|
||||
'lib' => '/var/lib',
|
||||
'spool' => '/var/spool',
|
||||
},
|
||||
);
|
||||
|
||||
is(
|
||||
resource_diff($x, $y),
|
||||
0,
|
||||
"No diff"
|
||||
);
|
||||
|
||||
$y->options->{spool} = '/var/lib/spool';
|
||||
|
||||
is(
|
||||
resource_diff($x, $y),
|
||||
1,
|
||||
"Diff"
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
done_testing;
|
Reference in New Issue
Block a user