4 |
|
|
5 |
my $debug = shift @ARGV; |
my $debug = shift @ARGV; |
6 |
|
|
7 |
use Test::More tests => 18; |
use Test::More tests => 34; |
8 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
9 |
use Cwd qw/abs_path/; |
use Cwd qw/abs_path/; |
10 |
use lib 'lib'; |
use lib 'lib'; |
12 |
BEGIN { |
BEGIN { |
13 |
use_ok('CWMP::Store'); |
use_ok('CWMP::Store'); |
14 |
use_ok('CWMP::Store::DBMDeep'); |
use_ok('CWMP::Store::DBMDeep'); |
15 |
|
use_ok('CWMP::Store::YAML'); |
16 |
} |
} |
17 |
|
|
18 |
ok(my $abs_path = abs_path($0), "abs_path"); |
ok(my $abs_path = abs_path($0), "abs_path"); |
20 |
|
|
21 |
my $path = "$abs_path/var/"; |
my $path = "$abs_path/var/"; |
22 |
|
|
23 |
unlink $path if -e $path; |
sub test_store { |
24 |
|
my $module = shift; |
25 |
|
|
26 |
ok( my $store = CWMP::Store->new({ |
diag "testing store plugin $module"; |
|
debug => $debug, |
|
|
# module => 'DBMDeep', |
|
|
module => 'YAML', |
|
|
path => $path, |
|
|
}), 'new' ); |
|
|
isa_ok( $store, 'CWMP::Store' ); |
|
27 |
|
|
28 |
cmp_ok( $store->path, 'eq', $path, 'path' ); |
ok( my $store = CWMP::Store->new({ |
29 |
|
debug => $debug, |
30 |
|
module => $module, |
31 |
|
path => $path, |
32 |
|
clean => 1, |
33 |
|
}), 'new' ); |
34 |
|
isa_ok( $store, 'CWMP::Store' ); |
35 |
|
|
36 |
my $state = { |
cmp_ok( $store->path, 'eq', $path, 'path' ); |
|
foo => 'bar', |
|
|
DeviceID => { |
|
|
SerialNumber => 123456, |
|
|
}, |
|
|
}; |
|
37 |
|
|
38 |
cmp_ok( $store->ID_to_uid( 42, $state ), 'eq', 123456, 'ID_to_uid' ); |
my $state = { |
39 |
|
foo => 'bar', |
40 |
|
DeviceID => { |
41 |
|
SerialNumber => 123456, |
42 |
|
}, |
43 |
|
}; |
44 |
|
|
45 |
ok( $store->update_state( ID => 42, $state ), 'update_state new' ); |
cmp_ok( $store->ID_to_uid( 42, $state ), 'eq', 123456, 'ID_to_uid' ); |
46 |
|
|
47 |
ok( my $store_state = $store->state( ID => '42'), 'db->get' ); |
ok( $store->update_state( ID => 42, $state ), 'update_state new' ); |
48 |
|
|
49 |
is_deeply( $store_state, $state, 'state ID' ); |
ok( my $store_state = $store->get_state( ID => '42'), 'get_state ID' ); |
50 |
|
|
51 |
ok( $store_state = $store->state( uid => 123456 ), 'db->get' ); |
is_deeply( $store_state, $state, 'state ID' ); |
52 |
|
|
53 |
is_deeply( $store_state, $state, 'state uid' ); |
ok( $store_state = $store->get_state( uid => 123456 ), 'get_state uid' ); |
54 |
|
|
55 |
ok( $store->update_state( ID => 42, { baz => 12345 } ), 'update_state existing' ); |
is_deeply( $store_state, $state, 'state ID same as uid' ); |
56 |
|
|
57 |
$state->{baz} = 12345; |
ok( $store->update_state( ID => 42, { baz => 12345 } ), 'update_state existing' ); |
58 |
|
|
59 |
is_deeply( $store->state( ID => 42 ), $state, 'store->state ID' ); |
$state->{baz} = 12345; |
60 |
|
|
61 |
is_deeply( $store->state( uid => 123456 ), $state, 'store->state uid' ); |
is_deeply( $store->get_state( ID => 42 ), $state, 'get_state ID' ); |
62 |
|
|
63 |
is_deeply( [ $store->known_CPE ], [ 123456 ], 'known_CPE' ); |
is_deeply( $store->get_state( uid => 123456 ), $state, 'get_state uid' ); |
64 |
|
|
65 |
ok( $store->update_state( ID => 11, { DeviceID => { SerialNumber => 99999 } } ), 'new device' ); |
is_deeply( [ $store->all_uids ], [ 123456 ], 'all_uids' ); |
66 |
|
|
67 |
is_deeply( [ $store->known_CPE ], [ 123456, 99999 ], 'known_CPE' ); |
ok( $store->update_state( ID => 11, { DeviceID => { SerialNumber => 99999 } } ), 'new device' ); |
68 |
|
|
69 |
|
is_deeply( [ $store->all_uids ], [ 123456, 99999 ], 'all_uids' ); |
70 |
|
|
71 |
|
} |
72 |
|
|
73 |
|
# now test all stores |
74 |
|
|
75 |
|
test_store('DBMDeep'); |
76 |
|
test_store('YAML'); |
77 |
|
|