Mercurial > hg > nginx-tests
comparison proxy_cache_variables.t @ 517:b2c3d509b2f9
Tests: proxy_cache with variables.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 24 Dec 2014 14:15:30 +0300 |
parents | |
children | 907e89fba9c3 |
comparison
equal
deleted
inserted
replaced
516:2bc470a58621 | 517:b2c3d509b2f9 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for http proxy cache, proxy_cache directive with variables. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 | |
20 ############################################################################### | |
21 | |
22 select STDERR; $| = 1; | |
23 select STDOUT; $| = 1; | |
24 | |
25 plan(skip_all => 'win32') if $^O eq 'MSWin32'; | |
26 | |
27 my $t = Test::Nginx->new()->has(qw/http proxy cache/) | |
28 ->write_file_expand('nginx.conf', <<'EOF'); | |
29 | |
30 %%TEST_GLOBALS%% | |
31 | |
32 daemon off; | |
33 | |
34 events { | |
35 } | |
36 | |
37 http { | |
38 %%TEST_GLOBALS_HTTP%% | |
39 | |
40 proxy_cache_path %%TESTDIR%%/cache1 levels=1:2 | |
41 keys_zone=NAME1:1m; | |
42 proxy_cache_path %%TESTDIR%%/cache2 levels=1:2 | |
43 keys_zone=NAME2:1m; | |
44 | |
45 server { | |
46 listen 127.0.0.1:8080; | |
47 server_name localhost; | |
48 | |
49 location / { | |
50 proxy_pass http://127.0.0.1:8081; | |
51 | |
52 proxy_cache $arg_c; | |
53 | |
54 proxy_cache_valid any 1m; | |
55 | |
56 add_header X-Cache-Status $upstream_cache_status; | |
57 } | |
58 } | |
59 | |
60 server { | |
61 listen 127.0.0.1:8081; | |
62 server_name localhost; | |
63 | |
64 location / { | |
65 } | |
66 } | |
67 } | |
68 | |
69 EOF | |
70 | |
71 $t->write_file('index.html', 'SEE-THIS'); | |
72 | |
73 $t->try_run('no proxy_cache with variables')->plan(9); | |
74 | |
75 ############################################################################### | |
76 | |
77 like(http_get('/?c=NAME1'), qr/MISS.*SEE-THIS/ms, 'proxy request'); | |
78 like(http_get('/?c=NAME1'), qr/HIT.*SEE-THIS/ms, 'proxy request cached'); | |
79 | |
80 unlike(http_head('/?c=NAME1'), qr/SEE-THIS/, 'head request'); | |
81 | |
82 $t->write_file('index.html', 'SEE-THAT'); | |
83 | |
84 like(http_get('/?c=NAME2'), qr/MISS.*SEE-THAT/ms, 'proxy request 2'); | |
85 like(http_get('/?c=NAME2'), qr/HIT.*SEE-THAT/ms, 'proxy request 2 cached'); | |
86 | |
87 # some invalid cases | |
88 | |
89 like(http_get('/?c=NAME'), qr/ 500 /, 'proxy_cache unknown'); | |
90 like(http_get('/'), qr/(?<!X-Cache).*SEE-THAT/ms, 'proxy_cache empty'); | |
91 | |
92 $t->write_file('index.html', 'SEE-THOSE'); | |
93 | |
94 like(http_get('/'), qr/SEE-THOSE/, 'proxy_cache empty - not cached'); | |
95 | |
96 like(`grep -F '[alert]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no alerts'); | |
97 | |
98 ############################################################################### |