File: Catmandu-Store-Multi.t

package info (click to toggle)
libcatmandu-perl 1.2024-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,552 kB
  • sloc: perl: 17,037; makefile: 24; sh: 1
file content (53 lines) | stat: -rw-r--r-- 1,258 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env perl

use strict;
use warnings;
use Test::More;
use Test::Exception;
use Catmandu::Store::Hash;
use utf8;

my $pkg;

BEGIN {
    $pkg = 'Catmandu::Store::Multi';
    use_ok $pkg;
}
require_ok $pkg;

my $data = [
    {_id => '123', name => 'Patrick', age => '39'},
    {_id => '321', name => 'Nicolas', age => '34'},
];

note("Hash stores");
{
    my $stores = [Catmandu::Store::Hash->new, Catmandu::Store::Hash->new,];
    my $store  = $pkg->new(stores => $stores);
    my $bag    = $store->bag;

    $bag->add_many($data);
    is_deeply $bag->to_array,              $data;
    is_deeply $stores->[0]->bag->to_array, $data;
    is_deeply $stores->[1]->bag->to_array, $data;

    is_deeply $bag->get('123'),              $data->[0];
    is_deeply $stores->[0]->bag->get('123'), $data->[0];
    is_deeply $stores->[1]->bag->get('123'), $data->[0];

    $bag->delete('123');
    is_deeply $bag->first,              $data->[1];
    is_deeply $stores->[0]->bag->first, $data->[1];
    is_deeply $stores->[1]->bag->first, $data->[1];

    $bag->delete_all;
    is $bag->count,              0;
    is $stores->[0]->bag->count, 0;
    is $stores->[1]->bag->count, 0;

    $bag->add_many($data);
    $bag->drop;
    is $bag->count, 0;
}

done_testing;