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
|
use Test::More tests => 13;
use strict;
use warnings;
use Net::Proxy;
my $proxy;
# test constructor
eval { $proxy = Net::Proxy->new(); };
like( $@, qr/^Argument to new\(\) must be a HASHREF/, 'new( HASHREF )' );
eval { $proxy = Net::Proxy->new(1); };
like( $@, qr/^Argument to new\(\) must be a HASHREF/, 'new( HASHREF )' );
# in argument
eval { $proxy = Net::Proxy->new( {} ); };
like( $@, qr/^'in' connector required/, 'in arg required' );
eval { $proxy = Net::Proxy->new( { in => 'in' } ); };
like( $@, qr/^'in' connector must be a HASHREF/, 'in must be a HASHREF');
eval { $proxy = Net::Proxy->new( { in => {} } ); };
like(
$@,
qr/^'type' key required for 'in' connector/,
'type required for in arg'
);
eval {
$proxy = Net::Proxy->new( { in => { type => 'zlonk', hook => {} } } );
};
like(
$@,
qr/^'hook' key is not a CODE reference for 'in' connector/,
'hook must be a CODE reference'
);
eval { $proxy = Net::Proxy->new( { in => { type => 'zlonk' } } ); };
like(
$@,
qr/^Couldn't load Net::Proxy::Connector::zlonk for 'in' connector/,
q{NPC::zlonk doesn't exist}
);
# out argument
eval { $proxy = Net::Proxy->new( { in => { type => 'tcp' } } ); };
like( $@, qr/^'out' connector required/, 'out arg required' );
eval { $proxy = Net::Proxy->new( { in => { type => 'tcp' }, out => 'out' } ) };
like( $@, qr/^'out' connector must be a HASHREF/, 'in must be a HASHREF');
eval { $proxy = Net::Proxy->new( { in => { type => 'tcp' }, out => {} } ); };
like(
$@,
qr/^'type' key required for 'out' connector/,
'type required for out arg'
);
eval {
$proxy = Net::Proxy->new(
{ in => { type => 'tcp' },
out => { type => 'zlonk', hook => bless {}, 'CODE' }
}
);
};
like(
$@,
qr/^'hook' key is not a CODE reference for 'out' connector/,
'hook must be a CODE reference'
);
eval {
$proxy = Net::Proxy->new(
{ in => { type => 'tcp' }, out => { type => 'zlonk' } } );
};
like(
$@,
qr/^Couldn't load Net::Proxy::Connector::zlonk for 'out' connector/,
q{NPC::zlonk doesn't exist}
);
# ok
eval {
$proxy = Net::Proxy->new(
{ in => { type => 'tcp' }, out => { type => 'tcp' } } );
};
is( $@, '', 'Net::Proxy->new()' );
|