App-tarweb

 view release on metacpan or  search on metacpan

t/app_tarweb.t  view on Meta::CPAN

use Test2::V0 -no_srand => 1;
use 5.034;
use experimental qw( signatures );
use App::tarweb;
use Test2::Tools::HTTP;
use Test2::Tools::DOM;
use HTTP::Request::Common;
use Mojo::DOM58;
use URI;
use Path::Tiny qw( path );
use Capture::Tiny qw( capture_stderr );

subtest 'no archive' => sub {

  my $cli = App::tarweb->new;

  my($stderr, $exit) = capture_stderr {
    $cli->main;
  };

  is $exit, 2, 'returned 2 on exit';
  like $stderr, qr/no archive file given!/;
};

subtest 'basic' => sub {

  my $cli = App::tarweb->new;

  my $called_run = 0;

  my $mock = mock 'Plack::Runner' => (
    override => [
      run => sub ($, $app) {

        $called_run = 1;

        my $url = URI->new('http://localhost');

        my $guard = psgi_app_guard $url => $app;

        $url->path('/');

        http_request
          GET($url),
          http_response {
            http_code 200;
            http_content_type 'text/html';
            call content => dom {
              find 'ul li a' => [
                dom { attr href => 'foo.html'; content 'foo.html' },
                dom { attr href => 'foo.txt';  content 'foo.txt'  },
              ];
            };
          };

        note http_tx->res->as_string;

        foreach my $href (map { $_->attr('href') } Mojo::DOM58->new(http_tx->res->decoded_content)->find('ul li a')->to_array->@*)
        {
          my $url = URI->new_abs( $href, $url );
          http_request
            GET($url),
            http_response {
              http_code 200;
            }
        }



( run in 0.430 second using v1.01-cache-2.11-cpan-5837b0d9d2c )