File: 10_http.t

package info (click to toggle)
libtest-fake-httpd-perl 0.09-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 164 kB
  • sloc: perl: 144; sh: 4; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 840 bytes parent folder | download | duplicates (4)
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
use Test::More;
use Test::Exception;
use Test::TCP qw(wait_port);
use LWP::UserAgent;

BEGIN {
    *describe = *it = \&subtest;
}

use Test::Fake::HTTPD;

describe 'run_http_server' => sub {
    my $httpd = run_http_server {
        my $req = shift;
        [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello World' ] ];
    };

    it 'should return a server info' => sub {
        my $port = $httpd->port;

        ok $port > 0;
        is $httpd->host_port => "127.0.0.1:$port";
        is $httpd->endpoint  => "http://127.0.0.1:$port";
    };

    it 'should receive correct response' => sub {
        my $ua = LWP::UserAgent->new;

        my $res = $ua->get($httpd->endpoint);

        is $res->code => 200;
        is $res->header('Content-Type') => 'text/plain';
        is $res->content => 'Hello World';
    };
};

done_testing;