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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
use lib 't/lib';
use Test::More;
use Test::Riak;
test_riak {
my ($client, $bucket_name) = @_;
my $content = '{ "dummy":"content"}';
ok my $bucket = $client->bucket($bucket_name),
'created bucket object ok';
{
ok my $obj = $bucket->new_object('metaobj', $content),
'created a new riak object to hold our metadata';
ok $obj->set_meta( mymeta => 'metavalue'),
'... and can add metadata to it';
ok my $meta_value = $obj->get_meta('mymeta'),
'... and can retrieve our metadata from the object';
is $meta_value, 'metavalue',
'... and metadata has correct value';
# setting meta overwrites the value; no support for multivalue headers
ok $obj->set_meta( mymeta => 'newvalue' ),
'... and can update the metadata';
ok $meta_value = $obj->get_meta('mymeta'),
'... and can retrieve new metadata from the object';
is $meta_value, 'newvalue',
'... and metadata has new value';
ok $obj->store,
'... and our object with metadata can be stored ok';
}
{
ok my $obj = $bucket->get('metaobj'),
'Can retrieve object';
is $obj->has_meta, 1,
'... and object says it has one piece of metadata';
ok my $meta_value = $obj->get_meta('mymeta'),
'... and can retrieve our metadata from the object';
is $meta_value, 'newvalue',
'... and metadata has expected value';
ok $obj->set_meta( meta2 => 'metavalue2' ),
'Can add a second meta';
is $obj->has_meta, 2,
'... and meta counter is incremented';
ok $obj->store,
"... and object can be stored again";
}
{
my $obj = $bucket->get('metaobj');
is $obj->has_meta, 2,
'Object says it now has two pieces of metadata';
ok $obj->get_meta('meta2'),
"... and second meta can be accessed";
is $obj->get_meta('meta2'), 'metavalue2',
'... and has expected value';
my $expected = {'meta2' => 'metavalue2', 'mymeta' => 'newvalue' };
is_deeply {$obj->all_meta}, $expected,
"... and all_meta gives us both metas in a hash";
ok $obj->remove_meta('meta2'),
'Can remove an individual meta';
is $obj->has_meta, 1,
'... and meta counter is decremented';
ok !$obj->remove_meta('meta2'),
'Double-removing the now-non-existant item returns false';
is $obj->has_meta, 1,
'... and meta counter is not decremented';
ok $obj->store,
"... and object can be stored again";
}
{
my $obj = $bucket->get('metaobj');
ok !$obj->get_meta('meta2'),
"Deleted meta is no longer available";
is $obj->get_meta('mymeta'), 'newvalue',
'... but non-deleted meta is still present';
}
# cannot add undef values via set_meta
{
my $obj = $bucket->get('metaobj');
eval {
$obj->set_meta( meta3 => undef )
};
like $@, qr/Validation failed for 'Str' with value undef/,
"Cannot add meta with undef value";
is $obj->has_meta, 1,
'... and meta counter is unchanged by trying to add invalid data';
}
my $obj = $bucket->get('metaobj');
$obj->delete; # teardown
};
|