@@ -2,7 +2,7 @@ use Test::Nginx::Socket::Lua;
2
2
3
3
repeat_each(2);
4
4
5
- plan tests => repeat_each() * (blocks() * 3 );
5
+ plan tests => repeat_each() * (blocks() * 2 );
6
6
7
7
$ENV {TEST_NGINX_HTML_DIR } ||= html_dir();
8
8
my $html_dir = $ENV {TEST_NGINX_HTML_DIR };
@@ -15,6 +15,8 @@ my $http_config = <<_EOC_;
15
15
}
16
16
http {
17
17
init_by_lua_block {
18
+ -- if the code in the init_by_lua* is run, there
19
+ -- will be a string contains the 'error'
18
20
ngx.log(ngx.ERR, "run init_by_lua")
19
21
}
20
22
}
@@ -74,6 +76,49 @@ __DATA__
74
76
return
75
77
end
76
78
79
+ local out, err = p:read('*a')
80
+ if not out then
81
+ ngx.log(ngx.ERR, err)
82
+
83
+ else
84
+ ngx.log(ngx.WARN, out)
85
+ end
86
+ }
87
+ }
88
+ --- no_error_log eval
89
+ qr/\[error\] .+ (?!:nginx.pid" failed \(2: No such file or directory\))$/
90
+
91
+
92
+
93
+ === TEST 2: ensure init_by_lua* is not run when testing Nginx configuration
94
+ --- config
95
+ location = /t {
96
+ content_by_lua_block {
97
+ local conf_file = set_up_ngx_tmp_conf()
98
+ local nginx = get_ngx_bin_path()
99
+
100
+ local cmd = nginx .. " -p $TEST_NGINX_HTML_DIR -c " .. conf_file .. " -t"
101
+ local p, err = io.popen(cmd)
102
+ if not p then
103
+ ngx.log(ngx.ERR, err)
104
+ return
105
+ end
106
+
107
+ local out, err = p:read('*a')
108
+ if not out then
109
+ ngx.log(ngx.ERR, err)
110
+
111
+ else
112
+ ngx.log(ngx.WARN, out)
113
+ end
114
+
115
+ local cmd = nginx .. " -p $TEST_NGINX_HTML_DIR -c " .. conf_file .. " -T"
116
+ local p, err = io.popen(cmd)
117
+ if not p then
118
+ ngx.log(ngx.ERR, err)
119
+ return
120
+ end
121
+
77
122
local out, err = p:read('*a')
78
123
if not out then
79
124
ngx.log(ngx.ERR, err)
@@ -84,5 +129,4 @@ __DATA__
84
129
}
85
130
}
86
131
--- no_error_log
87
- [error] .+ (?!:nginx.pid" failed \(2: No such file or directory\))
88
- run init_by_lua
132
+ [error]
0 commit comments