|
Revision 11543, 1.6 kB
(checked in by tokuhirom, 5 years ago)
|
|
$c->env is not a useful, we should use %ENV directly.
|
| Line | |
|---|
| 1 | use Test::Base; |
|---|
| 2 | use YAML (); |
|---|
| 3 | use HTTP::Engine::Context; |
|---|
| 4 | use HTTP::Engine::RequestBuilder; |
|---|
| 5 | use IO::Scalar; |
|---|
| 6 | |
|---|
| 7 | plan tests => 7; |
|---|
| 8 | |
|---|
| 9 | can_ok( |
|---|
| 10 | 'HTTP::Engine::RequestBuilder' => 'prepare' |
|---|
| 11 | ); |
|---|
| 12 | |
|---|
| 13 | filters { |
|---|
| 14 | env => [qw/yaml/] |
|---|
| 15 | }; |
|---|
| 16 | |
|---|
| 17 | my $builder = HTTP::Engine::RequestBuilder->new; |
|---|
| 18 | |
|---|
| 19 | run { |
|---|
| 20 | my $block = shift; |
|---|
| 21 | |
|---|
| 22 | local %ENV = %{ $block->env }; |
|---|
| 23 | my $c = HTTP::Engine::Context->new(); |
|---|
| 24 | |
|---|
| 25 | tie *STDIN, 'IO::Scalar', \( $block->body ); |
|---|
| 26 | $builder->prepare($c); |
|---|
| 27 | untie *STDIN; |
|---|
| 28 | |
|---|
| 29 | eval $block->test; |
|---|
| 30 | die $@ if $@; |
|---|
| 31 | }; |
|---|
| 32 | |
|---|
| 33 | __END__ |
|---|
| 34 | |
|---|
| 35 | === |
|---|
| 36 | --- env |
|---|
| 37 | REMOTE_ADDR: 127.0.0.1 |
|---|
| 38 | SERVER_PORT: 80 |
|---|
| 39 | QUERY_STRING: '' |
|---|
| 40 | REQUEST_METHOD: 'GET' |
|---|
| 41 | HTTP_HOST: localhost |
|---|
| 42 | --- body |
|---|
| 43 | --- test |
|---|
| 44 | is $c->req->address, '127.0.0.1'; |
|---|
| 45 | |
|---|
| 46 | === |
|---|
| 47 | --- env |
|---|
| 48 | REMOTE_ADDR: 127.0.0.1 |
|---|
| 49 | SERVER_PORT: 80 |
|---|
| 50 | QUERY_STRING: '' |
|---|
| 51 | REQUEST_METHOD: 'POST' |
|---|
| 52 | HTTP_HOST: localhost |
|---|
| 53 | HTTP_CONTENT_LENGTH: 7 |
|---|
| 54 | HTTP_CONTENT_TYPE: application/x-www-form-urlencoded |
|---|
| 55 | --- body: a=b&c=d |
|---|
| 56 | --- test |
|---|
| 57 | is_deeply $c->req->body_params, {a => 'b', c => 'd'}; |
|---|
| 58 | |
|---|
| 59 | === |
|---|
| 60 | --- env |
|---|
| 61 | REMOTE_ADDR: 127.0.0.1 |
|---|
| 62 | SERVER_PORT: 80 |
|---|
| 63 | QUERY_STRING: '' |
|---|
| 64 | REQUEST_METHOD: 'POST' |
|---|
| 65 | HTTP_HOST: localhost |
|---|
| 66 | HTTP_CONTENT_LENGTH: 12 |
|---|
| 67 | HTTP_CONTENT_TYPE: application/octet-stream |
|---|
| 68 | --- body: OCTET STREAM |
|---|
| 69 | --- test |
|---|
| 70 | isa_ok $c->req->body, 'IO::Handle'; |
|---|
| 71 | $c->req->body->sysread(my $buf, $c->req->content_length); |
|---|
| 72 | is $buf, 'OCTET STREAM'; |
|---|
| 73 | |
|---|
| 74 | === cookie |
|---|
| 75 | --- env |
|---|
| 76 | REMOTE_ADDR: 127.0.0.1 |
|---|
| 77 | SERVER_PORT: 80 |
|---|
| 78 | QUERY_STRING: '' |
|---|
| 79 | REQUEST_METHOD: 'POST' |
|---|
| 80 | HTTP_HOST: localhost |
|---|
| 81 | HTTP_CONTENT_LENGTH: 12 |
|---|
| 82 | HTTP_CONTENT_TYPE: application/octet-stream |
|---|
| 83 | HTTP_COOKIE: foo=hoge; foo=hoge; path=/ |
|---|
| 84 | --- body: OCTET STREAM |
|---|
| 85 | --- test |
|---|
| 86 | is $c->req->cookie('unknown'), undef; |
|---|
| 87 | is $c->req->cookie('foo')->value, 'hoge'; |
|---|
| 88 | |
|---|