From 7b3a0f64d29e0e4b4cac360850f63bd6efd38223 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Sat, 14 Sep 2024 10:26:52 +0800 Subject: [PATCH] with_current_ws --- spec/helpers.lua | 10 +--------- spec/internal/misc.lua | 12 ++++++++++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/spec/helpers.lua b/spec/helpers.lua index 6de7fdd4c4c8..39b1701f3fc0 100644 --- a/spec/helpers.lua +++ b/spec/helpers.lua @@ -1686,15 +1686,7 @@ end -- Only use in CLI tests from spec/02-integration/01-cmd kill_all = cmd.kill_all, - with_current_ws = function(ws,fn, db) - local old_ws = ngx.ctx.workspace - ngx.ctx.workspace = nil - ws = ws or {db.workspaces:select_by_name("default")} - ngx.ctx.workspace = ws[1] and ws[1].id - local res = fn() - ngx.ctx.workspace = old_ws - return res - end, + with_current_ws = misc.with_current_ws, signal = cmd.signal, diff --git a/spec/internal/misc.lua b/spec/internal/misc.lua index 93e57123756d..3de9a19ed0c1 100644 --- a/spec/internal/misc.lua +++ b/spec/internal/misc.lua @@ -230,6 +230,17 @@ local function lookup(t, k) end +local function with_current_ws(ws,fn, db) + local old_ws = ngx.ctx.workspace + ngx.ctx.workspace = nil + ws = ws or {db.workspaces:select_by_name("default")} + ngx.ctx.workspace = ws[1] and ws[1].id + local res = fn() + ngx.ctx.workspace = old_ws + return res +end + + local make_temp_dir do local seeded = false @@ -320,6 +331,7 @@ return { lookup = lookup, + with_current_ws = with_current_ws, make_temp_dir = make_temp_dir, use_old_plugin = use_old_plugin, }