xref: /openbsd-src/gnu/usr.bin/perl/cpan/HTTP-Tiny/t/141_no_proxy.t (revision 256a93a44f36679bee503f12e49566c2183f6181)
1#!perl
2use strict;
3use warnings;
4
5use Test::More 0.88;
6
7use HTTP::Tiny;
8
9# blank slate for testing
10delete $ENV{no_proxy};
11
12{
13    my $c = HTTP::Tiny->new();
14    is_deeply( $c->no_proxy, [], "no no_proxy given" );
15}
16
17my @cases = (
18    #<<< No perltidy
19    {
20        no_proxy => [
21            undef,
22            [],
23        ],
24        expect => [],
25    },
26    {
27        no_proxy => [
28            "localhost",
29            ["localhost"],
30        ],
31        expect => ["localhost"],
32    },
33    {
34        no_proxy => [
35            "localhost,example.com",
36            "localhost, example.com",
37            [qw/localhost example.com/]
38        ],
39        expect   => [ "localhost", "example.com" ],
40    },
41    #>>>
42);
43
44for my $c (@cases) {
45    for my $no_proxy ( @{ $c->{no_proxy} } ) {
46        my $label =
47           !defined $no_proxy ? 'undef'
48          : ref $no_proxy     ? "[qw/@$no_proxy/]"
49          :                     "'$no_proxy'";
50
51        # Can't test environment with array ref (ENV stringifies in new perls)
52        if ( ref $no_proxy ) {
53            my $ht = HTTP::Tiny->new( no_proxy => $no_proxy );
54            is_deeply( $ht->no_proxy, $c->{expect}, "new(no_proxy => $label)" );
55        }
56        else {
57            {
58                no warnings 'uninitialized';
59                local $ENV{no_proxy} = $no_proxy;
60                my $ht = HTTP::Tiny->new();
61                is_deeply( $ht->no_proxy, $c->{expect}, "\$ENV{no_proxy} = $label" );
62            }
63            {
64                local $ENV{no_proxy} = "Shouldnt,see,this";
65                my $ht = HTTP::Tiny->new( no_proxy => $no_proxy );
66                is_deeply( $ht->no_proxy, $c->{expect},
67                    "new(no_proxy => $label) versus other \$ENV{no_proxy}" );
68            }
69        }
70    }
71}
72
73done_testing();
74