summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-04-11 13:55:19 +0200
committerfranck cuny <franck@lumberjaph.net>2010-04-11 13:55:19 +0200
commit4486ced0ea05414c93703847f6818f4797b92a7a (patch)
tree54d401e8c04d6f41bcedf31c8f17011d33a8f401
parentremove some code; use _build_headers, fix POST and DELETE (diff)
downloadanyevent-riak-4486ced0ea05414c93703847f6818f4797b92a7a.tar.gz
more tests
-rw-r--r--t/basic.t74
1 files changed, 45 insertions, 29 deletions
diff --git a/t/basic.t b/t/basic.t
index 102bbab..ec7d3bd 100644
--- a/t/basic.t
+++ b/t/basic.t
@@ -5,8 +5,9 @@ use Test::More;
 use JSON::XS;
 use Test::Exception;
 use AnyEvent::Riak;
+use YAML::Syck;
 
-plan tests => 12;
+#plan tests => 15;
 
 my ( $host, $path );
 
@@ -18,13 +19,14 @@ BEGIN {
         unless ( $host && $path );
 }
 
-ok my $riak = AnyEvent::Riak->new( host => $host, path => $path ),
+ok my $riak = AnyEvent::Riak->new( host => $host, path => $path, w => 1,
+    dw => 1),
     'create riak object';
 
 # ping
 ok my $ping_one = $riak->is_alive(
     sub {
-        pass "is alive";
+        pass "is alive in cb";
 	return $_[0];
     }
 ), 'ping with callback';
@@ -38,9 +40,11 @@ is $s, 'OK', 'valid response from ping';
 # list bucket
 ok my $bucket_cb = $riak->list_bucket(
     'bar',
+    {},
     sub {
-        my $res = JSON::decode_json(shift);
-        is scalar $res->{keys}, '0', 'no keys';
+    	my $stuff = shift;
+        my $res = JSON::decode_json($stuff);
+        is scalar @{$res->{keys}}, 0, '0 keys in cb';
     }
     ),
     'fetch bucket list';
@@ -48,39 +52,51 @@ ok my $bucket_cb = $riak->list_bucket(
 ok my $buckets = $riak->list_bucket('bar')->recv, "fetch bucket list";
 is scalar @{ $buckets->{keys} }, '0', 'no keys';
 
-$bucket_cb->recv;
+ok my $res_bucket = $bucket_cb->recv, 'get bucket';
 
 # set bucket
 ok my $new_bucket
-    = $riak->set_bucket( 'foo', { props => { n_val => 2 } } )->recv,
-    'set a new bucket';
+     = $riak->set_bucket( 'foo', { props => { n_val => 2 } } )->recv,
+     'set a new bucket';
 
 my $value = {
-    bucket => 'foo',
-    key    => 'bar3',
-    object => { foo => "bar", baz => 1 },
-    links  => []
+   foo => 'bar',
 };
 
-ok my $res = $riak->store($value)->recv, '... set a new key';
+ok my $res = $riak->store('foo', 'bar', $value)->recv, 'set a new key';
 
-ok $res = $riak->fetch( 'foo', 'bar' )->recv, '... fetch our new key';
-# #ok $res = $riak->delete( 'foo', 'bar' )->recv, '... delete our key';
+ok $res = $riak->fetch( 'foo', 'bar' )->recv, 'fetch our new key';
+is_deeply $res, $value, 'value is ok';
+ok $res = $riak->delete( 'foo', 'bar' )->recv, 'delete our key';
 
-# #dies_ok { $riak->fetch( 'foo', 'foo' )->recv } '... dies when error';
-# #like $@, qr/404/, '... 404 response';
+ok my $store_w_cb = $riak->store(
+    'foo', 'bar3', $value, undef, undef,
+    sub {
+        pass "store value ok";
+        $riak->fetch(
+            'foo', 'bar3', undef,
+            sub {
+                my $body = shift;
+		is_deeply (JSON::decode_json($body), $value, 'value is ok in cb');
+            }
+        );
+    }
+);
+
+ok my $final_res = $store_w_cb->recv;
+$final_res->recv; # FIXME all cb should be called at this point
 
-# #ok $res = $riak->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 = $riak->store($second_value)->recv, '... set another new key';
+# ok $res = $riak->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 = $riak->store($second_value)->recv, '... set another new key';
 
-# #ok $res = $riak->walk( 'foo', 'baz', [ { bucket => 'foo', } ] )->recv,
-#     #'... walk';
-# #is $res->{results}->[0]->[0]->{key}, "bar", "... walked to bar";
+# ok $res = $riak->walk( 'foo', 'baz', [ { bucket => 'foo', } ] )->recv,
+#     '... walk';
+# is $res->{results}->[0]->[0]->{key}, "bar", "... walked to bar";
 
-# done_testing();
+done_testing();