File: util-fail.t

package info (click to toggle)
libemail-sender-perl 2.601-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 468 kB
  • sloc: perl: 2,276; makefile: 2
file content (42 lines) | stat: -rw-r--r-- 1,145 bytes parent folder | download | duplicates (6)
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
#!perl
use strict;
use warnings;
use Test::More tests => 14;

use Email::Sender::Util;

{
  package FakeSMTP;
  use Moo;

  has code    => (is => 'rw');
  has message => (is => 'rw');

  no Moo;
}

sub smtp { FakeSMTP->new({ code => $_[0], message => $_[1] }); }

my $i = 0;
sub test_fail {
  my ($error, $smtp, $rest, $class, $message) = @_;
  $rest ||= {};
  my $full_class = 'Email::Sender::Failure';
  $full_class .= "::$class" if $class;
  $i++;

  my $fail = Email::Sender::Util->_failure($error, $smtp, %$rest);

  is(ref $fail, $full_class, "class of failure $i is $full_class");
  is($fail->message, $message, "failure $i has the right message");
}

test_fail('xyzzy', undef,               {}, undef,       'xyzzy');
test_fail('xyzzy', smtp(100 => 'fail'), {}, undef,       'xyzzy: fail');
test_fail('xyzzy', smtp(400 => 'fail'), {}, 'Temporary', 'xyzzy: fail');
test_fail('xyzzy', smtp(500 => 'fail'), {}, 'Permanent', 'xyzzy: fail');

test_fail(undef,   smtp(100 => 'fail'), {}, undef,       'fail');
test_fail(undef,   smtp(400 => 'fail'), {}, 'Temporary', 'fail');
test_fail(undef,   smtp(500 => 'fail'), {}, 'Permanent', 'fail');