@@ -4,7 +4,7 @@ use Test::Nginx::Socket::Lua;
44
55repeat_each(1);
66
7- plan tests => repeat_each() * (blocks() * 2 + 1 );
7+ plan tests => repeat_each() * (blocks() * 3 );
88
99$ENV {TEST_NGINX_MEMCACHED_PORT } ||= 11211;
1010$ENV {TEST_NGINX_MYSQL_PORT } ||= 3306;
@@ -14,9 +14,13 @@ our $http_config = <<'_EOC_';
1414 drizzle_server 127.0.0.1:$TEST_NGINX_MYSQL_PORT protocol=mysql
1515 dbname=ngx_test user=ngx_test password=ngx_test;
1616 }
17+
18+ lua_package_path "../lua-resty-mysql/lib/?.lua;;";
1719_EOC_
1820
1921no_shuffle();
22+ no_long_string();
23+
2024run_tests();
2125
2226__DATA__
@@ -25,51 +29,46 @@ __DATA__
2529--- http_config eval: $::http_config
2630--- config
2731 location = /init {
28- drizzle_pass database;
29- drizzle_query "DROP TABLE IF EXISTS conv_uid";
30- }
31- --- request
32- GET /init
33- --- error_code: 200
34- --- timeout: 10
35- --- no_error_log
36- [error]
37-
38-
39-
40- === TEST 2: conv_uid - create table
41- --- http_config eval: $::http_config
42- --- config
43- location = /init {
44- drizzle_pass database;
45- drizzle_query "CREATE TABLE conv_uid(id serial primary key, new_uid integer, old_uid integer)";
32+ content_by_lua_block {
33+ local mysql = require "resty.mysql"
34+ local db = assert(mysql:new())
35+ local ok, err, errcode, sqlstate = db:connect{
36+ host = "127.0.0.1",
37+ port = $TEST_NGINX_MYSQL_PORT,
38+ database = "ngx_test",
39+ user = "ngx_test",
40+ password = "ngx_test",
41+ charset = "utf8",
42+ }
43+
44+ local queries = {
45+ "DROP TABLE IF EXISTS conv_uid",
46+ "CREATE TABLE conv_uid(id serial primary key, new_uid integer, old_uid integer)",
47+ "INSERT INTO conv_uid(old_uid,new_uid) VALUES(32,56),(35,78)",
48+ }
49+
50+ for _, query in ipairs(queries) do
51+ local ok, err = db:query(query)
52+ if not ok then
53+ ngx.say("failed to run mysql query \"", query, "\": ", err)
54+ return
55+ end
56+ end
57+
58+ ngx.say("done!")
59+ }
4660 }
4761--- request
4862GET /init
49- --- error_code: 200
50- --- timeout: 10
51- --- no_error_log
52- [error]
53-
54-
55-
56- === TEST 3: conv_uid - insert value
57- --- http_config eval: $::http_config
58- --- config
59- location = /init {
60- drizzle_pass database;
61- drizzle_query "INSERT INTO conv_uid(old_uid,new_uid) VALUES(32,56),(35,78)";
62- }
63- --- request
64- GET /init
65- --- error_code: 200
63+ --- response_body
64+ done!
6665--- timeout: 10
6766--- no_error_log
6867[error]
6968
7069
7170
72- === TEST 4 : flush data from memcached
71+ === TEST 2 : flush data from memcached
7372--- config
7473 location /flush {
7574 set $memc_cmd flush_all;
0 commit comments