Tests: added test for reading body from IO::Handle-like object.
This commit is contained in:
33
test/perl/body_io_fake/IOFake.pm
Normal file
33
test/perl/body_io_fake/IOFake.pm
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package IOFake;
|
||||||
|
|
||||||
|
sub new {
|
||||||
|
my $class = shift;
|
||||||
|
my $errors = shift;
|
||||||
|
my $self = {};
|
||||||
|
|
||||||
|
$self->{_count} = 2;
|
||||||
|
$self->{_errors} = $errors;
|
||||||
|
|
||||||
|
bless $self, $class;
|
||||||
|
return $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub getline() {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
if ($self->{_count} > 0) {
|
||||||
|
return $self->{_count}--;
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->{_errors}->print('IOFake getline() $/ is ' . ${ $/ });
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub close() {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
$self->{_errors}->print('IOFake close() called');
|
||||||
|
};
|
||||||
|
|
||||||
|
1;
|
||||||
11
test/perl/body_io_fake/psgi.pl
Normal file
11
test/perl/body_io_fake/psgi.pl
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
use File::Basename;
|
||||||
|
use lib dirname (__FILE__);
|
||||||
|
use IOFake;
|
||||||
|
|
||||||
|
my $app = sub {
|
||||||
|
my ($environ) = @_;
|
||||||
|
|
||||||
|
my $io = IOFake->new($environ->{'psgi.errors'});
|
||||||
|
|
||||||
|
return ['200', [ 'Content-Length' => '2' ], $io];
|
||||||
|
};
|
||||||
@@ -185,5 +185,19 @@ class TestUnitPerlApplication(unit.TestUnitApplicationPerl):
|
|||||||
|
|
||||||
self.assertEqual(resp['body'], '0123456789', 'keep-alive 2')
|
self.assertEqual(resp['body'], '0123456789', 'keep-alive 2')
|
||||||
|
|
||||||
|
@unittest.expectedFailure
|
||||||
|
def test_perl_body_io_fake(self):
|
||||||
|
self.load('body_io_fake')
|
||||||
|
|
||||||
|
self.assertEqual(self.get()['body'], '21', 'body io fake')
|
||||||
|
|
||||||
|
self.assertIsNotNone(
|
||||||
|
self.search_in_log(r'\[error\].+IOFake getline\(\) \$\/ is \d+'),
|
||||||
|
'body io fake $/ value')
|
||||||
|
|
||||||
|
self.assertIsNotNone(
|
||||||
|
self.search_in_log(r'\[error\].+IOFake close\(\) called'),
|
||||||
|
'body io fake close')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
TestUnitPerlApplication.main()
|
TestUnitPerlApplication.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user