"Fossies" - the Fresh Open Source Software Archive

Member "perl-5.32.1/cpan/HTTP-Tiny/t/002_croakage.t" (18 Dec 2020, 1377 Bytes) of package /linux/misc/perl-5.32.1.tar.xz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!perl
    2 
    3 use strict;
    4 use warnings;
    5 
    6 use Test::More;
    7 use lib 't';
    8 use Util qw[tmpfile monkey_patch set_socket_source];
    9 
   10 use HTTP::Tiny;
   11 
   12 BEGIN { monkey_patch() }
   13 
   14 my %usage = (
   15   'get' => q/Usage: $http->get(URL, [HASHREF])/,
   16   'mirror' => q/Usage: $http->mirror(URL, FILE, [HASHREF])/,
   17   'request' => q/Usage: $http->request(METHOD, URL, [HASHREF])/,
   18 );
   19 
   20 my @cases = (
   21   ['get'],
   22   ['get','http://www.example.com/','extra'],
   23   ['get','http://www.example.com/','extra', 'extra'],
   24   ['mirror'],
   25   ['mirror','http://www.example.com/',],
   26   ['mirror','http://www.example.com/','extra', 'extra'],
   27   ['mirror','http://www.example.com/','extra', 'extra', 'extra'],
   28   ['request'],
   29   ['request','GET'],
   30   ['request','GET','http://www.example.com/','extra'],
   31   ['request','GET','http://www.example.com/','extra', 'extra'],
   32 );
   33 
   34 my $res_fh = tmpfile();
   35 my $req_fh = tmpfile();
   36 
   37 my $http = HTTP::Tiny->new;
   38 set_socket_source($req_fh, $res_fh);
   39 
   40 for my $c ( @cases ) {
   41   my ($method, @args) = @$c;
   42   eval {$http->$method(@args)};
   43   my $err = $@;
   44   like ($err, qr/\Q$usage{$method}\E/, join("|",@$c) );
   45 }
   46 
   47 my $res = eval{ $http->get("http://www.example.com/", { headers => { host => "www.example2.com" } } ) };
   48 is( $res->{status}, 599, "Providing a Host header errors with 599" );
   49 like( $res->{content}, qr/'Host' header/, "Providing a Host header gives right error message" );
   50 
   51 done_testing;
   52