#!/usr/bin/perl

use strict;
use warnings;

use Test::More tests => 12;

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

    my $info = $idata->stat_object( "foo" );

    is( scalar @$info, 7, "number of columns" );
}

Test::IData->setup;

{
    my $uri = $idata->create_object( "foo", 9, "node01", "foobar" );

    my $info = $idata->stat_object( "foo" );

    is( scalar @$info, 7,                       "number of columns" );
    is( @$info[0], 1,                           "so_id" );
    is( @$info[1], "foo",                       "ext_id" );
    is( @$info[2], 9,                           "class_id" );
    is( @$info[3], "foobar",                    "comment" );
    is( @$info[4], 0,                           "read lock" );
    is( @$info[5], undef,                       "write lock" );
    like( @$info[6], qr/....-..-.. ..:..:../,   "epoch" );
}

Test::IData->setup;

eval {
    $idata->stat_object( "foo" );
};
like( $@, qr/no storage object found/, "object does not exist" );

Test::IData->setup;

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

Test::IData->setup;

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

Test::IData->cleanup;
