#!/usr/bin/perl

# Copryight (C) 2004-2005  Joshua Hoblitt
#
# $Id: 12_server_find_objects.t,v 1.1 2007-04-26 23:45:03 jhoblitt Exp $

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

use Test::More tests => 6;

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

use Nebulous::Server;
use Nebulous::Util qw( :standard );
use Test::Nebulous;

my $neb = Nebulous::Server->new(
    dsn         => "DBI:mysql:database=test:host=localhost",
    dbuser      => "test",
    dbpasswd    => "",
);

Test::Nebulous->setup;

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

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

    is(scalar @$keys, 0, 'number of 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;
