Files
factorio-expcluster/exp_server_list/test/module/env.lua
T
bbassieandClaude Opus 5.5 c0289ed8a7 Address review on exp_server_list
The controller and instance plugins are init functions with closures.
The controller batches refreshes with setMany and deleteMany, and the
instance gates updates on its status instead of a started flag.

short_name is now display_name. New always_on_top field sorts servers
first in get_servers. The record carries has_password from the game
password in factorio.settings, never the password itself, and the
description falls back to the one in factorio.settings. A controller
welcome is used when the instance has none, and the readme falls back
to a default welcome from the locale.

Lua gets is_synced for connect.lua. The readme passes an empty detail
instead of nil to the join tooltip so the player count stays in __2__,
restores the Password status, shows the welcome title as a centered
label and shortens long descriptions with the full text as a tooltip.

The Lua tests assert the lookups they index, which fixes the lint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 21:35:33 +00:00

66 lines
2.2 KiB
Lua

--[[-- Test environment for module/control.lua
Extends the shared stubs with a fresh copy of the server list module, a stub
of exp_util storage, and a helper to build the servers the instance plugin
sends.
Run as a chunk by test/lua/runner.js, receiving the shared folder. The suite
returned here becomes `...` in each test file.
]]
local shared_root = ... --- @type string
local source = assert(debug.getinfo(1, "S")).source:gsub("\\", "/")
local plugin_root = assert(source:match("^@(.*)/test/module/env%.lua$"))
local Framework = assert(loadfile(shared_root .. "/framework.lua"))() --- @type Framework
--- @class ExpServerList.TestEnv : Stubs
--- @field ServerList ExpServerList A fresh copy of the server list module
--- @field server fun(id: number, fields: table?): ExpServerList.Server A server as the controller sends it
--- @field connections table[] Calls to connect_to_server, with the player name as `to`
return Framework.suite(function(env)
--- @cast env ExpServerList.TestEnv
env.extend_requires{
["modules/exp_util/storage"] = {
register = function() end,
},
}
env.ServerList = assert(loadfile(plugin_root .. "/module/control.lua"))() --- @type ExpServerList
function env.server(id, fields)
local server = {
id = id,
name = "Server " .. id,
display_name = "S" .. id,
description = "",
welcome = "",
reset_time = "",
hidden = false,
always_on_top = false,
has_password = false,
mod_pack_name = "Base",
factorio_version = "2.1.14",
player_count = 0,
status = "running",
address = "localhost:" .. (34196 + id),
}
for key, value in pairs(fields or {}) do
server[key] = value
end
return server
end
env.connections = {}
local add_player = env.add_player
function env.add_player(params)
local player = add_player(params)
rawset(player, "connect_to_server", function(opts)
opts.to = player.name
env.connections[#env.connections + 1] = opts
end)
return player
end
return env
end)