Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/game-plugins/game-plugins.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,52 @@ describe("GamePluginsService.setAutoUpdate", () => {
).toBe(true);
});
});

describe("GamePluginsService.desiredForNode", () => {
let postgres: { query: jest.Mock };
let service: GamePluginsService;

beforeEach(() => {
postgres = {
query: jest.fn(async (sql: string): Promise<Array<any>> => {
if (sql.includes("FROM public.game_server_nodes")) {
return [{ pin_plugin_runtime: null }];
}
if (sql.includes("FROM public.game_plugin_installs")) {
return [{ plugin_slug: "arenas", version: null }];
}
if (sql.includes("FROM public.game_plugin_versions")) {
return [
{
version: "1.0.0",
url: "https://example.com/K4-Arenas-v1.0.0.zip",
sha256: "abc",
layout: "plugin",
install_path: "addons/{runtime}/plugins",
},
];
}
return [];
}),
};

service = new GamePluginsService(
{ warn: jest.fn(), log: jest.fn() } as any,
{} as any,
postgres as any,
{
resolvePluginRuntime: jest.fn(async (): Promise<string> => "swiftlys2"),
} as any,
{} as any,
{ add: jest.fn(), getJob: jest.fn() } as any,
);
});

// The node extracts to installPath verbatim, so an unexpanded placeholder
// lands the plugin in a literal addons/{runtime}/ that no runtime loads.
it("expands {runtime} in the install path for the node's runtime", async () => {
const { plugins } = await service.desiredForNode("node-1");

expect(plugins[0].installPath).toEqual("addons/swiftlys2/plugins");
});
});
3 changes: 2 additions & 1 deletion src/game-plugins/game-plugins.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,8 @@ export class GamePluginsService {
url: resolved.url,
sha256: resolved.sha256,
layout: resolved.layout,
installPath: resolved.install_path,
installPath:
resolved.install_path?.replaceAll("{runtime}", runtime) ?? null,
});
} catch (error) {
// A plugin with no build for this runtime is not an error the node can
Expand Down
Loading