Arango-Tango
view release on metacpan or search on metacpan
t/02-collection.t view on Meta::CPAN
# -*- cperl -*-
use Arango::Tango;
use Test2::V0;
use Test2::Tools::Exception qw/dies lives/;
do "./t/helper.pl";
skip_all "No ArangoDB environment variables for testing. See README" unless valid_env_vars();
skip_all "Can't reach ArangoDB Server" unless server_alive();
my $arango = Arango::Tango->new( );
skip_all "Credentials problems" unless auth_ok($arango);
clean_test_environment($arango);
my $db = $arango->create_database("tmp_");
my $test_collections = $db->list_collections;
is ref($test_collections), "ARRAY", "Collection list is still an array";
my $nr_db_collections = scalar(@$test_collections);
my $collection = $db->create_collection("collection");
isa_ok($collection => "Arango::Tango::Collection");
my $same_collection = $db->collection("collection");
isa_ok($collection => "Arango::Tango::Collection");
$test_collections = $db->list_collections;
is scalar(@$test_collections), $nr_db_collections+1;
my $info = $collection->info;
is ($info->{name}, "collection");
my $checksum = $collection->checksum;
ok exists($checksum->{checksum});
is $checksum->{type}, 2;
my $count = $collection->count;
is $count->{count}, 0;
my $figures = $collection->figures;
is $figures->{count}, 0;
my %ttl_idx_opts = (
type => 'ttl',
name => 'idx',
fields => ['t_x'],
expireAfter => 3600
);
my $idx = $db->create_ttl_index("collection", %ttl_idx_opts);
ok !$idx->{error};
is $idx->{type}, 'ttl';
is $idx->{name}, 'idx';
my %persistent_idx_opts = (
type => 'persistent',
name => 'idx_persistent',
fields => ['p_x'],
unique => 1,
sparse => 1,
);
my $idx2 = $db->create_index("collection", %persistent_idx_opts);
ok !$idx2->{error};
is $idx2->{type}, 'persistent';
is $idx2->{name}, 'idx_persistent';
ok $idx2->{unique};
ok $idx2->{sparse};
( run in 2.316 seconds using v1.01-cache-2.11-cpan-14f38c9f855 )