refactor balancer into more testable and extensible interface
This commit is contained in:
parent
1b5db4b3b0
commit
e9dc275b81
20 changed files with 368 additions and 467 deletions
|
|
@ -1,6 +1,31 @@
|
|||
local cwd = io.popen("pwd"):read('*l')
|
||||
package.path = cwd .. "/rootfs/etc/nginx/lua/?.lua;" .. package.path
|
||||
package.path = "./rootfs/etc/nginx/lua/?.lua;./rootfs/etc/nginx/lua/test/mocks/?.lua;" .. package.path
|
||||
|
||||
describe("[chash_test]", function()
|
||||
-- TODO(elvinefendi) add unit tests
|
||||
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" }}
|
||||
|
||||
local resty_chash = package.loaded["resty.chash"]
|
||||
resty_chash.new = function(self, nodes)
|
||||
return {
|
||||
find = function(self, key)
|
||||
assert.equal("/alma/armud", key)
|
||||
return "10.184.7.40:8080"
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
local backend = {
|
||||
name = "my-dummy-backend", ["upstream-hash-by"] = "$request_uri",
|
||||
endpoints = { { address = "10.184.7.40", port = "8080", maxFails = 0, failTimeout = 0 } }
|
||||
}
|
||||
local instance = balancer_chash:new(backend)
|
||||
|
||||
local host, port = instance:balance()
|
||||
assert.equal("10.184.7.40", host)
|
||||
assert.equal("8080", port)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue