|
| 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_POSTGRESQL_HOST_IPV6} ||= '[::1]'; |
| 11 | +$ENV{TEST_NGINX_POSTGRESQL_PORT} ||= 5432; |
| 12 | + |
| 13 | +our $http_config = <<'_EOC_'; |
| 14 | + upstream database { |
| 15 | + postgres_server $TEST_NGINX_POSTGRESQL_HOST_IPV6:$TEST_NGINX_POSTGRESQL_PORT |
| 16 | + dbname=ngx_test user=ngx_test password=ngx_test; |
| 17 | + } |
| 18 | +_EOC_ |
| 19 | + |
| 20 | +run_tests(); |
| 21 | + |
| 22 | +__DATA__ |
| 23 | +
|
| 24 | +=== TEST 1: sanity |
| 25 | +--- http_config |
| 26 | + upstream database { |
| 27 | + postgres_server $TEST_NGINX_POSTGRESQL_HOST_IPV6:$TEST_NGINX_POSTGRESQL_PORT |
| 28 | + dbname=ngx_test user=ngx_test password=ngx_test; |
| 29 | + postgres_keepalive off; |
| 30 | + } |
| 31 | +--- config |
| 32 | + location /postgres { |
| 33 | + postgres_pass database; |
| 34 | + postgres_query "select * from cats"; |
| 35 | + } |
| 36 | +--- request |
| 37 | +GET /postgres |
| 38 | +--- error_code: 200 |
| 39 | +--- response_headers |
| 40 | +Content-Type: application/x-resty-dbd-stream |
| 41 | +--- response_body eval |
| 42 | +"\x{00}". # endian |
| 43 | +"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3 |
| 44 | +"\x{00}". # result type |
| 45 | +"\x{00}\x{00}". # std errcode |
| 46 | +"\x{02}\x{00}". # driver errcode |
| 47 | +"\x{00}\x{00}". # driver errstr len |
| 48 | +"". # driver errstr data |
| 49 | +"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected |
| 50 | +"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id |
| 51 | +"\x{02}\x{00}". # col count |
| 52 | +"\x{09}\x{00}". # std col type (integer/int) |
| 53 | +"\x{17}\x{00}". # driver col type |
| 54 | +"\x{02}\x{00}". # col name len |
| 55 | +"id". # col name data |
| 56 | +"\x{06}\x{80}". # std col type (varchar/str) |
| 57 | +"\x{19}\x{00}". # driver col type |
| 58 | +"\x{04}\x{00}". # col name len |
| 59 | +"name". # col name data |
| 60 | +"\x{01}". # valid row flag |
| 61 | +"\x{01}\x{00}\x{00}\x{00}". # field len |
| 62 | +"2". # field data |
| 63 | +"\x{ff}\x{ff}\x{ff}\x{ff}". # field len |
| 64 | +"". # field data |
| 65 | +"\x{01}". # valid row flag |
| 66 | +"\x{01}\x{00}\x{00}\x{00}". # field len |
| 67 | +"3". # field data |
| 68 | +"\x{03}\x{00}\x{00}\x{00}". # field len |
| 69 | +"bob". # field data |
| 70 | +"\x{00}" # row list terminator |
| 71 | +--- timeout: 10 |
| 72 | +--- no_error_log |
| 73 | +[alert] |
| 74 | +[error] |
| 75 | +
|
| 76 | +
|
| 77 | +
|
| 78 | +=== TEST 2: keep-alive |
| 79 | +--- http_config |
| 80 | + upstream database { |
| 81 | + postgres_server $TEST_NGINX_POSTGRESQL_HOST_IPV6:$TEST_NGINX_POSTGRESQL_PORT |
| 82 | + dbname=ngx_test user=ngx_test password=ngx_test; |
| 83 | + } |
| 84 | +--- config |
| 85 | + location /postgres { |
| 86 | + postgres_pass database; |
| 87 | + postgres_query "select * from cats"; |
| 88 | + } |
| 89 | +
|
| 90 | + location /t { |
| 91 | + echo_location /postgres; |
| 92 | + echo_location /postgres; |
| 93 | + echo_location /postgres; |
| 94 | + } |
| 95 | +--- request |
| 96 | +GET /postgres |
| 97 | +--- error_code: 200 |
| 98 | +--- response_headers |
| 99 | +Content-Type: application/x-resty-dbd-stream |
| 100 | +--- response_body eval |
| 101 | +( |
| 102 | +"\x{00}". # endian |
| 103 | +"\x{03}\x{00}\x{00}\x{00}". # format version 0.0.3 |
| 104 | +"\x{00}". # result type |
| 105 | +"\x{00}\x{00}". # std errcode |
| 106 | +"\x{02}\x{00}". # driver errcode |
| 107 | +"\x{00}\x{00}". # driver errstr len |
| 108 | +"". # driver errstr data |
| 109 | +"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # rows affected |
| 110 | +"\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}\x{00}". # insert id |
| 111 | +"\x{02}\x{00}". # col count |
| 112 | +"\x{09}\x{00}". # std col type (integer/int) |
| 113 | +"\x{17}\x{00}". # driver col type |
| 114 | +"\x{02}\x{00}". # col name len |
| 115 | +"id". # col name data |
| 116 | +"\x{06}\x{80}". # std col type (varchar/str) |
| 117 | +"\x{19}\x{00}". # driver col type |
| 118 | +"\x{04}\x{00}". # col name len |
| 119 | +"name". # col name data |
| 120 | +"\x{01}". # valid row flag |
| 121 | +"\x{01}\x{00}\x{00}\x{00}". # field len |
| 122 | +"2". # field data |
| 123 | +"\x{ff}\x{ff}\x{ff}\x{ff}". # field len |
| 124 | +"". # field data |
| 125 | +"\x{01}". # valid row flag |
| 126 | +"\x{01}\x{00}\x{00}\x{00}". # field len |
| 127 | +"3". # field data |
| 128 | +"\x{03}\x{00}\x{00}\x{00}". # field len |
| 129 | +"bob". # field data |
| 130 | +"\x{00}" # row list terminator |
| 131 | +) x 3 |
| 132 | +--- timeout: 10 |
| 133 | +--- no_error_log |
| 134 | +[alert] |
| 135 | +[error] |
| 136 | +
|
0 commit comments