mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-09-22 01:04:01 +00:00
Address review on the stubs and controller tests
- The controller tests run against a real Controller, which is side effect free while not started, with real users through its UserManager. The only fakes left are two spies which record broadcasts and permission pushes on their way through. Since any user update also applies auto assignment, the leave event is observed directly rather than through a role change. - raise_event fills in the name and tick of the event the way factorio does, rather than wrapping the payload, and game.players finds players by index as well as by name through a metatable. - names is generic over anything with a name property, so it lives on the suite; the save and load helper no longer calls on_load, the test calls the handler itself as it does for the other handlers. - Sent messages and events are compared whole with deep_eq, which pins the event shape, the tick, and that the unassign key is absent rather than empty. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
7adcdde9dc
commit
e6552a39be
@@ -101,6 +101,18 @@ function Framework.new_suite(make_env)
|
||||
Suite.check(deep_equal(a, b), name, ("%s ~= %s"):format(repr(a, 1), repr(b, 1)))
|
||||
end
|
||||
|
||||
--- Names of an array of values with a name property, such as roles,
|
||||
--- players, forces, or events
|
||||
--- @param values { name: string }[]
|
||||
--- @return string[]
|
||||
function Suite.names(values)
|
||||
local rtn = {}
|
||||
for index, value in ipairs(values) do
|
||||
rtn[index] = value.name
|
||||
end
|
||||
return rtn
|
||||
end
|
||||
|
||||
--- Sorted copy of an array of strings
|
||||
function Suite.sorted(list)
|
||||
local rtn = {}
|
||||
|
||||
+12
-5
@@ -65,7 +65,10 @@ function Stubs.new()
|
||||
return next_event_id
|
||||
end,
|
||||
raise_event = function(id, data)
|
||||
stubs.events[#stubs.events + 1] = { id = id, data = data }
|
||||
-- Factorio fills in the name and tick of the event
|
||||
data.name = id
|
||||
data.tick = game.tick
|
||||
stubs.events[#stubs.events + 1] = data
|
||||
end,
|
||||
register_metatable = function(_, metatable)
|
||||
registered_metatables[metatable] = true
|
||||
@@ -79,13 +82,17 @@ function Stubs.new()
|
||||
}),
|
||||
})
|
||||
|
||||
local players_by_name, players_by_index, connected = {}, {}, {}
|
||||
-- Stored by name, with an index metamethod so players are also found by
|
||||
-- their player index, the same way game.players works
|
||||
local players_by_index = {}
|
||||
local players = setmetatable({}, { __index = players_by_index })
|
||||
local connected = {}
|
||||
game = Stubs.strict("LuaGameScript", {
|
||||
tick = 1,
|
||||
players = players_by_name,
|
||||
players = players,
|
||||
connected_players = connected,
|
||||
print = function(message) stubs.printed[#stubs.printed + 1] = message end,
|
||||
get_player = function(key) return players_by_name[key] or players_by_index[key] end,
|
||||
get_player = function(key) return players[key] end,
|
||||
}, { "player" })
|
||||
|
||||
--- Add a player to the stubbed game
|
||||
@@ -102,7 +109,7 @@ function Stubs.new()
|
||||
stubs.printed[#stubs.printed + 1] = { to = name, message }
|
||||
end,
|
||||
})
|
||||
players_by_name[name] = player
|
||||
rawset(players, name, player)
|
||||
players_by_index[index] = player
|
||||
if player.connected then connected[#connected + 1] = player end
|
||||
return player
|
||||
|
||||
Reference in New Issue
Block a user