File: http.t

package info (click to toggle)
perlbrew 0.78-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 708 kB
  • sloc: perl: 6,291; makefile: 6
file content (71 lines) | stat: -rw-r--r-- 1,809 bytes parent folder | download | duplicates (3)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env perl
use strict;
use Test::Spec;
use App::perlbrew;
use File::Temp 'tempdir';
use IO::All;

unless ($ENV{PERLBREW_DEV_TEST}) {
    plan skip_all => <<REASON;

This test invokes HTTP request to external servers and should not be ran in
blind. Whoever which to test this need to set PERLBREW_DEV_TEST env var to 1.

REASON
}

my $ua = App::perlbrew::http_user_agent_program();
note "User agent program = $ua";

describe "App::perlbrew::http_get function" => sub {
    my ($output);

    before all => sub {
        App::perlbrew::http_get(
            "https://get.perlbrew.pl",
            undef,
            sub { $output = $_[0]; }
        );
    };

    it "calls the callback to assign content to \$output", sub {
       ok defined($output) && length($output) > 0;
    };

    it "seems to download the correct content", sub {
        ok $output =~ m<\A #!/usr/bin/perl\n >x;
        ok $output =~ m< \$fatpacked\{"App/perlbrew.pm"\} >x;
    };
};

describe "App::perlbrew::http_download function, downloading the perlbrew-installer." => sub {
    my ($dir, $output, $download_error);

    before all => sub {
        $dir = tempdir( CLEANUP => 1 );
        $output = "$dir/perlbrew-installer";

        if (-f $output) {
            plan skip_all => <<REASON;

We created a temporary dir $dir for storing the downloaded content.
But somehow the target file name already exists before we start.
Therefore we cannot proceed the test.

REASON
        }

        my $download_error = App::perlbrew::http_download("https://install.perlbrew.pl", $output);
    };

    it "downloads to the wanted path" => sub {
        ok(-f $output);
    };

    it "seems to be downloading the right content" => sub {
        is(scalar(io($output)->getline), "#!/bin/sh\n");
    };
};

runtests unless caller;