Added tests for passing filehandle to res->body
[catagits/Catalyst-Runtime.git] / t / live / component / controller / action / streaming.t
CommitLineData
fbcc39ad 1#!perl
2
3use strict;
4use warnings;
5
6use FindBin;
7use lib "$FindBin::Bin/../../../lib";
8
3dc4d7e9 9use Test::More tests => 8;
fbcc39ad 10use Catalyst::Test 'TestApp';
11
3dc4d7e9 12# test direct streaming
fbcc39ad 13{
14 ok( my $response = request('http://localhost/streaming'), 'Request' );
15 ok( $response->is_success, 'Response Successful 2xx' );
16 is( $response->content_type, 'text/plain', 'Response Content-Type' );
17 is( $response->content,, <<'EOF', 'Content is a stream' );
18foo
19bar
20baz
21EOF
22}
3dc4d7e9 23
24# test streaming by passing a handle to $c->res->body
25{
26 my $file = "$FindBin::Bin/../../../../01use.t";
27 my $fh = IO::File->new( $file, 'r' );
28 my $buffer;
29 if ( defined $fh ) {
30 $fh->read( $buffer, 1024 );
31 $fh->close;
32 }
33
34 ok( my $response = request('http://localhost/action/streaming/body'), 'Request' );
35 ok( $response->is_success, 'Response Successful 2xx' );
36 is( $response->content_type, 'text/plain', 'Response Content-Type' );
37 is( $response->content, $buffer, 'Content is read from filehandle' );
38}