comparison proxy_cache_range.t @ 371:6fb6fea36560

Tests: proxy cache and range filter tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 12 Feb 2014 19:15:42 +0400
parents
children 1d6abf0db011
comparison
equal deleted inserted replaced
370:74cfe56c7b83 371:6fb6fea36560
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Tests for http proxy cache and range filter.
6
7 ###############################################################################
8
9 use warnings;
10 use strict;
11
12 use Test::More;
13
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
15
16 use lib 'lib';
17 use Test::Nginx;
18
19 ###############################################################################
20
21 select STDERR; $| = 1;
22 select STDOUT; $| = 1;
23
24 plan(skip_all => 'win32') if $^O eq 'MSWin32';
25
26 my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(5)
27 ->write_file_expand('nginx.conf', <<'EOF');
28
29 %%TEST_GLOBALS%%
30
31 daemon off;
32
33 events {
34 }
35
36 http {
37 %%TEST_GLOBALS_HTTP%%
38
39 proxy_cache_path %%TESTDIR%%/cache levels=1:2
40 keys_zone=NAME:1m;
41
42 server {
43 listen 127.0.0.1:8080;
44 server_name localhost;
45
46 location / {
47 proxy_pass http://127.0.0.1:8081;
48 proxy_cache NAME;
49 proxy_cache_valid 200 1m;
50 }
51 }
52
53 server {
54 listen 127.0.0.1:8081;
55 server_name localhost;
56
57 location / {
58 }
59 }
60 }
61
62 EOF
63
64 $t->write_file('t.html', 'SEE-THIS');
65 $t->run();
66
67 ###############################################################################
68
69 {
70 local $TODO = 'not yet';
71
72 like(http_get_range('/t.html?1', 'Range: bytes=4-'), qr/^THIS/m,
73 'range on first request');
74 like(http_get_range('/t.html?2', 'Range: bytes=0-2,4-'), qr/^SEE.*^THIS/ms,
75 'multipart range on first request');
76 }
77
78 like(http_get_range('/t.html?1', 'Range: bytes=4-'), qr/^THIS/m,
79 'cached range');
80 like(http_get_range('/t.html?1', 'Range: bytes=0-2,4-'), qr/^SEE.*^THIS/ms,
81 'cached multipart range');
82
83 like(`grep -F '[alert]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no alerts');
84
85 ###############################################################################
86
87 sub http_get_range {
88 my ($url, $extra) = @_;
89 return http(<<EOF);
90 GET $url HTTP/1.1
91 Host: localhost
92 Connection: close
93 $extra
94
95 EOF
96 }
97
98 ###############################################################################