cleanup lua tests

This commit is contained in:
Elvin Efendi 2018-07-21 22:36:05 -04:00
parent fe9bb6bee5
commit fcaf337b30
13 changed files with 4 additions and 67 deletions

View file

@ -1,5 +1,3 @@
package.path = "./rootfs/etc/nginx/lua/?.lua;./rootfs/etc/nginx/lua/test/mocks/?.lua;" .. package.path
describe("Balancer chash", function() describe("Balancer chash", function()
local balancer_chash = require("balancer.chash") local balancer_chash = require("balancer.chash")

View file

@ -1,17 +1,5 @@
package.path = "./rootfs/etc/nginx/lua/?.lua;./rootfs/etc/nginx/lua/test/mocks/?.lua;" .. package.path
local util = require("util") local util = require("util")
local _ngx = {
shared = {
balancer_ewma = { flush_all = function() end },
balancer_ewma_last_touched_at = { flush_all = function() end }
},
log = function(...) end,
now = function() return os.time() end,
}
_G.ngx = _ngx
describe("Balancer ewma", function() describe("Balancer ewma", function()
local balancer_ewma = require("balancer.ewma") local balancer_ewma = require("balancer.ewma")

View file

@ -1,12 +1,5 @@
package.path = "./rootfs/etc/nginx/lua/?.lua;./rootfs/etc/nginx/lua/test/mocks/?.lua;" .. package.path
_G._TEST = true _G._TEST = true
local _ngx = {
shared = {},
log = function(...) end,
}
_G.ngx = _ngx
local balancer, expected_implementations, backends local balancer, expected_implementations, backends
local function reset_balancer() local function reset_balancer()
@ -92,10 +85,10 @@ describe("Balancer", function()
local s_old = spy.on(implementation, "new") local s_old = spy.on(implementation, "new")
local s = spy.on(new_implementation, "new") local s = spy.on(new_implementation, "new")
local s_ngx_log = spy.on(_G.ngx, "log") local s_ngx_log = spy.on(ngx, "log")
assert.has_no.errors(function() balancer.sync_backend(backend) end) assert.has_no.errors(function() balancer.sync_backend(backend) end)
assert.spy(s_ngx_log).was_called_with(ngx.ERR, assert.spy(s_ngx_log).was_called_with(ngx.INFO,
"LB algorithm changed from round_robin to ewma, resetting the instance") "LB algorithm changed from round_robin to ewma, resetting the instance")
-- TODO(elvinefendi) figure out why -- TODO(elvinefendi) figure out why
-- assert.spy(s).was_called_with(new_implementation, backend) does not work here -- assert.spy(s).was_called_with(new_implementation, backend) does not work here

View file

@ -1,13 +1,5 @@
package.path = "./rootfs/etc/nginx/lua/?.lua;./rootfs/etc/nginx/lua/test/mocks/?.lua;" .. package.path
_G._TEST = true _G._TEST = true
local defer = require('util.defer') local defer = require("util.defer")
local _ngx = {
shared = {},
log = function(...) end,
get_phase = function() return "timer" end,
}
_G.ngx = _ngx
describe("Defer", function() describe("Defer", function()
describe("to_timer_phase", function() describe("to_timer_phase", function()

View file

@ -1 +0,0 @@
return {}

View file

@ -1,3 +0,0 @@
return {
new = function(self, nodes) return {} end
}

View file

@ -1 +0,0 @@
return {}

View file

@ -1,3 +0,0 @@
return {
new = function(self, name, ...) return {} end,
}

View file

@ -1 +0,0 @@
return {}

View file

@ -1,3 +0,0 @@
return {
new = function(self, nodes) return {} end
}

View file

@ -1 +0,0 @@
return {}

View file

@ -1 +0,0 @@
return {}

View file

@ -1,25 +1,5 @@
package.path = "./rootfs/etc/nginx/lua/?.lua;./rootfs/etc/nginx/lua/test/mocks/?.lua;" .. package.path
_G._TEST = true _G._TEST = true
local cjson = require('cjson') local cjson = require("cjson")
local function udp_mock()
return {
setpeername = function(...) return true end,
send = function(payload) return payload end,
close = function(...) return true end
}
end
local _ngx = {
shared = {},
log = function(...) end,
socket = {
udp = udp_mock
},
get_phase = function() return "timer" end,
var = {}
}
_G.ngx = _ngx
describe("Monitor", function() describe("Monitor", function()
local monitor = require("monitor") local monitor = require("monitor")