mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-17 14:59:16 +02:00
REFACTOR: Speed up by-ip lookups by introducing a new map entry (#2488)
Thankfully, the existing AllServers map is not exported, so we can ensure that all the changes are only local to this file. This also fixes a bug if renameServer was called with the same name. (Probably calling code checked that case already.)
This commit is contained in:
@@ -4,6 +4,8 @@ import {
|
||||
loadAllServers,
|
||||
prestigeAllServers,
|
||||
saveAllServers,
|
||||
renameServer,
|
||||
GetServer,
|
||||
} from "../../../src/Server/AllServers";
|
||||
import { Server } from "../../../src/Server/Server";
|
||||
import { IPAddress } from "../../../src/Types/strings";
|
||||
@@ -35,3 +37,23 @@ describe("AllServers can be saved and loaded", () => {
|
||||
expect(loadedServer.numOpenPortsRequired).toEqual(server1.numOpenPortsRequired);
|
||||
});
|
||||
});
|
||||
|
||||
describe("renameServer tests", () => {
|
||||
it("rename to self edge case", () => {
|
||||
prestigeAllServers();
|
||||
expect(GetAllServers(true)).toEqual([]);
|
||||
|
||||
const home = new Server({ hostname: "home", ip: "1.2.3.4" as IPAddress });
|
||||
AddToAllServers(home);
|
||||
// Failures of toEqual will report badly, due to a Jest bug involving our use of JSONMap.
|
||||
// The context is similar to this issue: https://github.com/hapijs/joi/issues/2350
|
||||
// I didn't run it all the way down, because it only affects error-reporting, not the comparison,
|
||||
// so everything is fine when tests are passing.
|
||||
expect(GetAllServers(true)).toEqual([home]);
|
||||
|
||||
renameServer("home", "home");
|
||||
expect(GetAllServers(true)).toEqual([home]);
|
||||
expect(GetServer("home")).toBe(home);
|
||||
expect(GetServer("1.2.3.4")).toBe(home);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user