~ubuntu-branches/ubuntu/trusty/mysql-5.6/trusty

« back to all changes in this revision

Viewing changes to mysql-test/lib/t/testMyConfigFactory.t

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-02-12 11:54:27 UTC
  • Revision ID: package-import@ubuntu.com-20140212115427-oq6tfsqxl1wuwehi
Tags: upstream-5.6.15
ImportĀ upstreamĀ versionĀ 5.6.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
# -*- cperl -*-
 
3
 
 
4
# Copyright (c) 2007 MySQL AB, 2009 Sun Microsystems, Inc.
 
5
# Use is subject to license terms.
 
6
 
7
# This program is free software; you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation; version 2 of the License.
 
10
 
11
# This program is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU General Public License for more details.
 
15
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with this program; if not, write to the Free Software
 
18
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
19
 
 
20
use strict;
 
21
use warnings;
 
22
 
 
23
use File::Temp qw / tempdir /;
 
24
my $dir = tempdir( CLEANUP => 1 );
 
25
 
 
26
use Test::More qw(no_plan);
 
27
 
 
28
BEGIN { use_ok ( "My::ConfigFactory" ) };
 
29
 
 
30
my $gen1_cnf= "$dir/gen1.cnf";
 
31
open(OUT, ">", $gen1_cnf) or die;
 
32
 
 
33
print OUT <<EOF
 
34
[mysqld.master]
 
35
# Comment
 
36
option1=value1
 
37
basedir=abasedir
 
38
 
 
39
[mysqld.1]
 
40
# Comment
 
41
option1=value1
 
42
option2=value2
 
43
 
 
44
[ENV]
 
45
MASTER_MY_PORT=\@mysqld.master.port
 
46
 
 
47
EOF
 
48
;
 
49
close OUT;
 
50
 
 
51
my $basedir= "../..";
 
52
 
 
53
my $config= My::ConfigFactory->new_config
 
54
(
 
55
 {
 
56
  basedir => $basedir,
 
57
  template_path => $gen1_cnf,
 
58
  vardir => "/path/to/var",
 
59
  baseport => 10987,
 
60
  #hosts => [ 'host1', 'host2' ],
 
61
 }
 
62
);
 
63
 
 
64
print $config;
 
65
 
 
66
ok ( $config->group("mysqld.master"), "group mysqld.master exists");
 
67
ok ( $config->group("mysqld.1"), "group mysqld.1 exists");
 
68
ok ( $config->group("client"), "group client exists");
 
69
ok ( !$config->group("mysqld.3"), "group mysqld.3 does not exist");
 
70
 
 
71
ok ( $config->first_like("mysqld"), "group like 'mysqld' exists");
 
72
 
 
73
is( $config->value('mysqld.1', '#host'), 'localhost',
 
74
    "mysqld.1.#host has been generated");
 
75
 
 
76
is( $config->value('client', 'host'), 'localhost',
 
77
    "client.host has been generated");
 
78
 
 
79
is( $config->value('client', 'host'),
 
80
    $config->value('mysqld.master', '#host'),
 
81
    "client.host is same as mysqld.master.host");
 
82
 
 
83
ok ( $config->value("mysqld.1", 'character-sets-dir') =~ /$basedir.*charsets$/,
 
84
     "'character-sets-dir' generated");
 
85
 
 
86
ok ( $config->value("mysqld.1", 'lc-messages-dir') =~ /$basedir.*share$/,
 
87
     "'lc-messages-dir' generated");
 
88
 
 
89
ok ( $config->value("ENV", 'MASTER_MY_PORT') =~ /\d/,
 
90
     "'lc-messages-dir' generated");
 
91
 
 
92
my $gen2_cnf= "$dir/gen2.cnf";
 
93
open(OUT, ">", $gen2_cnf) or die;
 
94
 
 
95
print OUT <<EOF
 
96
[mysqld.master]
 
97
EOF
 
98
;
 
99
close OUT;
 
100
 
 
101
my $config2= My::ConfigFactory->new_config
 
102
(
 
103
 {
 
104
  basedir => $basedir,
 
105
  template_path => $gen2_cnf,
 
106
  vardir => "/path/to/var",
 
107
  baseport => 10987,
 
108
  #hosts => [ 'host1', 'host2' ],
 
109
 }
 
110
);
 
111
 
 
112
print $config2;
 
113
 
 
114
ok ( $config2->first_like("mysqld"), "group like 'mysqld' exists");