1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
|
|
3 |
use strict; |
use strict; |
|
use Test::More tests => 8; |
|
|
use Test::Exception; |
|
4 |
use blib; |
use blib; |
5 |
|
|
6 |
use Data::Dump qw/dump/; |
use Test::More tests => 28; |
|
use Cwd qw/abs_path/; |
|
7 |
|
|
8 |
BEGIN { |
BEGIN { |
9 |
|
use_ok( 'WebPAC::Test' ); |
10 |
use_ok( 'WebPAC::Config' ); |
use_ok( 'WebPAC::Config' ); |
11 |
} |
} |
12 |
|
|
|
my $debug = shift @ARGV; |
|
|
|
|
|
ok(my $abs_path = abs_path($0), "abs_path"); |
|
|
$abs_path =~ s#/[^/]*$#/#; |
|
|
|
|
13 |
my $path = "$abs_path/conf/test.yml"; |
my $path = "$abs_path/conf/test.yml"; |
14 |
|
|
15 |
ok(my $c = new WebPAC::Config( path => $path ), "new"); |
ok(my $config = new WebPAC::Config( path => $path ), "new"); |
|
|
|
|
cmp_ok($c->{path}, 'eq', $path, "path $path"); |
|
16 |
|
|
17 |
ok($c->{config}, "config exist"); |
cmp_ok($config->{path}, 'eq', $path, "path $path"); |
18 |
|
|
19 |
isa_ok($c->databases, 'HASH', "databases"); |
ok($config->{config}, "config exist"); |
20 |
|
|
21 |
my @names = $c->databases; |
# $config->databases |
22 |
|
|
23 |
|
isa_ok($config->databases, 'HASH', "databases"); |
24 |
|
my @names = $config->databases; |
25 |
isa_ok(\@names, 'ARRAY', "databases names"); |
isa_ok(\@names, 'ARRAY', "databases names"); |
|
|
|
26 |
cmp_ok(@names, '==', 3, "got 3 names"); |
cmp_ok(@names, '==', 3, "got 3 names"); |
27 |
|
isa_ok($config->databases, 'HASH', "databases"); |
28 |
|
|
29 |
|
diag '$config->webpac = ', dump($config->webpac) if ($debug); |
30 |
|
|
31 |
|
isa_ok($config->webpac, 'HASH', "webpac"); |
32 |
|
my @inputs = $config->webpac('inputs'); |
33 |
|
diag "inputs = ",dump( @inputs ) if ($debug); |
34 |
|
isa_ok(\@inputs, 'ARRAY', "inputs"); |
35 |
|
cmp_ok(@inputs, '==', 2, "got 2 webpac inputs"); |
36 |
|
|
37 |
|
$config->iterate_inputs(sub { |
38 |
|
my ($input,$database,$db_config) = @_; |
39 |
|
isa_ok($input, 'HASH', 'input'); |
40 |
|
ok($database, 'database'); |
41 |
|
isa_ok($db_config, 'HASH', 'database config'); |
42 |
|
isa_ok($input->{normalize}, 'ARRAY', 'normalize'); |
43 |
|
}); |