#!/usr/bin/perl

use strict;
use warnings;

use Apache::Test qw( -withtestmore );

plan tests => 7;

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

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

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

Test::IData->setup;

SKIP: {
    skip "need to write a module to validate URIs", 7;

{
    # key
    my $idata = PS::IPP::IData::Client->new(
        proxy => "http://$hostport/idata",
    );
    my $uri = $idata->create( "foo" );

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

    is( $uri, @$locations[0], "URIs match" );
}

Test::IData->setup;

{
    # key
    my $idata = PS::IPP::IData::Client->new(
        proxy => "http://$hostport/idata",
    );
    my $uri1 = $idata->create( "foo" );
    my $uri2 = $idata->replicate( "foo" );

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

    ok( eq_set( [$uri1, $uri2], $locations ), "URIs match" );
}

Test::IData->setup;

{
    # key, volume
    my $idata = PS::IPP::IData::Client->new(
        proxy => "http://$hostport/idata",
    );
    my $uri = $idata->create( "foo" );

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

    is( $uri, $locations->[0], "URIs match" );
}

Test::IData->setup;

{
    # key
    my $idata = PS::IPP::IData::Client->new(
        proxy => "http://$hostport/idata",
    );
    my $uri1 = $idata->create( "foo" );
    my $uri2 = $idata->replicate( "foo" );

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

    ok( eq_set( [$uri1, $uri2], $locations ), "URIs match" );
}


Test::IData->setup;

{
    my $idata = PS::IPP::IData::Client->new(
        proxy => "http://$hostport/idata",
    );

    is( $idata->find_instances( "foo" ), undef, "storage object does not exist" );
}

Test::IData->setup;

eval {
    my $idata = PS::IPP::IData::Client->new(
        proxy => "http://$hostport/idata",
    );

    $idata->find_instances();
};
like( $@, qr/1 - 2 were expected/, "no params" );

Test::IData->setup;

eval {
    my $idata = PS::IPP::IData::Client->new(
        proxy => "http://$hostport/idata",
    );

    $idata->find_instances( "foo", 'read', 3 );
};
like( $@, qr/1 - 2 were expected/, "too many params" );

Test::IData->cleanup;

}
