@@ -24,10 +24,10 @@ our $HttpConfig = <<'_EOC_';
24
24
end
25
25
26
26
if val then
27
- if data.body.kvs==nil then
27
+ if data and data .body.kvs==nil then
28
28
ngx.exit(404)
29
29
end
30
- if data.body.kvs and val ~= data.body.kvs[1].value then
30
+ if data and data .body.kvs and val ~= data.body.kvs[1].value then
31
31
ngx.say("failed to check value")
32
32
ngx.log(ngx.ERR, "failed to check value, got: ", data.body.kvs[1].value,
33
33
", expect: ", val)
@@ -61,6 +61,12 @@ __DATA__
61
61
62
62
local data, err = etcd:get("/test")
63
63
check_res(data, err, "abc")
64
+
65
+ local data, err = etcd:get("")
66
+ check_res(data, nil, err)
67
+
68
+ local data, err = etcd:set("")
69
+ check_res(data, nil, err)
64
70
}
65
71
}
66
72
--- request
69
75
[error]
70
76
--- response_body
71
77
checked val as expect: abc
78
+ checked val as expect: key should not be empty
79
+ checked val as expect: key should not be empty
72
80
73
81
74
82
@@ -166,8 +174,12 @@ timeout/
166
174
local res, err = etcd:set("/wdir", "abc")
167
175
check_res(res, err)
168
176
177
+ ngx.timer.at(0.05, function ()
178
+ etcd:set("/wdir-", "bcd3")
179
+ end)
180
+
169
181
ngx.timer.at(0.1, function ()
170
- etcd:set("/wdir", "bcd4")
182
+ etcd:set("/wdir/ ", "bcd4")
171
183
end)
172
184
173
185
ngx.timer.at(0.2, function ()
@@ -179,7 +191,7 @@ timeout/
179
191
end)
180
192
181
193
local cur_time = ngx.now()
182
- local body_chunk_fun, err = etcd:watchdir("/wdir", {timeout = 1.5})
194
+ local body_chunk_fun, err = etcd:watchdir("/wdir/ ", {timeout = 1.5})
183
195
if not body_chunk_fun then
184
196
ngx.say("failed to watch: ", err)
185
197
end
@@ -213,6 +225,69 @@ timeout/
213
225
--- timeout: 5
214
226
215
227
228
+ === TEST 4.1: watchdir(key=="")
229
+ --- http_config eval: $::HttpConfig
230
+ --- config
231
+ location /t {
232
+ content_by_lua_block {
233
+ local etcd, err = require("resty.etcd").new({protocol = "v3"})
234
+ check_res(etcd, err)
235
+
236
+ local res, err = etcd:set("/wdir", "abc")
237
+ check_res(res, err)
238
+
239
+ ngx.timer.at(0.05, function ()
240
+ etcd:set("/wdir-", "bcd3")
241
+ end)
242
+
243
+ ngx.timer.at(0.1, function ()
244
+ etcd:set("/wdir/", "bcd4")
245
+ end)
246
+
247
+ ngx.timer.at(0.2, function ()
248
+ etcd:set("/wdir/a", "bcd4a")
249
+ end)
250
+
251
+ ngx.timer.at(0.3, function ()
252
+ etcd:delete("/wdir/a")
253
+ end)
254
+
255
+ local cur_time = ngx.now()
256
+ local body_chunk_fun, err = etcd:watchdir("", {timeout = 1.5})
257
+ if not body_chunk_fun then
258
+ ngx.say("failed to watch: ", err)
259
+ end
260
+
261
+ local idx = 0
262
+ while true do
263
+ local chunk, err = body_chunk_fun()
264
+
265
+ if not chunk then
266
+ if err then
267
+ ngx.say(err)
268
+ end
269
+ break
270
+ end
271
+
272
+ idx = idx + 1
273
+ ngx.say(idx, ": ", require("cjson").encode(chunk.result))
274
+ end
275
+ }
276
+ }
277
+ --- request
278
+ GET /t
279
+ --- no_error_log
280
+ [error]
281
+ --- response_body_like eval
282
+ qr/1:.*"created":true.*
283
+ 2:.*"value":"bcd3".*
284
+ 3:.*"value":"bcd4".*
285
+ 4:.*"value":"bcd4a".*
286
+ 5:.*"type":"DELETE".*
287
+ timeout/
288
+ --- timeout: 5
289
+
290
+
216
291
217
292
=== TEST 5: setx(key, val) failed
218
293
--- http_config eval: $::HttpConfig
0 commit comments