plan
skip_all
=>
'set TEST_ONLINE to enable this test'
unless
$ENV
{TEST_ONLINE};
my
$r
= Rethinkdb->new;
isa_ok
$r
,
'Rethinkdb'
;
$r
= r;
isa_ok
$r
,
'Rethinkdb'
;
my
$conn
= r->
connect
;
isa_ok
$conn
,
'Rethinkdb::IO'
;
is
$conn
->host,
'localhost'
;
is
$conn
->port, 28015;
is
$conn
->default_db,
'test'
;
is
$conn
->auth_key,
''
;
is
$conn
->timeout, 20;
eval
{
my
$r
= r->
connect
(
'wiggle'
); } or
do
{
like $@,
qr/ERROR: Could not connect to wiggle:28015/
,
'Correct host connection error message'
;
};
eval
{
my
$r
= r->
connect
(
'localhost'
, 48015 ); } or
do
{
like $@,
qr/ERROR: Could not connect to localhost:48015/
,
'Correct host connection error message'
;
};
$r
= r->
connect
(
'localhost'
, 28015,
'better'
);
isnt
$r
->default_db,
'test'
;
is
$r
->default_db,
'better'
,
'Correct `default_db` set'
;
eval
{ r->
connect
(
'localhost'
, 28015,
'better'
,
'hiddenkey'
); } or
do
{
like $@,
qr/ERROR: Incorrect authorization key./
,
'Correct `auth_key` connection error message'
;
};
my
$r
= r->
connect
(
'localhost'
, 28015,
'better'
,
''
, 100 );
is
$r
->timeout, 100,
'Correct timeout set'
;
eval
{ r->db(
'test'
)->create->run; } or
do
{
like $@,
qr/ERROR: run\(\) was not given a connection/
,
'Correct error on `run` without connection'
;
};
r->
connect
;
is r->io,
undef
;
r->
connect
->repl;
isa_ok r->io,
'Rethinkdb::IO'
;
$conn
= r->
connect
;
isa_ok
$conn
->
close
,
'Rethinkdb::IO'
;
is
$conn
->_handle,
undef
;
$conn
= r->
connect
;
isa_ok
$conn
->
close
(
noreply_wait
=> 0 ),
'Rethinkdb::IO'
;
is
$conn
->_handle,
undef
;
isa_ok
$conn
->reconnect,
'Rethinkdb::IO'
;
isa_ok
$conn
->_handle,
'IO::Socket::INET'
;
is
$conn
->_handle->peerport, 28015;
is
$conn
->_handle->peerhost,
'127.0.0.1'
;
isa_ok
$conn
->reconnect(
noreply_wait
=> 0 ),
'Rethinkdb::IO'
;
isa_ok
$conn
->_handle,
'IO::Socket::INET'
;
is
$conn
->_handle->peerport, 28015;
is
$conn
->_handle->peerhost,
'127.0.0.1'
;
$conn
->
use
(
'test2'
);
is
$conn
->default_db,
'test2'
;
$conn
->
use
(
'wiggle-waggle'
);
is
$conn
->default_db,
'wiggle-waggle'
;
my
$res
=
$conn
->noreply_wait;
is
$res
->type_description,
'wait_complete'
;
$res
= r->db(
'rethinkdb'
)->table(
'logs'
)->nth(0)->run( {
profile
=> r->true } );
isa_ok
$res
->profile,
'ARRAY'
,
'Correctly received profile data'
;
r->db(
'test'
)->drop->run;
r->db(
'test'
)->create->run( {
durability
=>
'soft'
} );
r->db(
'test'
)->table(
'battle'
)->create->run;
r->db(
'test'
)->table(
'battle'
)->insert(
[
{
id
=> 1,
superhero
=>
'Iron Man'
,
target
=>
'Mandarin'
,
damage_dealt
=> 100,
},
{
id
=> 2,
superhero
=>
'Wolverine'
,
target
=>
'Sabretooth'
,
damage_dealt
=> 40,
},
{
id
=> 3,
superhero
=>
'Iron Man'
,
target
=>
'Magneto'
,
damage_dealt
=> 90,
},
{
id
=> 4,
superhero
=>
'Wolverine'
,
target
=>
'Magneto'
,
damage_dealt
=> 10,
},
{
id
=> 5,
superhero
=>
'Spider-Man'
,
target
=>
'Green Goblin'
,
damage_dealt
=> 20,
}
]
)->run;
$res
= r->db(
'test'
)->table(
'battle'
)->group(
'superhero'
)->run( {
group_format
=>
'raw'
} );
is
$res
->response->{
'$reql_type$'
},
'GROUPED_DATA'
,
'Correct group_format response data'
;
isa_ok
$res
->response->{data},
'ARRAY'
,
'Correct group_format response data'
;
isa_ok
$res
->response->{data}[0][1],
'ARRAY'
,
'Correct group_format response data'
;
$res
= r->table(
'cluster_config'
)->run({
db
=>
'rethinkdb'
});
ok (
$res
->response->[0]->{id} eq
'auth'
or
$res
->response->[0]->{id} eq
'heartbeat'
),
'Correct response for db change'
;
r->db(
'test'
)->table(
'battle'
)->run({
array_limit
=> 2});
$res
= r->db(
'test'
)->table(
'battle'
)->run({
noreply
=> 1});
is
$res
,
undef
,
'Correct response for noreply'
;
$res
= r->db(
'test'
)->table(
'battle'
)->run(
sub
{
my
$res
=
shift
;
isa_ok
$res
,
'Rethinkdb::Response'
,
'Correct response for callback'
;
});
isa_ok
$res
,
'Rethinkdb::Response'
,
'Correct response for callback return'
;
r->db(
'test'
)->drop->run;
done_testing();