X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=t%2F05-store.t;h=6e315a3e7315c98ab646028a872c2830f9f75da2;hb=ce3f3727974ab81d7e2928fcb806ff186c364088;hp=fc848d1a7f536f8216f82f901b53817171084315;hpb=de7bd7d0d60b42a12a93ba526d97b7ebaa5dcf2e;p=perl-cwmp.git diff --git a/t/05-store.t b/t/05-store.t index fc848d1..6e315a3 100755 --- a/t/05-store.t +++ b/t/05-store.t @@ -4,7 +4,7 @@ use warnings; my $debug = shift @ARGV; -use Test::More tests => 18; +use Test::More tests => 34; use Data::Dump qw/dump/; use Cwd qw/abs_path/; use lib 'lib'; @@ -12,54 +12,66 @@ use lib 'lib'; BEGIN { use_ok('CWMP::Store'); use_ok('CWMP::Store::DBMDeep'); + use_ok('CWMP::Store::YAML'); } ok(my $abs_path = abs_path($0), "abs_path"); $abs_path =~ s!/[^/]*$!/!; #!fix-vim -my $path = "$abs_path/var/state.db"; +my $path = "$abs_path/var/"; -unlink $path if -e $path; +sub test_store { + my $module = shift; -ok( my $store = CWMP::Store->new({ - debug => $debug, - module => 'DBMDeep', - path => $path, -}), 'new' ); -isa_ok( $store, 'CWMP::Store' ); + diag "testing store plugin $module"; -cmp_ok( $store->path, 'eq', $path, 'path' ); + ok( my $store = CWMP::Store->new({ + debug => $debug, + module => $module, + path => $path, + clean => 1, + }), 'new' ); + isa_ok( $store, 'CWMP::Store' ); -my $state = { - foo => 'bar', - DeviceID => { - SerialNumber => 123456, - }, -}; + cmp_ok( $store->path, 'eq', $path, 'path' ); -cmp_ok( $store->ID_to_uid( 42, $state ), 'eq', 123456, 'ID_to_uid' ); + my $state = { + foo => 'bar', + DeviceID => { + SerialNumber => 123456, + }, + }; -ok( $store->update_state( ID => 42, $state ), 'update_state new' ); + cmp_ok( $store->ID_to_uid( 42, $state ), 'eq', 123456, 'ID_to_uid' ); -ok( my $store_state = $store->state( ID => '42'), 'db->get' ); + ok( $store->update_state( ID => 42, $state ), 'update_state new' ); -is_deeply( $store_state, $state, 'state ID' ); + ok( my $store_state = $store->get_state( ID => '42'), 'get_state ID' ); -ok( $store_state = $store->state( uid => 123456 ), 'db->get' ); + is_deeply( $store_state, $state, 'state ID' ); -is_deeply( $store_state, $state, 'state uid' ); + ok( $store_state = $store->get_state( uid => 123456 ), 'get_state uid' ); -ok( $store->update_state( ID => 42, { baz => 12345 } ), 'update_state existing' ); + is_deeply( $store_state, $state, 'state ID same as uid' ); -$state->{baz} = 12345; + ok( $store->update_state( ID => 42, { baz => 12345 } ), 'update_state existing' ); -is_deeply( $store->state( ID => 42 ), $state, 'store->state ID' ); + $state->{baz} = 12345; -is_deeply( $store->state( uid => 123456 ), $state, 'store->state uid' ); + is_deeply( $store->get_state( ID => 42 ), $state, 'get_state ID' ); -is_deeply( [ $store->known_CPE ], [ 123456 ], 'known_CPE' ); + is_deeply( $store->get_state( uid => 123456 ), $state, 'get_state uid' ); -ok( $store->update_state( ID => 11, { DeviceID => { SerialNumber => 99999 } } ), 'new device' ); + is_deeply( [ $store->all_uids ], [ 123456 ], 'all_uids' ); -is_deeply( [ $store->known_CPE ], [ 123456, 99999 ], 'known_CPE' ); + ok( $store->update_state( ID => 11, { DeviceID => { SerialNumber => 99999 } } ), 'new device' ); + + is_deeply( [ $store->all_uids ], [ 123456, 99999 ], 'all_uids' ); + +} + +# now test all stores + +test_store('DBMDeep'); +test_store('YAML');