summaryrefslogtreecommitdiff
path: root/t/basic.t
blob: ecb1d05a54ba64d2bc3331a53a013e974531212c (plain) (blame)
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
use strict;
use warnings;
use Test::More;
use JSON::XS;
use Test::Exception;
use AnyEvent::Riak;

my $jiak = AnyEvent::Riak->new(
    host => 'http://127.0.0.1:8098',

    #host => 'http://192.168.0.11:8098',
    path => 'jiak'
);

ok my $buckets = $jiak->list_bucket('bar')->recv, "... fetch bucket list";
is scalar @{ $buckets->{keys} }, '0', '... no keys';

ok my $new_bucket
    = $jiak->set_bucket( 'foo', { allowed_fields => '*' } )->recv,
    '... set a new bucket';

my $value = {
    bucket => 'foo',
    key    => 'bar',
    object => { foo => "bar", baz => 1 },
    links  => []
};

ok my $res = $jiak->store($value)->recv, '... set a new key';

ok $res = $jiak->fetch( 'foo', 'bar' )->recv, '... fetch our new key';
ok $res = $jiak->delete( 'foo', 'bar' )->recv, '... delete our key';

dies_ok { $jiak->fetch( 'foo', 'foo' )->recv } '... dies when error';
like $@, qr/404/, '... 404 response';

ok $res = $jiak->store($value)->recv, '... set a new key';
my $second_value = {
    bucket => 'foo',
    key    => 'baz',
    object => { foo => "bar", baz => 2 },
    links  => [ [ 'foo', 'bar', 'tagged' ] ],
};
ok $res = $jiak->store($second_value)->recv, '... set another new key';

ok $res = $jiak->walk( 'foo', 'baz', [ { bucket => 'foo', } ] )->recv,
    '... walk';
is $res->{results}->[0]->[0]->{key}, "bar", "... walked to bar";

done_testing();