Add Prettier and ESLint tooling (Refs #77)
This commit is contained in:
@@ -3,30 +3,46 @@ import { newFixture, type Fixture } from '../helpers/fixture.js';
|
||||
import { prepareNativeHost } from '../helpers/native-host.js';
|
||||
|
||||
let fixture: Fixture;
|
||||
beforeEach(async () => { vi.resetModules(); fixture = await newFixture([]); });
|
||||
afterEach(async () => { await fixture.cleanup(); });
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
fixture = await newFixture([]);
|
||||
});
|
||||
afterEach(async () => {
|
||||
await fixture.cleanup();
|
||||
});
|
||||
const settings = { game: 't6', mapSlug: 'town', maximum: 2, mode: 'create-destroy' };
|
||||
async function setup() {
|
||||
await prepareNativeHost();
|
||||
const { db } = await import('../../src/lib/server/db/index.js');
|
||||
const scaling = await import('../../src/lib/server/autoscaling/index.js');
|
||||
const { saveServerKey, reserveServerKey } = await import('../../src/lib/server/fleet/server-keys.js');
|
||||
const { saveServerKey, reserveServerKey } =
|
||||
await import('../../src/lib/server/fleet/server-keys.js');
|
||||
return { db, scaling, saveServerKey, reserveServerKey };
|
||||
}
|
||||
|
||||
it.each(['off', 'create-destroy'])('saves a %s policy without preallocating keys for its maximum', async mode => {
|
||||
const { db, scaling } = await setup();
|
||||
const input = { ...settings, mode, maximum: 20 };
|
||||
const evaluation = scaling.evaluateScaling(input);
|
||||
expect(evaluation.blockers).toEqual([]);
|
||||
expect(evaluation.decision.action).toBe('wait');
|
||||
if (mode !== 'off') expect(evaluation.decision.reason).toContain('No Plutonium keys');
|
||||
const { POST } = await import('../../src/routes/api/autoscaling/+server.js');
|
||||
const response = await POST({ request: new Request('http://localhost/api/autoscaling', { method: 'POST', body: JSON.stringify({ action: 'save', settings: input }) }) });
|
||||
expect(response.status).toBe(200);
|
||||
expect(db().prepare('SELECT COUNT(*) AS n FROM autoscaling_policies').get()).toEqual({ n: 1 });
|
||||
expect(await scaling.runAutoscaling()).toBe(false);
|
||||
});
|
||||
it.each(['off', 'create-destroy'])(
|
||||
'saves a %s policy without preallocating keys for its maximum',
|
||||
async (mode) => {
|
||||
const { db, scaling } = await setup();
|
||||
const input = { ...settings, mode, maximum: 20 };
|
||||
const evaluation = scaling.evaluateScaling(input);
|
||||
expect(evaluation.blockers).toEqual([]);
|
||||
expect(evaluation.decision.action).toBe('wait');
|
||||
if (mode !== 'off') expect(evaluation.decision.reason).toContain('No Plutonium keys');
|
||||
const { POST } = await import('../../src/routes/api/autoscaling/+server.js');
|
||||
const response = await POST({
|
||||
request: new Request('http://localhost/api/autoscaling', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ action: 'save', settings: input })
|
||||
})
|
||||
});
|
||||
expect(response.status).toBe(200);
|
||||
expect(db().prepare('SELECT COUNT(*) AS n FROM autoscaling_policies').get()).toEqual({
|
||||
n: 1
|
||||
});
|
||||
expect(await scaling.runAutoscaling()).toBe(false);
|
||||
}
|
||||
);
|
||||
|
||||
it('uses any free key for the selected game independently of its label or map', async () => {
|
||||
const { scaling, saveServerKey } = await setup();
|
||||
@@ -56,7 +72,9 @@ it('saves against the current key pool without an intermediate confirmation', as
|
||||
expect(scaling.scalingReport().policies[0].decision.reason).toContain('No Plutonium keys');
|
||||
saveServerKey('t6', 'game-key');
|
||||
reserveServerKey('t6_zombie_farm_1', 't6');
|
||||
expect(scaling.saveScaling({ ...settings, maximum: 3 }, saved.id, saved.revision).maximum).toBe(3);
|
||||
expect(scaling.saveScaling({ ...settings, maximum: 3 }, saved.id, saved.revision).maximum).toBe(
|
||||
3
|
||||
);
|
||||
const view = scaling.scalingReport().policies[0];
|
||||
expect(view.decision.reason).toContain('keys are in use');
|
||||
expect(view.snapshot.members).toEqual([]);
|
||||
@@ -73,12 +91,15 @@ it('shares capacity between live map policies and admits the job holding the las
|
||||
scaling.saveScaling(input);
|
||||
}
|
||||
expect(await scaling.runAutoscaling()).toBe(true);
|
||||
const jobs = db().prepare('SELECT deployment_id,server FROM server_creation_jobs').all() as { deployment_id: string; server: string }[];
|
||||
const jobs = db().prepare('SELECT deployment_id,server FROM server_creation_jobs').all() as {
|
||||
deployment_id: string;
|
||||
server: string;
|
||||
}[];
|
||||
expect(jobs).toHaveLength(1);
|
||||
expect(jobs[0].server).toBe('t6_zombie_farm_1');
|
||||
const { scalingAdmission } = await import('../../src/lib/server/autoscaling/admission.js');
|
||||
expect(scalingAdmission(jobs[0].deployment_id)).toBeNull();
|
||||
const town = scaling.scalingReport().policies.find(p => p.policy.mapSlug === 'town')!;
|
||||
const town = scaling.scalingReport().policies.find((p) => p.policy.mapSlug === 'town')!;
|
||||
expect(town.snapshot.keyPool).toEqual({ total: 1, available: 0 });
|
||||
expect(town.decision.reason).toContain('keys are in use');
|
||||
expect(town.policy.pausedReason).toBeNull();
|
||||
|
||||
Reference in New Issue
Block a user