Merge pull request #2830 from ElvinEfendi/remove-lua-mocks

Remove lua mocks
This commit is contained in:
k8s-ci-robot 2018-07-22 03:55:18 -07:00 committed by GitHub
commit 2e34382db6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 25 additions and 71 deletions

View file

@ -1,3 +1,16 @@
#!/usr/bin/env resty
local ffi = require("ffi")
-- without this we get errors such as "attempt to redefine XXX"
local old_cdef = ffi.cdef
local exists = {}
ffi.cdef = function(def)
if exists[def] then
return
end
exists[def] = true
return old_cdef(def)
end
require "busted.runner"({ standalone = false })

View file

@ -18,7 +18,11 @@ set -o errexit
set -o nounset
set -o pipefail
export LUA_PATH="/usr/local/lib/lua/?.lua;;"
export LUA_CPATH="/usr/local/lib/lua/?.so;/usr/lib/lua-platform-path/lua/5.1/?.so;;"
resty ./build/busted ${BUSTED_ARGS} ./rootfs/etc/nginx/lua/test;
resty \
-I ./rootfs/etc/nginx/lua \
-I /usr/local/lib/lua \
-I /usr/lib/lua-platform-path/lua/5.1 \
--shdict "configuration_data 5M" \
--shdict "balancer_ewma 1M" \
--shdict "balancer_ewma_last_touched_at 1M" \
./build/busted ${BUSTED_ARGS} ./rootfs/etc/nginx/lua/test/

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()
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 _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()
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
local _ngx = {
shared = {},
log = function(...) end,
}
_G.ngx = _ngx
local balancer, expected_implementations, backends
local function reset_balancer()
@ -92,10 +85,10 @@ describe("Balancer", function()
local s_old = spy.on(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.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")
-- TODO(elvinefendi) figure out why
-- 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
local defer = require('util.defer')
local _ngx = {
shared = {},
log = function(...) end,
get_phase = function() return "timer" end,
}
_G.ngx = _ngx
local defer = require("util.defer")
describe("Defer", 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
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
local cjson = require("cjson")
describe("Monitor", function()
local monitor = require("monitor")