|
| 1 | +# vi:filetype= |
| 2 | + |
| 3 | +use lib 'lib'; |
| 4 | +use Test::Nginx::Socket; |
| 5 | + |
| 6 | +#repeat_each(2); |
| 7 | + |
| 8 | +plan tests => repeat_each() * 2 * blocks(); |
| 9 | + |
| 10 | +$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211; |
| 11 | + |
| 12 | +no_shuffle(); |
| 13 | + |
| 14 | +run_tests(); |
| 15 | + |
| 16 | +__DATA__ |
| 17 | +
|
| 18 | +=== TEST 1: flush all |
| 19 | +--- config |
| 20 | + location /flush { |
| 21 | + set $memc_cmd 'flush_all'; |
| 22 | + memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT; |
| 23 | + } |
| 24 | +--- request |
| 25 | +GET /flush |
| 26 | +--- response_body eval: "OK\r\n" |
| 27 | +
|
| 28 | +
|
| 29 | +
|
| 30 | +=== TEST 2: skip is false |
| 31 | +--- config |
| 32 | + location /foo { |
| 33 | + default_type text/css; |
| 34 | + srcache_fetch GET /memc $uri; |
| 35 | + set $skip ''; |
| 36 | + srcache_fetch_skip $skip; |
| 37 | +
|
| 38 | + echo hello; |
| 39 | + } |
| 40 | +
|
| 41 | + location /memc { |
| 42 | + internal; |
| 43 | +
|
| 44 | + set $memc_cmd set; |
| 45 | + set $memc_key key; |
| 46 | + set $memc_value hello; |
| 47 | + set $memc_value 'hello'; |
| 48 | + set $memc_exptime 300; |
| 49 | + memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT; |
| 50 | + } |
| 51 | +--- request |
| 52 | + GET /foo |
| 53 | +--- response_body |
| 54 | +hello |
| 55 | +
|
| 56 | +
|
| 57 | +
|
| 58 | +=== TEST 3: check if /memc was invoked (just equal) |
| 59 | +--- config |
| 60 | + location /memc { |
| 61 | + set $memc_cmd get; |
| 62 | + set $memc_key key; |
| 63 | + set $memc_value hello; |
| 64 | + memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT; |
| 65 | + } |
| 66 | +--- request |
| 67 | + GET /memc |
| 68 | +--- response_body chomp |
| 69 | +hello |
| 70 | +
|
| 71 | +
|
| 72 | +
|
| 73 | +=== TEST 4: flush all |
| 74 | +--- config |
| 75 | + location /flush { |
| 76 | + set $memc_cmd 'flush_all'; |
| 77 | + memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT; |
| 78 | + } |
| 79 | +--- request |
| 80 | +GET /flush |
| 81 | +--- response_body eval: "OK\r\n" |
| 82 | +
|
| 83 | +
|
| 84 | +
|
| 85 | +=== TEST 5: fetch_skip is literally false |
| 86 | +--- config |
| 87 | + location /foo { |
| 88 | + default_type text/css; |
| 89 | + srcache_fetch GET /memc $uri; |
| 90 | + srcache_fetch_skip 0; |
| 91 | +
|
| 92 | + echo hello; |
| 93 | + } |
| 94 | +
|
| 95 | + location /memc { |
| 96 | + internal; |
| 97 | +
|
| 98 | + set $memc_cmd set; |
| 99 | + set $memc_key key; |
| 100 | + set $memc_value hello; |
| 101 | + set $memc_exptime 300; |
| 102 | + memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT; |
| 103 | + } |
| 104 | +--- request |
| 105 | + GET /foo |
| 106 | +--- response_body |
| 107 | +hello |
| 108 | +
|
| 109 | +
|
| 110 | +
|
| 111 | +=== TEST 6: check if /memc was invoked (less than) |
| 112 | +--- config |
| 113 | + location /memc { |
| 114 | + set $memc_cmd get; |
| 115 | + set $memc_key key; |
| 116 | + set $memc_value hello; |
| 117 | + memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT; |
| 118 | + } |
| 119 | +--- request |
| 120 | + GET /memc |
| 121 | +--- response_body chomp |
| 122 | +hello |
| 123 | +
|
| 124 | +
|
| 125 | +
|
| 126 | +=== TEST 7: flush all |
| 127 | +--- config |
| 128 | + location /flush { |
| 129 | + set $memc_cmd 'flush_all'; |
| 130 | + memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT; |
| 131 | + } |
| 132 | +--- request |
| 133 | +GET /flush |
| 134 | +--- response_body eval: "OK\r\n" |
| 135 | +
|
| 136 | +
|
| 137 | +
|
| 138 | +=== TEST 8: fetch_skip is true |
| 139 | +--- config |
| 140 | + location /foo { |
| 141 | + default_type text/css; |
| 142 | + srcache_fetch GET /memc $uri; |
| 143 | + srcache_fetch_skip 1; |
| 144 | +
|
| 145 | + echo hello; |
| 146 | + } |
| 147 | +
|
| 148 | + location /memc { |
| 149 | + internal; |
| 150 | +
|
| 151 | + set $memc_cmd set; |
| 152 | + set $memc_key key; |
| 153 | + set $memc_value hello; |
| 154 | + set $memc_exptime 300; |
| 155 | + memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT; |
| 156 | + } |
| 157 | +--- request |
| 158 | + GET /foo |
| 159 | +--- response_body |
| 160 | +hello |
| 161 | +
|
| 162 | +
|
| 163 | +
|
| 164 | +=== TEST 9: check if /memc was invoked (more than) |
| 165 | +--- config |
| 166 | + location /memc { |
| 167 | + set $memc_cmd get; |
| 168 | + set $memc_key key; |
| 169 | + set $memc_value hello; |
| 170 | + memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT; |
| 171 | + } |
| 172 | +--- request |
| 173 | + GET /memc |
| 174 | +--- response_body_like: 404 Not Found |
| 175 | +--- error_code: 404 |
| 176 | +
|
| 177 | +
|
| 178 | +
|
| 179 | +=== TEST 10: flush all |
| 180 | +--- config |
| 181 | + location /flush { |
| 182 | + set $memc_cmd 'flush_all'; |
| 183 | + memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT; |
| 184 | + } |
| 185 | +--- request |
| 186 | +GET /flush |
| 187 | +--- response_body eval: "OK\r\n" |
| 188 | +
|
| 189 | +
|
| 190 | +
|
| 191 | +=== TEST 11: explicit "true" string |
| 192 | +--- config |
| 193 | + location /foo.txt { |
| 194 | + default_type text/css; |
| 195 | + srcache_fetch GET /memc $uri; |
| 196 | + srcache_fetch_skip true; |
| 197 | + } |
| 198 | +
|
| 199 | + location /memc { |
| 200 | + internal; |
| 201 | +
|
| 202 | + set $memc_cmd set; |
| 203 | + set $memc_key key; |
| 204 | + set $memc_value hello; |
| 205 | + set $memc_exptime 300; |
| 206 | + memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT; |
| 207 | + } |
| 208 | +--- user_files |
| 209 | +>>> foo.txt |
| 210 | +hello |
| 211 | +--- request |
| 212 | + GET /foo.txt |
| 213 | +--- response_body |
| 214 | +hello |
| 215 | +
|
| 216 | +
|
| 217 | +
|
| 218 | +=== TEST 12: check if /memc was invoked (explicit "true" string) |
| 219 | +--- config |
| 220 | + location /memc { |
| 221 | + set $memc_cmd get; |
| 222 | + set $memc_key key; |
| 223 | + set $memc_value hello; |
| 224 | + memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT; |
| 225 | + } |
| 226 | +--- request |
| 227 | + GET /memc |
| 228 | +--- response_body_like: 404 Not Found |
| 229 | +--- error_code: 404 |
| 230 | +
|
| 231 | +
|
| 232 | +
|
| 233 | +=== TEST 13: flush all |
| 234 | +--- config |
| 235 | + location /flush { |
| 236 | + set $memc_cmd 'flush_all'; |
| 237 | + memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT; |
| 238 | + } |
| 239 | +--- request |
| 240 | +GET /flush |
| 241 | +--- response_body eval: "OK\r\n" |
| 242 | +
|
| 243 | +
|
| 244 | +
|
| 245 | +=== TEST 14: server-side config |
| 246 | +--- config |
| 247 | + srcache_fetch_skip 1; |
| 248 | + location /foo.txt { |
| 249 | + default_type text/css; |
| 250 | + srcache_fetch GET /memc $uri; |
| 251 | + } |
| 252 | +
|
| 253 | + location /memc { |
| 254 | + internal; |
| 255 | +
|
| 256 | + set $memc_cmd set; |
| 257 | + set $memc_key key; |
| 258 | + set $memc_value hello; |
| 259 | + set $memc_exptime 300; |
| 260 | + memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT; |
| 261 | + } |
| 262 | +--- user_files |
| 263 | +>>> foo.txt |
| 264 | +abc |
| 265 | +--- request |
| 266 | + GET /foo.txt |
| 267 | +--- response_body |
| 268 | +abc |
| 269 | +
|
| 270 | +
|
| 271 | +
|
| 272 | +=== TEST 15: check if /memc was invoked (server-level config) |
| 273 | +--- config |
| 274 | + location /memc { |
| 275 | + set $memc_cmd get; |
| 276 | + set $memc_key key; |
| 277 | + set $memc_value hello; |
| 278 | + memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT; |
| 279 | + } |
| 280 | +--- request |
| 281 | + GET /memc |
| 282 | +--- response_body_like: 404 Not Found |
| 283 | +--- error_code: 404 |
| 284 | +
|
| 285 | +
|
| 286 | +
|
| 287 | +=== TEST 16: flush all |
| 288 | +--- config |
| 289 | + location /flush { |
| 290 | + set $memc_cmd 'flush_all'; |
| 291 | + memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT; |
| 292 | + } |
| 293 | +--- request |
| 294 | +GET /flush |
| 295 | +--- response_body eval: "OK\r\n" |
| 296 | +
|
| 297 | +
|
| 298 | +
|
| 299 | +=== TEST 17: overriding server-side config |
| 300 | +--- config |
| 301 | + srcache_fetch_skip 1; |
| 302 | + location /foo.txt { |
| 303 | + default_type text/css; |
| 304 | + srcache_fetch GET /memc $uri; |
| 305 | + srcache_fetch_skip 0; |
| 306 | + } |
| 307 | +
|
| 308 | + location /memc { |
| 309 | + internal; |
| 310 | +
|
| 311 | + set $memc_cmd set; |
| 312 | + set $memc_key key; |
| 313 | + set $memc_value hello; |
| 314 | + set $memc_exptime 300; |
| 315 | + memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT; |
| 316 | + } |
| 317 | +--- user_files |
| 318 | +>>> foo.txt |
| 319 | +hello, world |
| 320 | +--- request |
| 321 | + GET /foo.txt |
| 322 | +--- response_body |
| 323 | +hello, world |
| 324 | +
|
| 325 | +
|
| 326 | +
|
| 327 | +=== TEST 18: check if /memc was invoked (overriding server config) |
| 328 | +--- config |
| 329 | + location /memc { |
| 330 | + set $memc_cmd get; |
| 331 | + set $memc_key key; |
| 332 | + set $memc_value hello; |
| 333 | + memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT; |
| 334 | + } |
| 335 | +--- request |
| 336 | + GET /memc |
| 337 | +--- response_body chomp |
| 338 | +hello |
| 339 | +
|
0 commit comments