File: VersionParser.t

package info (click to toggle)
percona-toolkit 3.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 68,916 kB
  • sloc: perl: 241,287; sql: 22,868; sh: 19,746; javascript: 6,799; makefile: 353; awk: 38; python: 30; sed: 1
file content (151 lines) | stat: -rw-r--r-- 3,638 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/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 tests => 31;

use VersionParser;
use PerconaTest;

my $v1 = new_ok "VersionParser", [ "4.1" ], "new from string works";

is(
   "$v1",
   "4.1",
   "object from string stringifies as expected"
);

is(
   $v1->innodb_version,
   'NO',
   'default ->innodb_version is NO'
);

is(
   $v1->flavor(),
   "Unknown",
   "default ->flavor is Unknown"
);

my $v2;
$v2 = new_ok "VersionParser", [ qw( major 5 minor 5 revision 5 ) ], "new from parts works";
is( "$v2", "5.5.5", "..and stringifies correctly" );
$v2 = new_ok "VersionParser", [ { qw( major 5 minor 5 revision 5 ) } ], "new from hashref works";
is( "$v2", "5.5.5", "..and stringifies correctly" );

for my $test (
    [ "5.0.1", "lt", "5.0.2" ],
    [ "5.0",   "eq", "5.0.2" ],
    [ "5.1.0", "gt", "5.0.99" ],
    [ "6",     "gt", "5.9.9" ],
    [ "4",     "ne", "5.0.2" ],
    [ "5.0.1", "ne", "5.0.2" ],
    [ "5.0.1", "eq", "5.0.1" ],
    [ "5.0.1", "eq", "5" ],
    [ "5.0.1", "lt", "6" ],
    [ "5.0.1", "gt", "5.0.09" ],
    # TODO: Should these actually happen?
    # [ "5.0.1"  eq "5.0.10" ]
    # [ "5.0.10" lt "5.0.3" ]
) {
    my ($v, $cmp, $against, $test) = @$test;
    
    cmp_ok( VersionParser->new($v), $cmp, $against, "$v $cmp $against" );
}

my $c = VersionParser->new("5.5.1");

is(
   $c->comment("SET NAMES utf8"),
   "/*!50501 SET NAMES utf8 */",
   "->comment works as expected"
);

is(
   $c->comment('@@hostname,'),
   '/*!50501 @@hostname, */',
   '->comment works with @@variable'
);


is(
   VersionParser->new('5.0.38-Ubuntu_0ubuntu1.1-log')->normalized_version,
   '50038',
   'Parser works on ordinary version',
);

is(
   VersionParser->new('5.5')->normalized_version,
   '50500',
   'Parser works on a simplified version',
);

my $fractional_version = VersionParser->new('5.0.08');

is(
   $fractional_version->revision,
   '0.8',
   'Verson(5.0.08), the revision is 0.8',
);

is(
   "$fractional_version",
   "5.0.08",
   "Version(5.0.08) stringifies to 5.0.08"
);

is(
   $fractional_version->normalized_version(),
   "50000",
   "Version(5.0.08) normalizes to 50000"
);

# Open a connection to MySQL, or skip the rest of the tests.
use DSNParser;
use Sandbox;
my $dp  = new DSNParser(opts=>$dsn_opts);
my $sb  = new Sandbox(basedir => '/tmp', DSNParser => $dp);
my $dbh = $sb->get_dbh_for('master');
SKIP: {
   skip 'Cannot connect to MySQL', 2 unless $dbh;
   my $vp = new_ok "VersionParser", [ $dbh ], "new from dbh works";
   cmp_ok($vp, "ge", '3.23.00', 'Version is > 3.23');

   unlike(
      $vp->innodb_version(),
      qr/DISABLED/,
      "InnoDB version"
   );

   my ($ver) = $dbh->selectrow_array("SELECT VERSION()");
   $ver =~ s/(\d+\.\d+\.\d+).*/$1/;

   is(
      "$vp",
      $ver,
      "object from dbh stringifies as expected"
   );

   my (undef, $flavor) = $dbh->selectrow_array("SHOW VARIABLES LIKE 'version_comment'");
   SKIP: {  
      skip "Couldn't fetch version_comment from the db", 1 unless $flavor;
      is(
         $vp->flavor(),
         $flavor,
         "When created from a dbh, flavor is set through version_comment",
      );
   };
}

# #############################################################################
# Done.
# #############################################################################
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
exit;