|
| 1 | +# vi:filetype=perl |
| 2 | + |
| 3 | +use lib 'lib'; |
| 4 | +use Test::Nginx::Socket; |
| 5 | + |
| 6 | +repeat_each(1); |
| 7 | + |
| 8 | +plan tests => repeat_each() * (blocks() * 3 + 3 * 1); |
| 9 | + |
| 10 | +our $http_config = <<'_EOC_'; |
| 11 | + proxy_cache_path /tmp/ngx_cache_purge keys_zone=test_cache:10m; |
| 12 | +
|
| 13 | + server { |
| 14 | + listen 8100; |
| 15 | +
|
| 16 | + location / { |
| 17 | + root /etc; |
| 18 | + } |
| 19 | + } |
| 20 | +_EOC_ |
| 21 | + |
| 22 | +our $config = <<'_EOC_'; |
| 23 | + location /proxy { |
| 24 | + proxy_pass http://127.0.0.1:8100/; |
| 25 | + proxy_cache test_cache; |
| 26 | + proxy_cache_key $uri$is_args$args; |
| 27 | + proxy_cache_valid 3m; |
| 28 | + add_header X-Cache-Status $upstream_cache_status; |
| 29 | + } |
| 30 | +
|
| 31 | + location ~ /purge(/.*) { |
| 32 | + proxy_cache_purge test_cache $1$is_args$args; |
| 33 | + } |
| 34 | +_EOC_ |
| 35 | + |
| 36 | +worker_connections(128); |
| 37 | +no_shuffle(); |
| 38 | +run_tests(); |
| 39 | + |
| 40 | +no_diff(); |
| 41 | + |
| 42 | +__DATA__ |
| 43 | +
|
| 44 | +=== TEST 1: prepare |
| 45 | +--- http_config eval: $::http_config |
| 46 | +--- config eval: $::config |
| 47 | +--- request |
| 48 | +GET /proxy/passwd |
| 49 | +--- error_code: 200 |
| 50 | +--- response_headers |
| 51 | +Content-Type: text/plain |
| 52 | +--- response_body_like: root |
| 53 | +--- timeout: 10 |
| 54 | +
|
| 55 | +
|
| 56 | +
|
| 57 | +=== TEST 2: get from cache |
| 58 | +--- http_config eval: $::http_config |
| 59 | +--- config eval: $::config |
| 60 | +--- request |
| 61 | +GET /proxy/passwd |
| 62 | +--- error_code: 200 |
| 63 | +--- response_headers |
| 64 | +Content-Type: text/plain |
| 65 | +X-Cache-Status: HIT |
| 66 | +--- response_body_like: root |
| 67 | +--- timeout: 10 |
| 68 | +
|
| 69 | +
|
| 70 | +
|
| 71 | +=== TEST 3: purge from cache |
| 72 | +--- http_config eval: $::http_config |
| 73 | +--- config eval: $::config |
| 74 | +--- request |
| 75 | +DELETE /purge/proxy/passwd |
| 76 | +--- error_code: 200 |
| 77 | +--- response_headers |
| 78 | +Content-Type: text/html |
| 79 | +--- response_body_like: Successful purge |
| 80 | +--- timeout: 10 |
| 81 | +
|
| 82 | +
|
| 83 | +
|
| 84 | +=== TEST 4: purge from empty cache |
| 85 | +--- http_config eval: $::http_config |
| 86 | +--- config eval: $::config |
| 87 | +--- request |
| 88 | +DELETE /purge/proxy/passwd |
| 89 | +--- error_code: 404 |
| 90 | +--- response_headers |
| 91 | +Content-Type: text/html |
| 92 | +--- response_body_like: 404 Not Found |
| 93 | +--- timeout: 10 |
| 94 | +
|
| 95 | +
|
| 96 | +
|
| 97 | +=== TEST 5: get from source |
| 98 | +--- http_config eval: $::http_config |
| 99 | +--- config eval: $::config |
| 100 | +--- request |
| 101 | +GET /proxy/passwd |
| 102 | +--- error_code: 200 |
| 103 | +--- response_headers |
| 104 | +Content-Type: text/plain |
| 105 | +X-Cache-Status: MISS |
| 106 | +--- response_body_like: root |
| 107 | +--- timeout: 10 |
| 108 | +
|
| 109 | +
|
| 110 | +
|
| 111 | +=== TEST 6: get from cache (again) |
| 112 | +--- http_config eval: $::http_config |
| 113 | +--- config eval: $::config |
| 114 | +--- request |
| 115 | +GET /proxy/passwd |
| 116 | +--- error_code: 200 |
| 117 | +--- response_headers |
| 118 | +Content-Type: text/plain |
| 119 | +X-Cache-Status: HIT |
| 120 | +--- response_body_like: root |
| 121 | +--- timeout: 10 |
0 commit comments