Imported Upstream version 1.7
This commit is contained in:
33
t/DTO/00-compile.t
Normal file
33
t/DTO/00-compile.t
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More;
|
||||
use Test::Moose::More;
|
||||
use Data::DTO::GELF;
|
||||
|
||||
use Readonly;
|
||||
Readonly my $CLASS => 'Data::DTO::GELF';
|
||||
|
||||
subtest "$CLASS Is valid object." => sub {
|
||||
meta_ok($CLASS);
|
||||
};
|
||||
|
||||
subtest "$CLASS has correct attributes" => sub {
|
||||
has_attribute_ok( $CLASS, 'version' );
|
||||
has_attribute_ok( $CLASS, 'host' );
|
||||
has_attribute_ok( $CLASS, 'short_message' );
|
||||
has_attribute_ok( $CLASS, 'full_message' );
|
||||
has_attribute_ok( $CLASS, 'timestamp' );
|
||||
has_attribute_ok( $CLASS, 'level' );
|
||||
|
||||
};
|
||||
|
||||
subtest "$CLASS has correct predicates, clearers, writers, and builders" =>
|
||||
sub {
|
||||
has_method_ok( $CLASS, '_build_version' );
|
||||
has_method_ok( $CLASS, '_build_timestamp' );
|
||||
};
|
||||
|
||||
done_testing();
|
||||
62
t/DTO/01-instance.t
Normal file
62
t/DTO/01-instance.t
Normal file
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::Most;
|
||||
use Test::Moose::More;
|
||||
use Data::DTO::GELF;
|
||||
use Data::UUID;
|
||||
use POSIX qw(strftime);
|
||||
use Data::Random::String;
|
||||
|
||||
use JSON -convert_blessed_universally;
|
||||
|
||||
use Readonly;
|
||||
Readonly my $CLASS => 'Data::DTO::GELF';
|
||||
|
||||
my $obj;
|
||||
my $data = {
|
||||
'full_message' => Data::Random::String->create_random_string(
|
||||
length => '100',
|
||||
contains => 'alpha'
|
||||
),
|
||||
'level' => "DEBUG",
|
||||
'_timestr' => strftime( "%Y-%m-%d %H:%M:%S", gmtime( time() ) ),
|
||||
'_uuid' => Data::UUID->new()->create_str(),
|
||||
};
|
||||
|
||||
subtest "$CLASS Is valid object." => sub {
|
||||
lives_ok {
|
||||
$obj = $CLASS->new($data)
|
||||
}
|
||||
"Lives though creating instance if $CLASS";
|
||||
|
||||
ok( $obj, "$CLASS is Instanced" );
|
||||
};
|
||||
|
||||
subtest "$CLASS has proper values" => sub {
|
||||
cmp_ok( $obj->version(), "eq", "1.1", "Version tag is 1.1" );
|
||||
cmp_ok( $obj->full_message(), "eq", $data->{full_message},
|
||||
"Full message is ok" );
|
||||
cmp_ok(
|
||||
$obj->short_message(), "eq",
|
||||
( substr $data->{full_message}, 0, 100 ),
|
||||
"Short message is full message truncated to 100 chars."
|
||||
);
|
||||
cmp_ok( $obj->level(), "==", "0", "DEBUG level is coerced to 0" );
|
||||
ok( defined $obj->timestamp(), "Timestamp is defined" );
|
||||
cmp_ok( $obj->_uuid(), "eq", $data->{_uuid},
|
||||
"Dynamic _var's were created" );
|
||||
|
||||
};
|
||||
subtest "$CLASS hashifys for TO_JSON" => sub {
|
||||
lives_ok {
|
||||
my $json = JSON->new->allow_nonref->convert_blessed;
|
||||
my $j = $json->encode($obj);
|
||||
ok( defined $j, "Has JSON value" );
|
||||
}
|
||||
"Lives through converting to json";
|
||||
};
|
||||
|
||||
done_testing();
|
||||
Reference in New Issue
Block a user