Enable lj-releng tool to lint lua code.
This commit is contained in:
parent
36f7dd2e0b
commit
bafbd4cccf
36 changed files with 213 additions and 93 deletions
|
|
@ -1,9 +1,15 @@
|
|||
function mock_ngx(mock)
|
||||
local _ngx = mock
|
||||
setmetatable(_ngx, {__index = _G.ngx})
|
||||
_G.ngx = _ngx
|
||||
end
|
||||
|
||||
describe("Balancer chash", function()
|
||||
local balancer_chash = require("balancer.chash")
|
||||
|
||||
describe("balance()", function()
|
||||
it("uses correct key for given backend", function()
|
||||
_G.ngx = { var = { request_uri = "/alma/armud" }}
|
||||
mock_ngx({var = { request_uri = "/alma/armud"}})
|
||||
local balancer_chash = require("balancer.chash")
|
||||
|
||||
local resty_chash = package.loaded["resty.chash"]
|
||||
resty_chash.new = function(self, nodes)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,8 @@
|
|||
function mock_ngx(mock)
|
||||
local _ngx = mock
|
||||
setmetatable(_ngx, {__index = _G.ngx})
|
||||
_G.ngx = _ngx
|
||||
end
|
||||
|
||||
local function get_test_backend(n_endpoints)
|
||||
local backend = {
|
||||
|
|
@ -18,11 +23,15 @@ local function get_test_backend(n_endpoints)
|
|||
end
|
||||
|
||||
describe("Balancer chash subset", function()
|
||||
local balancer_chashsubset = require("balancer.chashsubset")
|
||||
local balancer_chashsubset
|
||||
|
||||
before_each(function()
|
||||
mock_ngx({ var = { request_uri = "/alma/armud" }})
|
||||
balancer_chashsubset = require("balancer.chashsubset")
|
||||
end)
|
||||
|
||||
describe("balance()", function()
|
||||
it("returns peers from the same subset", function()
|
||||
_G.ngx = { var = { request_uri = "/alma/armud" }}
|
||||
|
||||
local backend = get_test_backend(9)
|
||||
|
||||
|
|
@ -67,7 +76,6 @@ describe("Balancer chash subset", function()
|
|||
end)
|
||||
describe("new(backend)", function()
|
||||
it("fills last subset correctly", function()
|
||||
_G.ngx = { var = { request_uri = "/alma/armud" }}
|
||||
|
||||
local backend = get_test_backend(7)
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ describe("Balancer ewma", function()
|
|||
|
||||
before_each(function()
|
||||
mock_ngx({ now = function() return ngx_now end, var = { balancer_ewma_score = -1 } })
|
||||
package.loaded["balancer.ewma"] = nil
|
||||
balancer_ewma = require("balancer.ewma")
|
||||
|
||||
backend = {
|
||||
name = "namespace-service-port", ["load-balance"] = "ewma",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
local sticky_balanced = require("balancer.sticky_balanced")
|
||||
local sticky_persistent = require("balancer.sticky_persistent")
|
||||
local sticky_balanced
|
||||
local sticky_persistent
|
||||
local cookie = require("resty.cookie")
|
||||
local util = require("util")
|
||||
|
||||
|
|
@ -15,6 +15,14 @@ local function reset_ngx()
|
|||
_G.ngx = original_ngx
|
||||
end
|
||||
|
||||
local function reset_sticky_balancer()
|
||||
package.loaded["balancer.sticky"] = nil
|
||||
package.loaded["balancer.sticky_balanced"] = nil
|
||||
package.loaded["balancer.sticky_persistent"] = nil
|
||||
sticky_balanced = require("balancer.sticky_balanced")
|
||||
sticky_persistent = require("balancer.sticky_persistent")
|
||||
end
|
||||
|
||||
function get_mocked_cookie_new()
|
||||
local o = { value = nil }
|
||||
local mock = {
|
||||
|
|
@ -47,6 +55,7 @@ end
|
|||
describe("Sticky", function()
|
||||
before_each(function()
|
||||
mock_ngx({ var = { location_path = "/", host = "test.com" } })
|
||||
reset_sticky_balancer()
|
||||
end)
|
||||
|
||||
after_each(function()
|
||||
|
|
@ -302,11 +311,8 @@ describe("Sticky", function()
|
|||
local mocked_cookie_new = cookie.new
|
||||
|
||||
before_each(function()
|
||||
package.loaded["balancer.sticky_balanced"] = nil
|
||||
package.loaded["balancer.sticky_persistent"] = nil
|
||||
sticky_balanced = require("balancer.sticky_balanced")
|
||||
sticky_persistent = require("balancer.sticky_persistent")
|
||||
mock_ngx({ var = { location_path = "/", host = "test.com" } })
|
||||
reset_sticky_balancer()
|
||||
end)
|
||||
|
||||
after_each(function()
|
||||
|
|
@ -459,6 +465,7 @@ describe("Sticky", function()
|
|||
end)
|
||||
it("returns a cookie without SameSite=None when user specifies samesite None and conditional samesite none with unsupported user agent", function()
|
||||
mock_ngx({ var = { location_path = "/", host = "test.com" , http_user_agent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"} })
|
||||
reset_sticky_balancer()
|
||||
test_set_cookie(sticky_balanced, "None", true, "/", nil)
|
||||
end)
|
||||
end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue