ArangoDB

 view release on metacpan or  search on metacpan

t/02_collection.t  view on Meta::CPAN

use strict;
use Test::More;
use Test::Fatal qw(lives_ok dies_ok exception);
use Test::Mock::Guard;
use ArangoDB;
use JSON;

if ( !$ENV{TEST_ARANGODB_PORT} ) {
    plan skip_all => 'Can"t find port of arangod';
}

my $port   = $ENV{TEST_ARANGODB_PORT};
my $config = {
    host       => 'localhost',
    port       => $port,
    keep_alive => 1,
};

sub init {
    my $db = ArangoDB->new($config);
    map { $_->drop } @{ $db->collections };
}

subtest 'create collection' => sub {
    init();
    my $db = ArangoDB->new($config);
    my $coll;
    lives_ok { $coll = $db->create("foo"); } 'Create new collection';
    isa_ok $coll, 'ArangoDB::Collection';
    is $coll->name, 'foo';
    ok $coll->is_loaded;
    ok !$coll->is_newborn;
    ok !$coll->is_unloaded;
    ok !$coll->is_being_unloaded;
    ok !$coll->is_deleted;
    ok !$coll->is_corrupted;

    like exception {
        my $guard = mock_guard( 'ArangoDB::Connection' => { http_post => sub {die}, } );
        $db->create('bar');
    }, qr/^Failed to create collection/;

    like exception {
        $db->create('foo');
    }, qr/^Failed to create collection/;

    $db->collection('baz');
};

subtest 'get collection' => sub {
    init();
    my $db = ArangoDB->new($config);

    $db->('foo');
    $db->('baz');

    my $coll = $db->find('bar');
    is $coll, undef, 'Returns undef if the collection does not exist.';

    $coll = $db->find('foo');
    isa_ok $coll, 'ArangoDB::Collection';

    like exception {



( run in 1.024 second using v1.01-cache-2.11-cpan-54e63673c56 )