4 |
|
|
5 |
my $debug = shift @ARGV; |
my $debug = shift @ARGV; |
6 |
|
|
7 |
use Test::More tests => 34; |
use Test::More tests => 32; |
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'; |
42 |
}, |
}, |
43 |
}; |
}; |
44 |
|
|
45 |
cmp_ok( $store->ID_to_uid( 42, $state ), 'eq', 123456, 'ID_to_uid' ); |
cmp_ok( $store->state_to_uid( $state ), 'eq', 123456, 'state_to_uid' ); |
46 |
|
|
47 |
ok( $store->update_state( ID => 42, $state ), 'update_state new' ); |
ok( $store->update_state( $state ), 'update_state new' ); |
48 |
|
|
49 |
ok( my $store_state = $store->get_state( ID => '42'), 'get_state ID' ); |
ok( my $store_state = $store->get_state( 123456 ), 'get_state' ); |
50 |
|
|
51 |
is_deeply( $store_state, $state, 'state ID' ); |
isa_ok( $state, 'HASH' ); |
52 |
|
isa_ok( $store_state, 'HASH' ); |
53 |
|
|
54 |
ok( $store_state = $store->get_state( uid => 123456 ), 'get_state uid' ); |
if ( $debug ) { |
55 |
|
|
56 |
is_deeply( $store_state, $state, 'state ID same as uid' ); |
diag "store_state = ",dump( $store_state ); |
57 |
|
|
58 |
|
} |
59 |
|
|
60 |
ok( $store->update_state( ID => 42, { baz => 12345 } ), 'update_state existing' ); |
is_deeply( $state, $store_state, 'state ID same as uid' ); |
61 |
|
|
62 |
$state->{baz} = 12345; |
ok( $store->update_state( { |
63 |
|
DeviceID => { |
64 |
|
SerialNumber => 123456, |
65 |
|
}, |
66 |
|
baz => 12345 |
67 |
|
} ), 'update_state existing' ); |
68 |
|
|
69 |
is_deeply( $store->get_state( ID => 42 ), $state, 'get_state ID' ); |
$state->{baz} = 12345; |
70 |
|
|
71 |
is_deeply( $store->get_state( uid => 123456 ), $state, 'get_state uid' ); |
is_deeply( $store->get_state( 123456 ), $state, 'get_state' ); |
72 |
|
|
73 |
is_deeply( [ $store->all_uids ], [ 123456 ], 'all_uids' ); |
is_deeply( [ $store->all_uids ], [ 123456 ], 'all_uids' ); |
74 |
|
|
75 |
ok( $store->update_state( ID => 11, { DeviceID => { SerialNumber => 99999 } } ), 'new device' ); |
ok( $store->update_state( { DeviceID => { SerialNumber => 99999 } } ), 'new device' ); |
76 |
|
|
77 |
is_deeply( [ $store->all_uids ], [ 123456, 99999 ], 'all_uids' ); |
is_deeply( [ $store->all_uids ], [ 123456, 99999 ], 'all_uids' ); |
78 |
|
|