Skip to content

Commit 4641530

Browse files
committed
Test 307 308 status codes
1 parent 98792a5 commit 4641530

File tree

1 file changed

+166
-1
lines changed

1 file changed

+166
-1
lines changed

t/status.t

Lines changed: 166 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use lib 'lib';
44
use Test::Nginx::Socket;
55

6-
plan tests => repeat_each() * 97;
6+
plan tests => repeat_each() * 124;
77

88
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
99

@@ -559,3 +559,168 @@ Content-Type: text/html
559559
--- response_body_like: 404 Not Found
560560
--- error_code: 404
561561
562+
563+
564+
=== TEST 26: basic fetch (cache 308 by default)
565+
--- config
566+
location /foo {
567+
default_type text/css;
568+
srcache_fetch GET /memc $uri;
569+
srcache_store PUT /memc $uri;
570+
571+
content_by_lua '
572+
ngx.redirect("/bah", 308)
573+
';
574+
}
575+
576+
location /memc {
577+
internal;
578+
579+
set $memc_key $query_string;
580+
set $memc_exptime 300;
581+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
582+
}
583+
--- request
584+
GET /foo HTTP/1.0
585+
--- response_headers
586+
Content-Type: text/html
587+
--- response_body_like: 308 Permanent Redirect
588+
--- error_code: 308
589+
590+
591+
592+
=== TEST 27: inspect the cached item
593+
--- config
594+
location /memc {
595+
set $memc_key "/foo";
596+
set $memc_exptime 300;
597+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
598+
}
599+
--- request
600+
GET /memc
601+
--- response_headers
602+
Content-Type: text/html
603+
--- response_headers
604+
Content-Type: text/plain
605+
--- response_body_like
606+
^HTTP/1\.1 308 Permanent Redirect\r
607+
Content-Type: text/html\r
608+
Location: /bah\r
609+
\r
610+
.*?308 Permanent Redirect.*
611+
612+
613+
614+
=== TEST 28: flush all
615+
--- config
616+
location /flush {
617+
set $memc_cmd 'flush_all';
618+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
619+
}
620+
--- response_headers
621+
Content-Type: text/plain
622+
Content-Length: 4
623+
!Foo-Bar
624+
--- request
625+
GET /flush
626+
--- response_body eval: "OK\r\n"
627+
628+
629+
630+
=== TEST 29: basic fetch (cache 307 by default)
631+
--- config
632+
location /foo {
633+
default_type text/css;
634+
srcache_fetch GET /memc $uri;
635+
srcache_store PUT /memc $uri;
636+
637+
content_by_lua '
638+
ngx.redirect("/bah", 307)
639+
';
640+
}
641+
642+
location /memc {
643+
internal;
644+
645+
set $memc_key $query_string;
646+
set $memc_exptime 300;
647+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
648+
}
649+
--- request
650+
GET /foo HTTP/1.0
651+
--- response_headers
652+
Content-Type: text/html
653+
Location: /bah
654+
--- response_body_like: 307 Temporary Redirect
655+
--- error_code: 307
656+
657+
658+
659+
=== TEST 30: inspect the cached item
660+
--- config
661+
location /memc {
662+
set $memc_key "/foo";
663+
set $memc_exptime 300;
664+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
665+
}
666+
--- request
667+
GET /memc
668+
--- response_headers
669+
Content-Type: text/html
670+
--- response_headers
671+
Content-Type: text/plain
672+
--- response_body_like
673+
^HTTP/1\.1 307 Temporary Redirect\r
674+
Content-Type: text/html\r
675+
Location: /bah\r
676+
\r
677+
.*?307 Temporary Redirect.*
678+
679+
680+
681+
=== TEST 31: cache hit
682+
--- config
683+
location /foo {
684+
default_type text/css;
685+
srcache_fetch GET /memc $uri;
686+
srcache_store PUT /memc $uri;
687+
srcache_store_statuses 303 304;
688+
689+
content_by_lua '
690+
ngx.say("hi")
691+
';
692+
}
693+
694+
location /memc {
695+
internal;
696+
697+
set $memc_key $query_string;
698+
set $memc_exptime 300;
699+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
700+
}
701+
--- request
702+
GET /foo HTTP/1.0
703+
--- response_headers
704+
Content-Type: text/html
705+
Location: /bah
706+
--- response_body_like: 307 Temporary Redirect
707+
--- error_code: 307
708+
709+
710+
711+
=== TEST 32: flush all
712+
--- config
713+
location /flush {
714+
set $memc_cmd 'flush_all';
715+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
716+
}
717+
--- response_headers
718+
Content-Type: text/plain
719+
Content-Length: 4
720+
!Foo-Bar
721+
--- request
722+
GET /flush
723+
--- response_body eval: "OK\r\n"
724+
725+
726+

0 commit comments

Comments
 (0)