Skip to content

Commit

Permalink
adding more tests related to connections and global optargs
Browse files Browse the repository at this point in the history
  • Loading branch information
njlg committed Sep 18, 2015
1 parent 3e76190 commit 8a5890e
Showing 1 changed file with 87 additions and 15 deletions.
102 changes: 87 additions & 15 deletions t/connect.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,28 @@ is $conn->auth_key, '';
is $conn->timeout, 20;

# other values for connect
TODO: {
todo_skip 'Need to make testable', 9;
eval { my $r = r->connect('wiggle'); } or do {
like $@, qr/ERROR: Could not connect to wiggle:28015/,
'Correct host connection error message';
};

$r = r->connect('wiggle');
isnt $r->host, 'localhost';
is $r->port, 28015;
is $r->default_db, 'test';
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( 'wiggle', 48015 );
isnt $r->host, 'localhost';
isnt $r->port, 28015;
is $r->default_db, 'test';
$r = r->connect( 'localhost', 28015, 'better' );
isnt $r->default_db, 'test';
is $r->default_db, 'better', 'Correct `default_db` set';

$r = r->connect( 'wiggle', 48015, 'best' );
isnt $r->host, 'localhost';
isnt $r->port, 28015;
isnt $r->default_db, 'test';
}
# test auth_key
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';

# internal stuff
r->connect;
Expand Down Expand Up @@ -80,4 +84,72 @@ is $conn->default_db, 'wiggle-waggle';
my $res = $conn->noreply_wait;
is $res->type_description, 'wait_complete';

# testing run parameters

# profile
$res
= r->db('rethinkdb')->table('logs')->nth(0)->run( { profile => r->true } );
isa_ok $res->profile, 'ARRAY', 'Correctly received profile data';

# durability (no real way to test the output)
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;

# group_format
$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';

# db
$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';

# array_limit (doesn't seem to change response)
r->db('test')->table('battle')->run({array_limit => 2});

# noreply
$res = r->db('test')->table('battle')->run({noreply => 1});
is $res, undef, 'Correct response for noreply';

# clean up
r->db('test')->drop->run;

done_testing();

0 comments on commit 8a5890e

Please sign in to comment.