File: 001-basic.t

package info (click to toggle)
libhttp-throwable-perl 0.028-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 428 kB
  • sloc: perl: 1,354; makefile: 2; sh: 1
file content (57 lines) | stat: -rw-r--r-- 1,306 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
#!/usr/bin/perl
use strict;
use warnings;

use Test::More;
use Test::Fatal;
use lib 't/lib';
use Test::HT;

ht_test(
    { status_code => 500, reason => 'Internal Server Error' },
    {
        code   => 500,
        reason => 'Internal Server Error',
        assert => sub {
          my $e = shift;

          is(
              "$e",
              '500 Internal Server Error',
              '... got the right string overload',
          );

          if ($e->does('HTTP::Throwable::Role::TextBody')) {
              is_deeply(
                  $e->(),
                  [
                      500,
                      [
                          'Content-Type'   => 'text/plain',
                          'Content-Length' => 25,
                      ],
                      [ '500 Internal Server Error' ]
                  ],
                  '... got the right &{} overload transformation'
              );
          }
        },
    },
);

subtest "strict constructors all around" => sub {
  my $error = exception {
    HTTP::Throwable::Factory->throw(MovedPermanently => {
      location => '/foo',
      bogus    => 123,
    });
  };

  like(
    $error,
    qr{Found unknown attribute\(s\) passed to the constructor},
    "http throwables have strict constructors",
  );
};

done_testing;