#!/usr/bin/perl

# Copryight (C) 2004-2005  Joshua Hoblitt
#
# $Id: 12_server_find_objects.t,v 1.4 2008-05-16 20:29:19 jhoblitt Exp $

use strict;
use warnings FATAL => qw( all );

use Test::More tests => 6;

use lib qw( ./t ./lib );

use Nebulous::Server;
use Test::Nebulous;

my $neb = Nebulous::Server->new(
    dsn         => $NEB_DB,
    dbuser      => $NEB_USER,
    dbpasswd    => $NEB_PASS,
);

Test::Nebulous->setup;

# search for a regex of '' should match nothing
eval {
    # key
    my $uri = $neb->create_object("foo");

    my $keys = $neb->find_objects();
};
like($@, qr/no keys found/, "no keys found");

Test::Nebulous->setup;

{
    # key
    my $uri = $neb->create_object("foo");

    my $keys = $neb->find_objects("foo");

    is(scalar @$keys, 1, 'number of keys found');
    is($keys->[0], "foo", "key name");
}

Test::Nebulous->setup;

{
    # key
    my $uri1 = $neb->create_object("foo");
    my $uri2 = $neb->replicate_object("foo");

    my $keys = $neb->find_objects("foo");

    is(scalar @$keys, 1, 'number of keys found');
    is($keys->[0], "foo", "key name");
}

Test::Nebulous->setup;

eval {
    $neb->find_objects("foo", 3);
};
like($@, qr/1 was expected/, "too many params");

Test::Nebulous->cleanup;
