4
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
5
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
6
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
10
use warnings FATAL => 'all';
11
use English qw(-no_match_vars);
12
use Test::More tests => 13;
14
use TextResultSetParser;
18
$Data::Dumper::Indent = 1;
19
$Data::Dumper::Sortkeys = 1;
20
$Data::Dumper::Quotekeys = 0;
22
my $r = new TextResultSetParser();
23
isa_ok($r, 'TextResultSetParser');
26
sub { $r->parse(load_file('t/lib/samples/slowlogs/slow002.txt')) },
27
qr/Cannot determine if text is/,
28
"Dies if output type cannot be determined"
32
$r->parse( load_file('t/lib/samples/pl/recset001.txt') ),
39
Info => 'show processlist',
45
'Basic tablular processlist'
49
$r->parse( load_file('t/lib/samples/pl/recset002.txt') ),
56
Info => 'select * from foo1;',
59
Host => '1.2.3.4:3333'
66
Info => 'select * from foo2;',
69
Host => '1.2.3.4:5455'
72
'2 row vertical processlist'
75
my $recset = $r->parse ( load_file('t/lib/samples/pl/recset003.txt') );
80
'113 row vertical processlist'
83
$recset = $r->parse( load_file('t/lib/samples/pl/recset004.txt') );
88
'51 row vertical processlist'
92
$r->parse( load_file('t/lib/samples/pl/recset005.txt') ),
97
Host => '1.2.3.148:49718',
105
'1 vertical row, No State value'
109
$r->parse( load_file('t/lib/samples/pl/recset009.txt') ),
114
Host => 'localhost:54732',
116
Command => 'Binlog Dump',
118
State => 'Has sent all binlog to slave; waiting for binlog to be updated',
129
Info => 'show full processlist',
132
'Horizontal, tab-separated'
135
$recset = $r->parse(load_file('t/lib/samples/show-variables/vars001.txt'));
136
# Should only get the var once.
137
my $got_var = grep { $_->{Variable_name} eq 'warning_count' } @$recset;
144
$recset = $r->parse(load_file('t/lib/samples/show-variables/vars002.txt'));
145
$got_var = grep { $_->{Variable_name} eq 'warning_count' } @$recset;
153
# #############################################################################
154
# Parse with NAME_lc for lowercase key/col names.
155
# #############################################################################
156
$r = new TextResultSetParser(NAME_lc => 1);
158
$recset = $r->parse(load_file('t/lib/samples/show-variables/vars001.txt'));
159
$got_var = grep { $_->{variable_name} eq 'warning_count' } @$recset;
166
$recset = $r->parse(load_file('t/lib/samples/show-variables/vars002.txt'));
167
$got_var = grep { $_->{variable_name} eq 'warning_count' } @$recset;
171
"NAME_lc tab-separated"
175
$r->parse( load_file('t/lib/samples/pl/recset002.txt') ),
182
info => 'select * from foo1;',
185
host => '1.2.3.4:3333'
192
info => 'select * from foo2;',
195
host => '1.2.3.4:5455'
201
# #############################################################################
203
# #############################################################################