#!/usr/bin/perl

# Copryight (C) 2004-2005  Joshua Hoblitt
#
# $Id: 09_server_stat_object.t,v 1.11 2007-05-03 03:21:28 jhoblitt Exp $

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

use Test::More tests => 12;

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

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

my $neb = Nebulous::Server->new(
    dsn         => "DBI:mysql:database=test:host=localhost",
    dbuser      => "test",
    dbpasswd    => "",
);

Test::Nebulous->setup;
{
    $neb->create_object("foo");

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

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

Test::Nebulous->setup;

{
    $neb->create_object("foo", "node01");

    my $info = $neb->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], 0,                           "read lock");
    is(@$info[3], undef,                       "write lock");
    like(@$info[4], qr/....-..-.. ..:..:../,   "epoch");
    like(@$info[5], qr/....-..-.. ..:..:../,   "mtime");
    is(@$info[6], 1,                           "instances");
}

Test::Nebulous->setup;

eval {
    $neb->stat_object("foo");
};
like($@, qr/is valid object key/, "object does not exist");

Test::Nebulous->setup;

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

Test::Nebulous->setup;

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

Test::Nebulous->cleanup;
