1 |
#!/usr/bin/perl |
2 |
use strict; |
3 |
use warnings; |
4 |
|
5 |
my $debug = shift @ARGV; |
6 |
|
7 |
use Test::More tests => 32; |
8 |
use Data::Dump qw/dump/; |
9 |
use Cwd qw/abs_path/; |
10 |
use lib 'lib'; |
11 |
|
12 |
BEGIN { |
13 |
use_ok('CWMP::Store'); |
14 |
use_ok('CWMP::Store::DBMDeep'); |
15 |
use_ok('CWMP::Store::YAML'); |
16 |
} |
17 |
|
18 |
ok(my $abs_path = abs_path($0), "abs_path"); |
19 |
$abs_path =~ s!/[^/]*$!/!; #!fix-vim |
20 |
|
21 |
my $path = "$abs_path/var/"; |
22 |
|
23 |
sub test_store { |
24 |
my $module = shift; |
25 |
|
26 |
diag "testing store plugin $module"; |
27 |
|
28 |
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 |
cmp_ok( $store->path, 'eq', $path, 'path' ); |
37 |
|
38 |
my $state = { |
39 |
foo => 'bar', |
40 |
DeviceID => { |
41 |
SerialNumber => 123456, |
42 |
}, |
43 |
}; |
44 |
|
45 |
cmp_ok( $store->state_to_uid( $state ), 'eq', 123456, 'state_to_uid' ); |
46 |
|
47 |
ok( $store->update_state( $state ), 'update_state new' ); |
48 |
|
49 |
ok( my $store_state = $store->get_state( 123456 ), 'get_state' ); |
50 |
|
51 |
isa_ok( $state, 'HASH' ); |
52 |
isa_ok( $store_state, 'HASH' ); |
53 |
|
54 |
if ( $debug ) { |
55 |
|
56 |
diag "store_state = ",dump( $store_state ); |
57 |
|
58 |
} |
59 |
|
60 |
is_deeply( $state, $store_state, 'state ID same as uid' ); |
61 |
|
62 |
ok( $store->update_state( { |
63 |
DeviceID => { |
64 |
SerialNumber => 123456, |
65 |
}, |
66 |
baz => 12345 |
67 |
} ), 'update_state existing' ); |
68 |
|
69 |
$state->{baz} = 12345; |
70 |
|
71 |
is_deeply( $store->get_state( 123456 ), $state, 'get_state' ); |
72 |
|
73 |
is_deeply( [ $store->all_uids ], [ 123456 ], 'all_uids' ); |
74 |
|
75 |
ok( $store->update_state( { DeviceID => { SerialNumber => 99999 } } ), 'new device' ); |
76 |
|
77 |
is_deeply( [ $store->all_uids ], [ 123456, 99999 ], 'all_uids' ); |
78 |
|
79 |
} |
80 |
|
81 |
# now test all stores |
82 |
|
83 |
test_store('DBMDeep'); |
84 |
test_store('YAML'); |
85 |
|