#!/usr/bin/perl

# Copryight (C) 2007  Joshua Hoblitt
#
# $Id: 13_server_rename_object.t,v 1.5 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;

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

    $neb->rename_object("foo", "bar");

    eval {
        $neb->find_objects('^foo$');
    };
    like($@, qr/no keys found/, "old key name");

    my $keys = $neb->find_objects('^bar$');
    is(scalar @$keys, 1, 'number of keys found');
}

Test::Nebulous->setup;

# destination key exists
eval {
    $neb->create_object('foo');
    $neb->create_object('bar');

    $neb->rename_object('foo', 'bar');
};
like($@, qr/is not valid object key/, "too few params");

Test::Nebulous->setup;

eval {
    $neb->rename_object();
};
like($@, qr/2 were expected/, "no params");

Test::Nebulous->setup;

eval {
    $neb->create_object("foo");

    $neb->rename_object("foo");
};
like($@, qr/2 were expected/, "too few params");

Test::Nebulous->setup;

eval {
    $neb->create_object("foo");

    $neb->rename_object("foo", "bar", "baz");
};
like($@, qr/2 were expected/, "too many params");

Test::Nebulous->cleanup;
