Skip to content

Commit

Permalink
more range tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 20, 2012
1 parent 6c03571 commit 68d81d6
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions t/mojolicious/static_lite_app.t
Expand Up @@ -28,29 +28,35 @@ $t->get_ok('/hello.txt' => {Range => 'bytes=2-8'})->status_is(206)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->header_is('Accept-Ranges' => 'bytes')->header_is('Content-Length' => 7)
->header_is('Content-Range: bytes 2-8/31')->content_is('llo Moj');
->header_is('Content-Range' => 'bytes 2-8/31')->content_is('llo Moj');

# GET /hello.txt (partial static file, no end)
$t->get_ok('/hello.txt' => {Range => 'bytes=8-'})->status_is(206)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->header_is('Accept-Ranges' => 'bytes')->header_is('Content-Length' => 23)
->header_is('Content-Range: bytes 8-31/31')
->header_is('Content-Range' => 'bytes 8-30/31')
->content_is("jo from a static file!\n");

# GET /hello.txt (partial static file, starting at first byte)
$t->get_ok('/hello.txt' => {Range => 'bytes=0-8'})->status_is(206)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->header_is('Accept-Ranges' => 'bytes')->header_is('Content-Length' => 9)
->header_is('Content-Range: bytes 0-8/31')->content_is('Hello Moj');
->header_is('Content-Range' => 'bytes 0-8/31')->content_is('Hello Moj');

# GET /hello.txt (partial static file, first byte)
$t->get_ok('/hello.txt' => {Range => 'bytes=0-0'})->status_is(206)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->header_is('Accept-Ranges' => 'bytes')->header_is('Content-Length' => 1)
->header_is('Content-Range: bytes 0-0/31')->content_is('H');
->header_is('Content-Range' => 'bytes 0-0/31')->content_is('H');

# GET /hello.txt (partial static file, invalid range)
$t->get_ok('/hello.txt' => {Range => 'bytes=32-33'})->status_is(416)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->header_is('Accept-Ranges' => 'bytes')->content_is('');

# GET /hello3.txt (render_static and single byte file)
$t->get_ok('/hello3.txt')->status_is(200)
Expand All @@ -64,7 +70,7 @@ $t->get_ok('/hello3.txt' => {Range => 'bytes=0-0'})->status_is(206)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->header_is('Accept-Ranges' => 'bytes')->header_is('Content-Length' => 1)
->header_is('Content-Range: bytes 0-0/1')->content_is('X');
->header_is('Content-Range' => 'bytes 0-0/1')->content_is('X');

# GET /static.txt (base64 static inline file, If-Modified-Since)
my $modified = Mojo::Date->new->epoch(time - 3600);
Expand Down Expand Up @@ -96,10 +102,17 @@ $t->get_ok('/static.txt' => {'If-Modified-Since' => $modified})

# GET /static.txt (base64 partial inline file)
$t->get_ok('/static.txt' => {Range => 'bytes=2-5'})->status_is(206)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->header_is('Accept-Ranges' => 'bytes')
->header_is('Content-Range' => 'bytes 2-5/15')
->header_is('Content-Length' => 4)->content_is('st 1');

# GET /static.txt (base64 partial inline file, invalid range)
$t->get_ok('/static.txt' => {Range => 'bytes=45-50'})->status_is(416)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->header_is('Accept-Ranges' => 'bytes')->header_is('Content-Length' => 4)
->content_is('st 1');
->header_is('Accept-Ranges' => 'bytes')->content_is('');

done_testing();

Expand Down

0 comments on commit 68d81d6

Please sign in to comment.