1 # Copyright (c) 2006 Zmanda Inc. All Rights Reserved.
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License version 2 as published
5 # by the Free Software Foundation.
7 # This program is distributed in the hope that it will be useful, but
8 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 # You should have received a copy of the GNU General Public License along
13 # with this program; if not, write to the Free Software Foundation, Inc.,
14 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 # Contact information: Zmanda Inc, 505 N Mathlida Ave, Suite 120
17 # Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
19 use Test::More qw(no_plan);
22 use lib "@amperldir@";
25 # wrapper to call amgetconf and return the results
27 # open amgetconf and read from it
28 my $cmd = "$sbindir/amgetconf " . join(" ", @_) . " 2>&1";
34 # this is re-created for each test
38 # First, try amgetconf out without a config
40 like(amgetconf(), qr(\AUsage: )i,
41 "bare 'amgetconf' gives usage message");
42 like(amgetconf("this-probably-doesnt-exist"), qr(could not open conf file)i,
43 "error message when configuration parameter doesn't exist");
46 # Next, work against a basically empty config
48 $testconf = Amconfig->new();
52 is(amgetconf('TESTCONF', "reserve"), "100",
53 "reserve defaults to 100");
54 is(amgetconf('TESTCONF', "tapelist"), "tapelist",
55 "tapelist defaults to 'tapelist'");
56 is(amgetconf('TESTCONF', "usetimestamps"), "yes",
57 "usetimestamps defaults to 'yes'");
59 # test a nonexistent parameter
60 like(amgetconf('TESTCONF', "foos_per_bar"), qr/no such parameter/,
61 "handles nonexistent parameters");
63 # test build parameters (just the most common)
64 is(amgetconf('TESTCONF', "build.bindir"), $bindir, "build.bindir is correct");
65 is(amgetconf('TESTCONF', "build.sbindir"), $sbindir, "build.sbindir is correct");
66 is(amgetconf('TESTCONF', "build.amlibexecdir"), $amlibexecdir, "build.amlibexecdir is correct");
67 is(amgetconf('TESTCONF', "build.mandir"), $mandir, "build.mandir is correct");
68 is(amgetconf('TESTCONF', "build.AMANDA_DBGDIR"), $AMANDA_DBGDIR, "build.AMANDA_DBGDIR is correct");
69 is(amgetconf('TESTCONF', "build.AMANDA_TMPDIR"), $AMANDA_TMPDIR, "build.AMANDA_TMPDIR is correct");
70 is(amgetconf('TESTCONF', "build.CONFIG_DIR"), $CONFIG_DIR, "build.CONFIG_DIR is correct");
73 my $dbfile = amgetconf('TESTCONF', "dbopen.foo");
74 like($dbfile, qr(^$AMANDA_DBGDIR/server/foo.[0-9]*.debug$),
75 "'amgetconf dbopen.foo' returns a proper debug filename");
77 "'amgetconf dbopen.foo' creates the debug file");
78 like(amgetconf('TESTCONF', "dbclose.foo"), qr/cannot parse/,
79 "dbclose without filename fails");
80 is(amgetconf('TESTCONF', "dbclose.foo:$dbfile"), $dbfile,
81 "'amgetconf dbclose.foo:<filename>' returns the debug filename");
84 # Test an invalid config file
86 $testconf = Amconfig->new();
87 $testconf->add_param("foos_per_bar", "10");
90 like(amgetconf('TESTCONF', "foos_per_bar"), qr/errors processing config file/,
91 "gives error on invalid configuration");
94 # Now let's fill in some interesting values
96 $testconf = Amconfig->new();
97 $testconf->add_param("reserved-udp-port", '100,200');
98 $testconf->add_param("printer", '"/dev/lp"');
99 $testconf->add_param("reserve", '27');
102 is(amgetconf('TESTCONF', "reserved-udp-port"), "100,200",
103 "correctly returns intrange parameters from the file");
104 is(amgetconf('TESTCONF', "printer"), "/dev/lp",
105 "correctly returns string parameters from the file");
106 is(amgetconf('TESTCONF', "reserve"), "27",
107 "correctly returns integer parameters from the file");
108 is(amgetconf('TESTCONF', "rEsErVe"), "27",
109 "is case-insensitive");
112 # device_property can appear multiple times
114 $testconf = Amconfig->new();
115 $testconf->add_param("device_property", '"power" "on"');
116 $testconf->add_param("device_property", '"turbo" "engaged"');
119 is_deeply([sort(+split(qr/\n/, amgetconf('TESTCONF', 'device_property')))],
120 [sort('"power" "on"', '"turbo" "engaged"')],
121 "device_property can have multiple values");
126 $testconf = Amconfig->new();
127 $testconf->add_tapetype("cassette", [ length => "32 k" ]);
128 $testconf->add_tapetype("reel2reel", [ length => "1 M" ]);
129 $testconf->add_tapetype("scotch", [ length => "500 bytes" ]); # (use a sharpie)
130 $testconf->add_dumptype("testdump", [ comment => '"testdump-dumptype"' ]);
131 $testconf->add_interface("testiface", [ use => '10' ]);
132 $testconf->add_holdingdisk("hd17", [ chunksize => '128' ]);
135 is_deeply([sort(+split(/\n/, amgetconf('TESTCONF', '--list', 'tapetype')))],
136 [sort("cassette", "reel2reel", "scotch", "TEST-TAPE")],
137 "--list returns correct set of tapetypes");
138 is(amgetconf('TESTCONF', 'tapetype:scotch:length'), '500',
139 "returns tapetype parameter correctly");
141 ok(grep { $_ eq 'testdump' } split(/\n/, amgetconf('TESTCONF', '--list', 'dumptype')),
142 "--list returns a test dumptype among the default dumptypes");
143 is(amgetconf('TESTCONF', 'dumptype:testdump:comment'), 'testdump-dumptype',
144 "returns dumptype parameter correctly");
146 is_deeply([sort(+split(/\n/, amgetconf('TESTCONF', '--list', 'interface')))],
147 [sort("testiface", "default")],
148 "--list returns correct set of interfaces");
149 is(amgetconf('TESTCONF', 'interface:testiface:use'), '10',
150 "returns interface parameter correctly");
152 is_deeply([sort(+split(/\n/, amgetconf('TESTCONF', '--list', 'holdingdisk')))],
154 "--list returns correct set of holdingdisks");
155 is(amgetconf('TESTCONF', 'holdingdisk:hd17:chunksize'), '128',
156 "returns holdingdisk parameter correctly");
158 # non-existent subsection types, names, and parameters
159 like(amgetconf('TESTCONF', 'NOSUCHTYPE:testiface:comment'), qr/no such parameter/,
160 "handles bad subsection type");
161 like(amgetconf('TESTCONF', 'dumptype:NOSUCHDUMP:comment'), qr/no such parameter/,
162 "handles bad dumptype namek");
163 like(amgetconf('TESTCONF', 'dumptype:testdump:NOSUCHPARAM'), qr/no such parameter/,
164 "handles bad dumptype parameter name");
167 # exclude lists are a bit funny, too
169 $testconf = Amconfig->new();
170 $testconf->add_dumptype("testdump", [
171 "exclude file optional" => '"f1"', # this optional will have no effect
172 "exclude file append" => '"f2"',
173 "exclude list" => '"l1"',
174 "exclude list append" => '"l2"',
175 "include file" => '"ifo"',
176 "include list optional" => '"ilo"',
180 is_deeply([sort(+split(qr/\n/, amgetconf('TESTCONF', 'dumptype:testdump:exclude')))],
181 [sort('FILE "f1" "f2"',
183 "exclude files and lists displayed correctly; a non-final optional is ignored");
185 is_deeply([sort(+split(qr/\n/, amgetconf('TESTCONF', 'dumptype:testdump:include')))],
186 [sort('FILE OPTIONAL "ifo"',
187 'LIST OPTIONAL "ilo"')],
188 "a final 'OPTIONAL' makes the whole include/exclude optional")