1# vi:filetype= 2 3use lib 'lib'; 4use Test::Nginx::Socket; 5 6repeat_each(1); 7 8plan tests => repeat_each() * blocks(); 9 10$ENV{TEST_NGINX_POSTGRESQL_PORT} ||= 5432; 11$ENV{TEST_NGINX_POSTGRESQL_HOST} ||= '127.0.0.1'; 12 13$ENV{TEST_NGINX_MYSQL_HOST} ||= '127.0.0.1'; 14$ENV{TEST_NGINX_MYSQL_PORT} ||= 3306; 15 16our $http_config = <<'_EOC_'; 17 upstream database { 18 drizzle_server $TEST_NGINX_MYSQL_HOST:$TEST_NGINX_MYSQL_PORT protocol=mysql 19 dbname=ngx_test user=ngx_test password=ngx_test; 20 } 21_EOC_ 22 23our $http_config2 = <<'_EOC_'; 24 upstream database { 25 postgres_server $TEST_NGINX_POSTGRESQL_HOST:$TEST_NGINX_POSTGRESQL_PORT 26 dbname=ngx_test user=ngx_test password=ngx_test; 27 } 28_EOC_ 29 30worker_connections(128); 31no_shuffle(); 32run_tests(); 33 34no_diff(); 35 36__DATA__ 37 38=== TEST 1: cats - drop table 39--- http_config eval: $::http_config 40--- config 41 location = /init { 42 drizzle_pass database; 43 drizzle_query "DROP TABLE IF EXISTS cats"; 44 } 45--- request 46GET /init 47--- error_code: 200 48--- timeout: 10 49 50 51 52=== TEST 2: cats - create table 53--- http_config eval: $::http_config 54--- config 55 location = /init { 56 drizzle_pass database; 57 drizzle_query "CREATE TABLE cats (id integer, name text)"; 58 } 59--- request 60GET /init 61--- error_code: 200 62--- timeout: 10 63 64 65 66=== TEST 3: cats - insert value 67--- http_config eval: $::http_config 68--- config 69 location = /init { 70 drizzle_pass database; 71 drizzle_query "INSERT INTO cats (id) VALUES (2)"; 72 } 73--- request 74GET /init 75--- error_code: 200 76--- timeout: 10 77 78 79 80=== TEST 4: cats - insert value 81--- http_config eval: $::http_config 82--- config 83 location = /init { 84 drizzle_pass database; 85 drizzle_query "INSERT INTO cats (id, name) VALUES (3, 'bob')"; 86 } 87--- request 88GET /init 89--- error_code: 200 90--- timeout: 10 91 92 93 94=== TEST 5: dogs - drop table 95--- http_config eval: $::http_config 96--- config 97 location = /init { 98 drizzle_pass database; 99 drizzle_query "DROP TABLE IF EXISTS dogs"; 100 } 101--- request 102GET /init 103--- error_code: 200 104--- timeout: 10 105 106 107 108=== TEST 6: dogs - create table 109--- http_config eval: $::http_config 110--- config 111 location = /init { 112 drizzle_pass database; 113 drizzle_query "CREATE TABLE dogs (male boolean, name text, height real)"; 114 } 115--- request 116GET /init 117--- error_code: 200 118--- timeout: 10 119 120 121 122=== TEST 7: dogs - insert values 123--- http_config eval: $::http_config 124--- config 125 location = /init { 126 drizzle_pass database; 127 drizzle_query " 128INSERT INTO dogs (male, name, height) 129VALUES 130 (false, 'hello \"tom', 3.14), 131 (true, 'hi,ya', -3), 132 (false, 'hey\\ndad', 7), 133 (false, '\\rkay', 0.005), 134 (false, 'ab;c', 0.005), 135 (false, 'foo\\tbar', 21);"; 136 } 137--- request 138GET /init 139--- error_code: 200 140--- timeout: 10 141 142 143 144=== TEST 8: birds - drop table 145--- http_config eval: $::http_config 146--- config 147 location = /init { 148 drizzle_pass database; 149 drizzle_query "DROP TABLE IF EXISTS birds"; 150 } 151--- request 152GET /init 153--- error_code: 200 154--- timeout: 10 155 156 157 158=== TEST 9: birds - create table 159--- http_config eval: $::http_config 160--- config 161 location = /init { 162 drizzle_pass database; 163 drizzle_query "CREATE TABLE birds (`\"name\"` text, height real)"; 164 } 165--- request 166GET /init 167--- error_code: 200 168--- timeout: 10 169 170 171 172=== TEST 10: birds - insert values 173--- http_config eval: $::http_config 174--- config 175 location = /init { 176 drizzle_pass database; 177 drizzle_query " 178INSERT INTO birds (`\"name\"`, height) 179VALUES 180 ('hello \"tom', 3.14), 181 ('hi,ya', -3), 182 ('hey\\ndad', 7), 183 ('\\rkay', 0.005), 184 ('ab;c', 0.005), 185 ('foo\\tbar', 21);"; 186 } 187--- request 188GET /init 189--- error_code: 200 190--- timeout: 10 191 192 193 194=== TEST 11: cats - drop table 195--- http_config eval: $::http_config2 196--- config 197 location = /init { 198 postgres_pass database; 199 postgres_query "DROP TABLE cats"; 200 error_page 500 = /ignore; 201 } 202 203 location /ignore { echo "ignore"; } 204--- request 205GET /init 206--- error_code: 200 207--- timeout: 10 208 209 210 211=== TEST 12: cats - create table 212--- http_config eval: $::http_config2 213--- config 214 location = /init { 215 postgres_pass database; 216 postgres_query "CREATE TABLE cats (id integer, name text)"; 217 } 218--- request 219GET /init 220--- error_code: 200 221--- timeout: 10 222 223 224 225=== TEST 13: cats - insert value 226--- http_config eval: $::http_config2 227--- config 228 location = /init { 229 postgres_pass database; 230 postgres_query "INSERT INTO cats (id) VALUES (2)"; 231 } 232--- request 233GET /init 234--- error_code: 200 235--- timeout: 10 236 237 238 239=== TEST 14: cats - insert value 240--- http_config eval: $::http_config2 241--- config 242 location = /init { 243 postgres_pass database; 244 postgres_query "INSERT INTO cats (id, name) VALUES (3, 'bob')"; 245 } 246--- request 247GET /init 248--- error_code: 200 249--- timeout: 10 250 251