#!/usr/bin/perl

# Copryight (C) 2004-2005  Joshua Hoblitt
#
# $Id: 59_client_delete.t,v 1.2 2008-08-01 23:55:26 jhoblitt Exp $

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

use Apache::Test qw( -withtestmore );

plan tests => 9;

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

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

my $hostport = Apache::Test->config->{ 'hostport' };

Test::Nebulous->setup;

{
    my $neb = Nebulous::Client->new(
        proxy => "http://$hostport/nebulous",
    );
    $neb->create( "foo" );

    ok( $neb->delete( "foo" ), "delete object" );

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

    is( $locations, undef, "no instances" );
}

Test::Nebulous->setup;

{
    my $neb = Nebulous::Client->new(
        proxy => "http://$hostport/nebulous",
    );
    $neb->create( "foo" );
    $neb->replicate( "foo" );

    ok( $neb->delete( "foo" ), "delete object" );

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

    is( $locations, undef, "no instances" );
}

Test::Nebulous->setup;

{
    my $neb = Nebulous::Client->new(
        proxy => "http://$hostport/nebulous",
    );
    $neb->create( "neb://node01/foo" );

    ok( $neb->delete( "neb://node02/foo" ), "delete object" );

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

    is( $locations, undef, "no instances" );
}

Test::Nebulous->setup;

{
    my $neb = Nebulous::Client->new(
        proxy => "http://$hostport/nebulous",
    );

    is( $neb->delete( "foo" ), undef, "delete non-existant object" );
}

Test::Nebulous->setup;

eval {
    my $neb = Nebulous::Client->new(
        proxy => "http://$hostport/nebulous",
    );
    $neb->delete();
};
like( $@, qr/1 was expected/, "no params" );

Test::Nebulous->setup;

eval {
    my $neb = Nebulous::Client->new(
        proxy => "http://$hostport/nebulous",
    );
    $neb->delete( "foo", 2 );
};
like( $@, qr/1 was expected/, "too many params" );

Test::Nebulous->cleanup;
