File: 200_live_local_ip.t

package info (click to toggle)
libhttp-tiny-perl 0.090-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 788 kB
  • sloc: perl: 3,124; makefile: 6
file content (42 lines) | stat: -rw-r--r-- 1,075 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 IO::Socket::INET;
use Test::More 0.88;
use HTTP::Tiny;

my $test_host = "www.google.com";
my $test_url  = "http://www.google.com/";

plan 'skip_all' => "Only run for \$ENV{AUTOMATED_TESTING}"
  unless $ENV{AUTOMATED_TESTING};

plan 'skip_all' => "Internet connection timed out"
  unless IO::Socket::INET->new(
    PeerHost  => $test_host,
    PeerPort  => 80,
    Proto     => 'tcp',
    Timeout   => 10,
  );

my ($tiny, $response);

# default local address should work; try three times since the test url
# can have intermittent failures
$tiny = HTTP::Tiny->new;
for (1 .. 3) {
    $response = $tiny->get($test_url);
    last if $response->{success};
    sleep 2;
}
isnt( $response->{status}, '599', "Request to $test_url completed (default local address)" );

# bad local IP should fail
$tiny = HTTP::Tiny->new(local_address => '999.999.999.999'); # bad IP is error
$response = $tiny->get($test_url);
is( $response->{status}, '599', "Request to $test_url failed (invalid local address)" )
  or diag explain $response;

done_testing;