/
os-getenv-hup.t
141 lines (110 loc) · 2.86 KB
/
os-getenv-hup.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# vim:set ft= ts=4 sw=4 et fdm=marker:
our $SkipReason;
BEGIN {
if ($ENV{TEST_NGINX_CHECK_LEAK}) {
$SkipReason = "unavailable for the hup tests";
} else {
undef $ENV{TEST_NGINX_USE_STAP};
}
}
use lib '.';
use t::TestCore::Stream $SkipReason ? (skip_all => $SkipReason) : ();
plan tests => repeat_each() * (blocks() * 2 + 1);
no_shuffle();
use_hup();
$ENV{TEST_NGINX_BAR} = 'old';
$ENV{TEST_NGINX_LUA_PACKAGE_PATH} = "$t::TestCore::Stream::lua_package_path";
run_tests();
__DATA__
=== TEST 1: env directive explicit value is visible within init_by_lua*
--- main_config
env FOO=old;
--- stream_config
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
init_by_lua_block {
require "resty.core"
package.loaded.foo = os.getenv("FOO")
}
--- stream_server_config
content_by_lua_block {
ngx.say(package.loaded.foo)
}
--- stream_response
old
--- error_log
[notice]
=== TEST 2: HUP reload changes env value (1/3)
--- main_config
env FOO=new;
--- stream_config
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
init_by_lua_block {
require "resty.core"
package.loaded.foo = os.getenv("FOO")
}
--- stream_server_config
content_by_lua_block {
ngx.say(package.loaded.foo)
}
--- stream_response
new
=== TEST 3: HUP reload changes env value (2/3)
--- main_config
env FOO=;
--- stream_config
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
init_by_lua_block {
require "resty.core"
package.loaded.foo = os.getenv("FOO")
}
--- stream_server_config
content_by_lua_block {
ngx.say(package.loaded.foo)
}
--- stream_response_like chomp
\s
=== TEST 4: HUP reload changes env value (3/3)
--- main_config
env FOO;
--- stream_config
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
init_by_lua_block {
require "resty.core"
package.loaded.foo = os.getenv("FOO")
}
--- stream_server_config
content_by_lua_block {
ngx.say(package.loaded.foo)
}
--- stream_response
nil
=== TEST 5: HUP reload changes visible environment variable (1/2)
--- main_config
env TEST_NGINX_BAR;
--- stream_config
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
init_by_lua_block {
require "resty.core"
package.loaded.test_nginx_bar = os.getenv("TEST_NGINX_BAR")
}
--- stream_server_config
content_by_lua_block {
ngx.say(package.loaded.test_nginx_bar)
}
--- stream_response
old
=== TEST 6: HUP reload changes visible environment variable (2/2)
--- main_config
env TEST_NGINX_BAR=new;
--- stream_config
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH";
init_by_lua_block {
require "resty.core"
package.loaded.test_nginx_bar = os.getenv("TEST_NGINX_BAR")
}
--- stream_server_config
content_by_lua_block {
ngx.say(package.loaded.test_nginx_bar)
}
--- stream_response
new