#!/usr/bin/perl

use strict;
use warnings;

use Test::More tests => 8;

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

use PS::IPP::IData::Server;
use PS::IPP::IData::Util qw( :standard );
use Test::IData;

my $idata = "PS::IPP::IData::Server";

$idata->setup(
    "DBI:mysql:database=test:host=localhost",
    "test",
    "",
);

Test::IData->setup;

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

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

Test::IData->setup;

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

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

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

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

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

    eval {
        $idata->find_instances( "foo" );
    };
    like( $@, qr/no instances found/, "storage object was deleted" );
}

Test::IData->setup;

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

Test::IData->setup;

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

Test::IData->setup;

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

Test::IData->cleanup;
