#!/usr/bin/perl

# Copryight (C) 2004-2005  Joshua Hoblitt
#
# $Id: 08_server_delete_instance.t,v 1.10 2008-03-20 21:10:14 jhoblitt Exp $

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

use Test::More tests => 8;

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");

    ok($neb->delete_instance($uri), "delete instance");
}

Test::Nebulous->setup;

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

    ok($neb->delete_instance($uri1), "delete instance");

    my $locations = $neb->find_instances("foo");

    is($locations->[0], $uri2, "instance remains");

    ok($neb->delete_instance( $uri2 ), "delete instance");

    eval {
        $neb->find_instances("foo");
    };
    like($@, qr/is valid object key/, "storage object was deleted");
}

Test::Nebulous->setup;

eval {
    $neb->delete_instance("file:/foo");
};
like($@, qr/no instance is associated with uri/, "uri does not exist");

Test::Nebulous->setup;

eval {
    $neb->delete_instance();
};
like($@, qr/1 was expected/, "no params");

Test::Nebulous->setup;

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

Test::Nebulous->cleanup;
