Tests for commands.lua + fix few mistakes
This commit is contained in:
parent
b30ed8ddec
commit
e0cd0bd369
@ -38,17 +38,17 @@ minetest.register_chatcommand("qos:clear", {
|
||||
description = "Return current QoS queue utilization percentage value",
|
||||
privs = { [QoS.config("admin_priv")] = true },
|
||||
func = function(name, priority)
|
||||
if priority:find("%S") then
|
||||
if priority and priority:find("%S") then
|
||||
local i = tonumber(priority)
|
||||
if i and QoS.data.queues[i] then
|
||||
local length = QoS.data.queues[i]
|
||||
local length = QoS.data.queues[i].count
|
||||
QoS.data.queues[i]:clear()
|
||||
minetest.chat_send_player(name, ("QoS cleared %d priority %d entries"):format(length, i))
|
||||
else
|
||||
minetest.chat_send_player(name, "QoS clear: invalid priority, double check your input")
|
||||
end
|
||||
else
|
||||
for i, queue in ipairs() do
|
||||
for i, queue in ipairs(QoS.data.queues) do
|
||||
local length = queue.count
|
||||
queue:clear()
|
||||
minetest.chat_send_player(name, ("QoS cleared %d priority %d entries"):format(length, i))
|
||||
|
63
spec/command_spec.lua
Normal file
63
spec/command_spec.lua
Normal file
@ -0,0 +1,63 @@
|
||||
require("mineunit")
|
||||
|
||||
mineunit("core")
|
||||
|
||||
mineunit("common/chatcommands")
|
||||
|
||||
sourcefile("init")
|
||||
|
||||
describe("Queue initialization", function()
|
||||
|
||||
it("executes qos:queue_length", function()
|
||||
local func = minetest.registered_chatcommands["qos:queue_length"].func
|
||||
|
||||
spy.on(minetest, "chat_send_player")
|
||||
func("SX")
|
||||
assert.spy(minetest.chat_send_player).was.called(1)
|
||||
|
||||
spy.on(minetest, "chat_send_player")
|
||||
func("SX", "1")
|
||||
assert.spy(minetest.chat_send_player).was.called(1)
|
||||
end)
|
||||
|
||||
it("executes qos:active_requests", function()
|
||||
local func = minetest.registered_chatcommands["qos:active_requests"].func
|
||||
|
||||
spy.on(minetest, "chat_send_player")
|
||||
func("SX")
|
||||
assert.spy(minetest.chat_send_player).was.called(1)
|
||||
end)
|
||||
|
||||
it("executes qos:active_utilization", function()
|
||||
local func = minetest.registered_chatcommands["qos:active_utilization"].func
|
||||
|
||||
spy.on(minetest, "chat_send_player")
|
||||
func("SX")
|
||||
assert.spy(minetest.chat_send_player).was.called(1)
|
||||
end)
|
||||
|
||||
it("executes qos:utilization", function()
|
||||
local func = minetest.registered_chatcommands["qos:utilization"].func
|
||||
|
||||
spy.on(minetest, "chat_send_player")
|
||||
func("SX")
|
||||
assert.spy(minetest.chat_send_player).was.called(1)
|
||||
|
||||
spy.on(minetest, "chat_send_player")
|
||||
func("SX", "1")
|
||||
assert.spy(minetest.chat_send_player).was.called(1)
|
||||
end)
|
||||
|
||||
it("executes qos:clear", function()
|
||||
local func = minetest.registered_chatcommands["qos:clear"].func
|
||||
|
||||
spy.on(minetest, "chat_send_player")
|
||||
func("SX")
|
||||
assert.spy(minetest.chat_send_player).was.called(3)
|
||||
|
||||
spy.on(minetest, "chat_send_player")
|
||||
func("SX", "1")
|
||||
assert.spy(minetest.chat_send_player).was.called(1)
|
||||
end)
|
||||
|
||||
end)
|
Loading…
x
Reference in New Issue
Block a user