Skip to content

Commit f2c9621

Browse files
committed
added loc-if.t to test directives used in location if blocks.
1 parent 0a436fb commit f2c9621

File tree

2 files changed

+109
-1
lines changed

2 files changed

+109
-1
lines changed

src/ngx_postgres_module.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ static ngx_command_t ngx_postgres_module_commands[] = {
8282
NULL },
8383

8484
{ ngx_string("postgres_output"),
85-
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE123,
85+
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|
86+
NGX_HTTP_LIF_CONF|NGX_CONF_TAKE123,
8687
ngx_postgres_conf_output,
8788
NGX_HTTP_LOC_CONF_OFFSET,
8889
0,

test/t/loc-if.t

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# vi:filetype=perl
2+
3+
use lib 'lib';
4+
use Test::Nginx::Socket;
5+
6+
#repeat_each(2);
7+
repeat_each(1);
8+
9+
plan tests => repeat_each() * (blocks() * 3);
10+
11+
our $http_config = <<'_EOC_';
12+
upstream database {
13+
postgres_server 127.0.0.1:5432 dbname=ngx_test
14+
user=ngx_test password=ngx_test;
15+
}
16+
_EOC_
17+
18+
worker_connections(128);
19+
run_tests();
20+
21+
no_diff();
22+
23+
__DATA__
24+
25+
=== TEST 1: postgres_pass and postgres_query work in location if blocks
26+
--- http_config
27+
upstream database {
28+
postgres_server 127.0.0.1:5432 dbname=ngx_test
29+
user=ngx_test password=ngx_test;
30+
postgres_keepalive off;
31+
}
32+
--- config
33+
location /postgres {
34+
if ($arg_foo) {
35+
postgres_pass database;
36+
postgres_query "select * from cats";
37+
break;
38+
}
39+
40+
return 404;
41+
}
42+
--- request
43+
GET /postgres?foo=1
44+
--- error_code: 200
45+
--- response_headers
46+
Content-Type: application/x-resty-dbd-stream
47+
--- response_body eval
48+
"\x{00}". # endian
49+
"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3
50+
"\x{00}". # result type
51+
"\x{00}\x{00}". # std errcode
52+
"\x{02}\x{00}". # driver errcode
53+
"\x{00}\x{00}". # driver errstr len
54+
"". # driver errstr data
55+
"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected
56+
"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id
57+
"\x{02}\x{00}". # col count
58+
"\x{09}\x{00}". # std col type (integer/int)
59+
"\x{17}\x{00}". # driver col type
60+
"\x{02}\x{00}". # col name len
61+
"id". # col name data
62+
"\x{06}\x{80}". # std col type (varchar/str)
63+
"\x{19}\x{00}". # driver col type
64+
"\x{04}\x{00}". # col name len
65+
"name". # col name data
66+
"\x{01}". # valid row flag
67+
"\x{01}\x{00}\x{00}\x{00}". # field len
68+
"2". # field data
69+
"\x{ff}\x{ff}\x{ff}\x{ff}". # field len
70+
"". # field data
71+
"\x{01}". # valid row flag
72+
"\x{01}\x{00}\x{00}\x{00}". # field len
73+
"3". # field data
74+
"\x{03}\x{00}\x{00}\x{00}". # field len
75+
"bob". # field data
76+
"\x{00}" # row list terminator
77+
--- timeout: 10
78+
79+
80+
81+
=== TEST 1: postgres_pass and postgres_query work in location if blocks
82+
--- http_config
83+
upstream database {
84+
postgres_server 127.0.0.1:5432 dbname=ngx_test
85+
user=ngx_test password=ngx_test;
86+
postgres_keepalive off;
87+
}
88+
--- config
89+
location /postgres {
90+
default_type text/plain;
91+
if ($arg_foo) {
92+
postgres_pass database;
93+
postgres_query "select * from cats order by id";
94+
postgres_output value 0 0;
95+
break;
96+
}
97+
98+
return 404;
99+
}
100+
--- request
101+
GET /postgres?foo=1
102+
--- error_code: 200
103+
--- response_headers
104+
Content-Type: text/plain
105+
--- response_body chomp
106+
2
107+

0 commit comments

Comments
 (0)