File: base.t

package info (click to toggle)
libmetabase-fact-perl 0.022-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 328 kB
  • ctags: 125
  • sloc: perl: 1,021; makefile: 2
file content (96 lines) | stat: -rw-r--r-- 2,947 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Copyright (c) 2008 by Ricardo Signes. All rights reserved.
# Licensed under terms of Perl itself (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License was distributed with this file or you may obtain a 
# copy of the License from http://dev.perl.org/licenses/

use strict;
use warnings;

use Test::More 0.88;
use Test::Exception;

use lib 't/lib';
use Test::Metabase::StringFact;

plan tests => 17;

require_ok( 'Metabase::Fact' );

#--------------------------------------------------------------------------#
# fixtures
#--------------------------------------------------------------------------#    

my ($obj, $err);

#--------------------------------------------------------------------------#
# required parameters missing
#--------------------------------------------------------------------------#

eval { $obj = Metabase::Fact->new() };
$err = $@;
like( $err, qr/missing required/, "new() without params throws error" );
for my $p ( qw/ resource content / ) {
    like( $err, qr/$p/, "... '$p' noted missing" );
}

is(
  Metabase::Fact->default_schema_version,
  1,
  "schema_version() defaults to 1",
);

#--------------------------------------------------------------------------#
# fake an object and test methods
#--------------------------------------------------------------------------#

# type is class munged from "::" to "-"
is( Metabase::Fact->type, "Metabase-Fact", 
  "->type converts class name" 
);

# unimplemented
for my $m ( qw/content_as_bytes content_from_bytes validate_content/ ) {
    my $obj = bless {} => 'Metabase::Fact';
    eval { $obj->$m };
    like( $@, qr/$m not implemented by Metabase::Fact/, "$m not implemented");
}

#--------------------------------------------------------------------------#
# new should take either hashref or list
#--------------------------------------------------------------------------#

my $string = "Who am I?";

my $args = {
    resource => "metabase:fact:543fc732-0eec-11df-a736-0018f34ec37c",
    content  => $string,
};

lives_ok{ $obj = Test::Metabase::StringFact->new( $args ) } 
    "new( <hashref> ) doesn't die";

isa_ok( $obj, 'Test::Metabase::StringFact' ); 

lives_ok{ $obj = Test::Metabase::StringFact->new( %$args ) } 
    "new( <list> ) doesn't die";

isa_ok( $obj, 'Test::Metabase::StringFact' );

is( $obj->type, "Test-Metabase-StringFact", "object type is correct" );
is( $obj->content, $string, "object content correct" );

#--------------------------------------------------------------------------#
# class validation
#--------------------------------------------------------------------------#

eval { $obj->_load_fact_class("Cwd;die 'Insecure'!"); };
like( $@, qr/does not look like a class name/,
  "fact class loading validates class name"
);
eval { $obj->resource->_load("Cwd;die 'Insecure'!"); };
like( $@, qr/does not look like a class name/,
  "fact class loading validates class name"
);