comparison proxy-cache.t @ 74:3afbba94c8eb

Tests: basic proxy_cache tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 25 Mar 2009 14:12:33 +0300
parents
children 14cf2658592d
comparison
equal deleted inserted replaced
73:c8ba98ad0570 74:3afbba94c8eb
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Tests for http proxy cache.
6
7 ###############################################################################
8
9 use warnings;
10 use strict;
11
12 use Test::More tests => 2;
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 my $t = Test::Nginx->new();
25
26 $t->write_file_expand('nginx.conf', <<'EOF');
27
28 master_process off;
29 daemon off;
30
31 events {
32 }
33
34 http {
35 access_log off;
36 root %%TESTDIR%%;
37
38 client_body_temp_path %%TESTDIR%%/client_body_temp;
39 fastcgi_temp_path %%TESTDIR%%/fastcgi_temp;
40 proxy_temp_path %%TESTDIR%%/proxy_temp;
41
42 proxy_cache_path %%TESTDIR%%/cache levels=1:2
43 keys_zone=NAME:10m
44 inactive=5m clean_time=2h00m;
45
46 server {
47 listen 127.0.0.1:8080;
48 server_name localhost;
49
50 location / {
51 proxy_pass http://127.0.0.1:8081;
52
53 proxy_cache NAME;
54
55 proxy_cache_valid 200 302 1h;
56 proxy_cache_valid 301 1d;
57 proxy_cache_valid any 1m;
58
59 proxy_cache_min_uses 1;
60
61 proxy_cache_use_stale error timeout invalid_header http_500;
62 }
63 }
64 server {
65 listen 127.0.0.1:8081;
66 server_name localhost;
67
68 location / {
69 }
70 }
71 }
72
73 EOF
74
75 $t->write_file('t.html', 'SEE-THIS');
76 $t->run();
77
78 ###############################################################################
79
80 like(http_get('/t.html'), qr/SEE-THIS/, 'proxy request');
81
82 $t->write_file('t.html', 'NOOP');
83 like(http_get('/t.html'), qr/SEE-THIS/, 'proxy request cached');
84
85 ###############################################################################