Changeset 16873

Show
Ignore:
Timestamp:
07/30/08 18:32:38 (5 years ago)
Author:
yappo
Message:

add copy_to and link_to method tests

Location:
lang/perl/HTTP-Engine
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/HTTP-Engine/branches/lazy_request/t/020_interface/test_upload.t

    r16846 r16873  
    55use HTTP::Request; 
    66use Test::Base; 
     7use File::Temp qw( tempdir ); 
     8use File::Spec; 
    79 
    8 plan tests => 1*blocks; 
     10plan tests => 3*blocks; 
    911 
    1012filters { 
     
    2830    } 
    2931 
     32    my $upload; 
    3033    my $response = HTTP::Engine->new( 
    3134        interface => { 
     
    3639                $c->res->body('OK!'); 
    3740                return unless $body; 
    38                 return unless $c->req->upload('test_upload_file'); 
    39                 unless ($body eq $c->req->upload('test_upload_file')->slurp) { 
     41 
     42                return unless $upload = $c->req->upload('test_upload_file'); 
     43                my $upload_body = $upload->slurp; 
     44                unless ($body eq $upload_body) { 
    4045                    $c->res->body('NG'); 
    4146                } 
     
    4752    my $data = $response->headers->as_string."\n".$response->content; 
    4853    is $data, $block->response; 
     54 
     55    unless ($upload) { 
     56        ok 1; 
     57        ok 1; 
     58        return; 
     59    }; 
     60 
     61    my $tmpdir = tempdir( CLEANUP => 1 ); 
     62    is slurp( copy => $tmpdir => $upload ), $body; 
     63    is slurp( link => $tmpdir => $upload ), $body; 
    4964}; 
     65 
     66sub slurp { 
     67    my($action, $tmpdir, $upload) = @_; 
     68    my $method = "${action}_to"; 
     69    my $path = File::Spec->catfile( $tmpdir, $action ); 
     70    $upload->$method($path); 
     71    open my $fh, '<', $path or die $!; 
     72    eval { local $/; <$fh> }; 
     73} 
    5074 
    5175sub crlf { 
  • lang/perl/HTTP-Engine/trunk/t/020_interface/test_upload.t

    r16846 r16873  
    55use HTTP::Request; 
    66use Test::Base; 
     7use File::Temp qw( tempdir ); 
     8use File::Spec; 
    79 
    8 plan tests => 1*blocks; 
     10plan tests => 3*blocks; 
    911 
    1012filters { 
     
    2830    } 
    2931 
     32    my $upload; 
    3033    my $response = HTTP::Engine->new( 
    3134        interface => { 
     
    3639                $c->res->body('OK!'); 
    3740                return unless $body; 
    38                 return unless $c->req->upload('test_upload_file'); 
    39                 unless ($body eq $c->req->upload('test_upload_file')->slurp) { 
     41 
     42                return unless $upload = $c->req->upload('test_upload_file'); 
     43                my $upload_body = $upload->slurp; 
     44                unless ($body eq $upload_body) { 
    4045                    $c->res->body('NG'); 
    4146                } 
     
    4752    my $data = $response->headers->as_string."\n".$response->content; 
    4853    is $data, $block->response; 
     54 
     55    unless ($upload) { 
     56        ok 1; 
     57        ok 1; 
     58        return; 
     59    }; 
     60 
     61    my $tmpdir = tempdir( CLEANUP => 1 ); 
     62    is slurp( copy => $tmpdir => $upload ), $body; 
     63    is slurp( link => $tmpdir => $upload ), $body; 
    4964}; 
     65 
     66sub slurp { 
     67    my($action, $tmpdir, $upload) = @_; 
     68    my $method = "${action}_to"; 
     69    my $path = File::Spec->catfile( $tmpdir, $action ); 
     70    $upload->$method($path); 
     71    open my $fh, '<', $path or die $!; 
     72    eval { local $/; <$fh> }; 
     73} 
    5074 
    5175sub crlf {