App-Wallflower

 view release on metacpan or  search on metacpan

t/20-get.t  view on Meta::CPAN

            'Last-Modified'  => $last_modified
        ],
        'index.html',
        'Hello, World!'
    ],
    [ '/' => 304, [], 'index.html', 'Hello, World!' ],
];

push @tests, [
    'not respecting directory semantics',
    Path::Tiny->tempdir( CLEANUP => 1 ),
    sub {
        [   200,
            [ 'Content-Type' => 'text/plain', 'Content-Length' => 13 ],
            [ 'Hello,', ' ', 'World!' ]
        ];
    },
    [ 'http://localhost//foo' => 200,
        [ 'Content-Type' => 'text/plain', 'Content-Length' => 13 ],
        'foo',
        'Hello, World!'
    ],
    [ 'http://localhost//foo/bar' => 999, [], '', '' ],
    [ '/foo' => 200,
        [ 'Content-Type' => 'text/plain', 'Content-Length' => 13 ],
        'foo',
        'Hello, World!'
    ],
    [ '/foo/bar' => 999, [], '', '' ],
    [ '/bar/foo' => 200,
        [ 'Content-Type' => 'text/plain', 'Content-Length' => 13 ],
        'bar/foo',
        'Hello, World!'
    ],
    [ '/bar' => 999, [], '', '' ],
];

plan tests => sum map 2 * ( @$_ - 3 ), @tests;

for my $t (@tests) {
    my ( $desc, $dir, $app, @urls ) = @$t;

    my $wf = Wallflower->new(
        application => $app,
        destination => $dir,
    );

    for my $u (@urls) {
        my ( $url, $status, $headers, $file, $content ) = @$u;

        my $result = $wf->get($url);
        is_deeply(
            $result,
            [   $status, $headers, $file && Path::Tiny->new( $dir, $file )
            ],
            "app ($desc) for $url"
        );

        if ( $status == 200 || $status == 304 ) {
            my $file_content
                = do { local $/; local @ARGV = ( $result->[2] ); <> };
            is( $file_content, $content, "content ($desc) for $url" );
        }
        else {
            is( $result->[2], '', "no file ($desc) for $url" );
        }
    }
}



( run in 1.436 second using v1.01-cache-2.11-cpan-54e63673c56 )