equal
deleted
inserted
replaced
|
1 #! /usr/bin/perl |
|
2 |
|
3 use strict; |
|
4 use warnings; |
|
5 use Test::More; |
|
6 use Pod::Coverage; |
|
7 use File::Temp; |
|
8 |
|
9 BEGIN { |
|
10 use_ok "DNStools::Config" => qw(get_config); |
|
11 } |
|
12 |
|
13 can_ok("DNStools::Config" => "get_config"); |
|
14 |
|
15 eval { get_config("xxx|xxx", "yyy|yyy") }; |
|
16 ok($@, "dies on missing config"); |
|
17 |
|
18 my ($tmp, %cf); |
|
19 |
|
20 # prepare some simple sample config |
|
21 $tmp = File::Temp->new(); |
|
22 print {$tmp} <<__EOF; |
|
23 # comment |
|
24 abc = xyz |
|
25 other = value with space |
|
26 __EOF |
|
27 close($tmp); |
|
28 |
|
29 # the files is specified, it should find the first |
|
30 # existing |
|
31 %cf = get_config("xxx|xxx", $tmp->filename); |
|
32 ok(%cf, "got config"); |
|
33 is($cf{abc} => "xyz", "simple value"); |
|
34 is($cf{other} => "valuewithspace", "spaced value"); |
|
35 |
|
36 # it should find the file specified in $ENV{DNSTOOLS_CONF} |
|
37 $ENV{DNSTOOLS_CONF} = $tmp->filename; |
|
38 %cf = (); |
|
39 %cf = get_config("xxx|xxx", $tmp->filename); |
|
40 ok(%cf, "got config from \$DNSTOOLS_CONF"); |
|
41 is($cf{abc} => "xyz", "simple value"); |
|
42 is($cf{other} => "valuewithspace", "spaced value"); |
|
43 |
|
44 |
|
45 done_testing(); |