1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
|
# vi:filetype=
use lib 'lib';
use Test::Nginx::Socket;
repeat_each(2);
plan tests => repeat_each() * (2 * blocks() + 3);
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
#no_diff;
no_shuffle;
run_tests();
__DATA__
=== TEST 1: set flags and get flags
--- config
location /flags {
echo 'set foo BAR (flag: 1234567890)';
echo_subrequest PUT '/memc?key=foo&flags=1234567890' -b BAR;
echo 'get foo';
echo_subrequest GET '/memc?key=foo';
}
location /memc {
echo_before_body "status: $echo_response_status";
echo_before_body "flags: $memc_flags";
set $memc_key $arg_key;
set $memc_flags $arg_flags;
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
}
--- request
GET /flags
--- response_body eval
"set foo BAR (flag: 1234567890)
status: 201
flags: 1234567890
STORED\r
get foo
status: 200
flags: 1234567890
BAR"
=== TEST 2: test empty flags (default to 0)
--- config
location /flags {
echo 'set foo BAR (flag: EMPTY)';
echo_subrequest PUT '/memc?key=foo' -b BAR;
echo 'get foo';
echo_subrequest GET '/memc?key=foo';
}
location /memc {
echo_before_body "status: $echo_response_status";
echo_before_body "flags: $memc_flags";
set $memc_key $arg_key;
set $memc_flags $arg_flags;
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
}
--- request
GET /flags
--- response_body eval
"set foo BAR (flag: EMPTY)
status: 201
flags: 0
STORED\r
get foo
status: 200
flags: 0
BAR"
=== TEST 3: test empty flags (default to 0) (another form)
--- config
location /flags {
echo 'set foo BAR (flag: EMPTY)';
echo_subrequest PUT '/memc?key=foo&flags=' -b BAR;
echo 'get foo';
echo_subrequest GET '/memc?key=foo';
}
location /memc {
echo_before_body "status: $echo_response_status";
echo_before_body "flags: $memc_flags";
set $memc_key $arg_key;
set $memc_flags $arg_flags;
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
}
--- request
GET /flags
--- response_body eval
"set foo BAR (flag: EMPTY)
status: 201
flags: 0
STORED\r
get foo
status: 200
flags: 0
BAR"
=== TEST 4: add flags and get flags
--- config
location /flags {
echo 'flush_all';
echo_subrequest GET '/memc?cmd=flush_all';
echo 'add foo BAR (flag: 54321)';
echo_subrequest POST '/memc?key=foo&flags=54321' -b BAR;
echo 'get foo';
echo_subrequest GET '/memc?key=foo';
}
location /memc {
echo_before_body "status: $echo_response_status";
echo_before_body "flags: $memc_flags";
set $memc_cmd $arg_cmd;
set $memc_key $arg_key;
set $memc_flags $arg_flags;
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
}
--- request
GET /flags
--- response_body eval
"flush_all
status: 200
flags:
OK\r
add foo BAR (flag: 54321)
status: 201
flags: 54321
STORED\r
get foo
status: 200
flags: 54321
BAR"
=== TEST 5: set invalid flags
--- config
location /allow {
set $memc_cmd 'set';
set $memc_key 'foo';
set $memc_value 'nice';
set $memc_flags 'invalid';
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
}
--- request
GET /allow
--- response_body_like: 400 Bad Request
--- error_code: 400
--- error_log
variable "$memc_flags" takes invalid value: invalid,
=== TEST 6: set negative flags
--- config
location /allow {
set $memc_cmd 'set';
set $memc_key 'sun';
set $memc_value 'tree';
set $memc_flags '-1';
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
}
--- request
GET /allow
--- response_body_like: 400 Bad Request
--- error_code: 400
=== TEST 7: set flags and get flags in http time
--- config
location /flags {
echo 'set foo BAR (flag: 1264680563)';
echo_subrequest PUT '/memc?key=foo&flags=1264680563' -b BAR;
echo 'get foo';
echo_subrequest GET '/memc?key=foo';
}
location /memc {
echo_before_body "status: $echo_response_status";
echo_before_body "flags: $memc_flags $memc_flags_as_http_time";
set $memc_key $arg_key;
set $memc_flags $arg_flags;
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
}
--- request
GET /flags
--- response_body eval
"set foo BAR (flag: 1264680563)
status: 201
flags: 1264680563 Thu, 28 Jan 2010 12:09:23 GMT
STORED\r
get foo
status: 200
flags: 1264680563 Thu, 28 Jan 2010 12:09:23 GMT
BAR"
=== TEST 8: last-modified (conditional GET)
--- SKIP
--- config
location /memc {
set $memc_key $arg_key;
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
memc_flags_to_last_modified on;
add_header X-Flags $memc_flags;
}
--- request
GET /memc?key=foo
--- more_headers
If-Modified-Since: Thu, 28 Jan 2010 12:09:23 GMT
--- response_headers
Last-Modified: Thu, 28 Jan 2010 12:09:23 GMT
X-Flags: 1264680563
--- error_code: 304
--- response_body:
=== TEST 9: last-modified (unconditional GET)
--- config
location /memc {
set $memc_key $arg_key;
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
memc_flags_to_last_modified on;
add_header X-Flags $memc_flags;
}
--- request
GET /memc?key=foo
--- response_headers
Last-Modified: Thu, 28 Jan 2010 12:09:23 GMT
X-Flags: 1264680563
--- error_code: 200
--- response_body: BAR
|