Skip to content

Commit cb572a0

Browse files
committed
added the tests for the last commit.
1 parent f20e81f commit cb572a0

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

t/content-length.t

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# vi:filetype=
2+
3+
use lib 'lib';
4+
use Test::Nginx::Socket;
5+
6+
#repeat_each(2);
7+
8+
plan tests => repeat_each() * (blocks() * 5);
9+
10+
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
11+
12+
#master_on();
13+
no_shuffle();
14+
15+
run_tests();
16+
17+
__DATA__
18+
19+
=== TEST 1: flush all
20+
--- config
21+
location /flush {
22+
set $memc_cmd 'flush_all';
23+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
24+
}
25+
--- response_headers
26+
Content-Type: text/plain
27+
Content-Length: 4
28+
--- request
29+
GET /flush
30+
--- response_body eval: "OK\r\n"
31+
--- no_error_log
32+
[error]
33+
34+
35+
36+
=== TEST 2: basic fetch (cache miss)
37+
--- config
38+
location /foo {
39+
srcache_fetch GET /memc $uri;
40+
srcache_store PUT /memc $uri;
41+
42+
proxy_pass http://127.0.0.1:$server_port/gate;
43+
}
44+
45+
location = /gate {
46+
default_type text/css;
47+
content_by_lua '
48+
ngx.header.content_length = 10
49+
ngx.say("hello")
50+
';
51+
}
52+
53+
location /memc {
54+
internal;
55+
56+
set $memc_key $query_string;
57+
set $memc_exptime 300;
58+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
59+
}
60+
--- request
61+
GET /foo
62+
--- response_headers
63+
Content-Type: text/css
64+
Content-Length: 10
65+
--- response_body
66+
hello
67+
--- error_log
68+
srcache_store: skipped because response body truncated: 10 < 6
69+
70+
71+
72+
=== TEST 3: basic fetch (cache miss)
73+
--- config
74+
location /foo {
75+
default_type text/css;
76+
srcache_fetch GET /memc $uri;
77+
srcache_store PUT /memc $uri;
78+
79+
echo world;
80+
}
81+
82+
location /memc {
83+
internal;
84+
85+
set $memc_key $query_string;
86+
set $memc_exptime 300;
87+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
88+
}
89+
--- request
90+
GET /foo
91+
--- response_headers
92+
Content-Type: text/css
93+
!Content-Length
94+
--- response_body
95+
world
96+
--- no_error_log
97+
[error]
98+

0 commit comments

Comments
 (0)