Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
improved header tests
  • Loading branch information
kraih committed Aug 11, 2012
1 parent 74af25c commit 70cd9bb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 36 deletions.
6 changes: 3 additions & 3 deletions t/mojo/app.t
Expand Up @@ -257,9 +257,9 @@ ok $remote_port > 0, 'has local port';

# Parallel requests
my $delay = Mojo::IOLoop->delay;
$ua->get('/13/', $delay->begin);
$ua->post('/14/' => {Expect => 'fun'}, 'bar baz foo' x 128, $delay->begin);
$ua->get('/15/', $delay->begin);
$ua->get('/13/' => $delay->begin);
$ua->post('/14/' => {Expect => 'fun'} => 'bar baz foo' x 128 => $delay->begin);
$ua->get('/15/' => $delay->begin);
($tx, $tx2, my $tx3) = $delay->wait;
ok $tx->is_finished, 'transaction is finished';
is $tx->res->body, 'Your Mojo is working!', 'right content';
Expand Down
19 changes: 10 additions & 9 deletions t/mojo/transactor.t
Expand Up @@ -30,7 +30,8 @@ is $tx->req->method, 'POST', 'right method';
is $tx->req->headers->expect, 'nothing', 'right "Expect" value';

# POST with header and content
$tx = $t->tx(POST => 'https://mojolicio.us' => {Expect => 'nothing'}, 'test');
$tx
= $t->tx(POST => 'https://mojolicio.us' => {Expect => 'nothing'} => 'test');
is $tx->req->url->to_abs, 'https://mojolicio.us', 'right URL';
is $tx->req->method, 'POST', 'right method';
is $tx->req->headers->expect, 'nothing', 'right "Expect" value';
Expand All @@ -49,7 +50,7 @@ is $tx->req->url->to_abs, 'http://kraih.com/foo', 'right URL';
is $tx->req->method, 'POST', 'right method';
is $tx->req->headers->content_type, 'application/json',
'right "Content-Type" value';
is_deeply $tx->req->json, {test => 123}, 'right content';
is_deeply $tx->req->json, {test => 123} => 'right content';
$tx = $t->json('http://kraih.com/foo', => [1, 2, 3]);
is $tx->req->url->to_abs, 'http://kraih.com/foo', 'right URL';
is $tx->req->method, 'POST', 'right method';
Expand All @@ -64,7 +65,7 @@ is $tx->req->method, 'POST', 'right method';
is $tx->req->headers->dnt, 1, 'right "DNT" value';
is $tx->req->headers->content_type, 'application/json',
'right "Content-Type" value';
is_deeply $tx->req->json, {test => 123}, 'right content';
is_deeply $tx->req->json, {test => 123} => 'right content';

# JSON POST with custom content type
$tx = $t->json(
Expand Down Expand Up @@ -419,8 +420,8 @@ is $tx->res->code, undef, 'no status';
is $tx->res->headers->location, undef, 'no "Location" value';

# 301 redirect with content
$tx
= $t->tx(POST => 'http://mojolico.us/foo' => {Accept => '*/*'}, 'whatever');
$tx = $t->tx(
POST => 'http://mojolico.us/foo' => {Accept => '*/*'} => 'whatever');
$tx->res->code(301);
$tx->res->headers->location('http://kraih.com/bar');
is $tx->req->headers->accept, '*/*', 'right "Accept" value';
Expand Down Expand Up @@ -458,8 +459,8 @@ is $tx->res->code, undef, 'no status';
is $tx->res->headers->location, undef, 'no "Location" value';

# 307 redirect with content
$tx
= $t->tx(POST => 'http://mojolico.us/foo' => {Accept => '*/*'}, 'whatever');
$tx = $t->tx(
POST => 'http://mojolico.us/foo' => {Accept => '*/*'} => 'whatever');
$tx->res->code(307);
$tx->res->headers->location('http://kraih.com/bar');
is $tx->req->headers->accept, '*/*', 'right "Accept" value';
Expand Down Expand Up @@ -525,8 +526,8 @@ is $tx->res->code, undef, 'no status';
is $tx->res->headers->location, undef, 'no "Location" value';

# 308 redirect with content
$tx
= $t->tx(POST => 'http://mojolico.us/foo' => {Accept => '*/*'}, 'whatever');
$tx = $t->tx(
POST => 'http://mojolico.us/foo' => {Accept => '*/*'} => 'whatever');
$tx->res->code(308);
$tx->res->headers->location('http://kraih.com/bar');
is $tx->req->headers->accept, '*/*', 'right "Accept" value';
Expand Down
37 changes: 13 additions & 24 deletions t/mojolicious/lite_app.t
Expand Up @@ -9,7 +9,7 @@ BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}

use Test::More tests => 710;
use Test::More tests => 712;

# "Wait you're the only friend I have...
# You really want a robot for a friend?
Expand Down Expand Up @@ -296,20 +296,11 @@ post '/with/header/condition' => sub {
$self->render_text('foo ' . $self->req->headers->header('X-Secret-Header'));
} => (headers => {'X-Secret-Header' => 'bar'});

# POST /with/body/and/desc
post '/with/body/and/desc' => sub {
# POST /echo/body
post '/echo/body' => sub {
my $self = shift;
return if $self->req->body ne 'body';
$self->render_text('bar');
};

# POST /with/body/and/headers/desc
post '/with/body/and/headers/desc' => sub {
my $self = shift;
return
if $self->req->headers->header('with') ne 'header'
|| $self->req->body ne 'body';
$self->render_text('bar');
$self->res->headers->header(Echo => $self->req->headers->header('Echo'));
$self->render_text($self->req->body);
};

# GET /session_cookie
Expand Down Expand Up @@ -969,22 +960,20 @@ $t->get_ok('/with/header/condition' => {'X-Secret-Header' => 'bar'})
->status_is(404)->content_like(qr/Oops!/);

# POST /with/header/condition
$t->post_ok('/with/header/condition' => {'X-Secret-Header' => 'bar'}, 'bar')
$t->post_ok('/with/header/condition' => {'X-Secret-Header' => 'bar'} => 'bar')
->status_is(200)->content_is('foo bar');

# POST /with/header/condition (missing header)
$t->post_ok('/with/header/condition' => {}, 'bar')->status_is(404)
$t->post_ok('/with/header/condition' => {} => 'bar')->status_is(404)
->content_like(qr/Oops!/);

# POST /with/body/and/desc
$t->post_ok('/with/body/and/desc', 'body', 'desc')->status_is(200)
->content_is('bar');
# POST /echo/body (description and no header)
$t->post_ok('/echo/body' => 'foo' => 'header missing')->status_is(200)
->header_isnt(Echo => 'bar')->content_is('foo');

# POST /with/body/and/headers/and/desc
$t->post_ok(
'/with/body/and/headers/desc' => {with => 'header'},
'body', 'desc'
)->status_is(200)->content_is('bar');
# POST /echo/body (description and header)
$t->post_ok('/echo/body' => {Echo => 'bar'} => 'foo' => 'header present')
->status_is(200)->header_is(Echo => 'bar')->content_is('foo');

# GET /session_cookie
$t->get_ok('/session_cookie')->status_is(200)
Expand Down

0 comments on commit 70cd9bb

Please sign in to comment.