Fix artifact metadata test fixtures and cover modified files
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { createHash } from 'node:crypto';
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||||
import { newFixture, type Fixture } from '../helpers/fixture.js';
|
import { newFixture, type Fixture } from '../helpers/fixture.js';
|
||||||
|
|
||||||
@@ -35,8 +36,8 @@ describe('server detail data', () => {
|
|||||||
db().exec("INSERT INTO servers (name) VALUES ('target')");
|
db().exec("INSERT INTO servers (name) VALUES ('target')");
|
||||||
const { createScript } = await import('../../src/lib/server/fleet/scripts.js');
|
const { createScript } = await import('../../src/lib/server/fleet/scripts.js');
|
||||||
const { recordScript } = await import('../../src/lib/server/fleet/inventory.js');
|
const { recordScript } = await import('../../src/lib/server/fleet/inventory.js');
|
||||||
const { version } = createScript({ name:'Plugin', kind:'plugin', targetRelPath:'native.bin', content:Buffer.from('plugin') });
|
const { script, version } = createScript({ name:'Plugin', kind:'plugin', releaseVersion:'v1.0.0', targetRelPath:'native.bin', content:Buffer.from('plugin') });
|
||||||
recordScript('target','native.bin',version.id,'hash',6,'beta');
|
recordScript('target','native.bin',version.id,version.sha256,6,'beta');
|
||||||
recordScript('target','dedicated_zm.cfg',null,'hash',10,'compose');
|
recordScript('target','dedicated_zm.cfg',null,'hash',10,'compose');
|
||||||
recordScript('target','main.gsc',null,'hash',10,'beta');
|
recordScript('target','main.gsc',null,'hash',10,'beta');
|
||||||
recordScript('target','unknown.dat',null,'hash',10,'manual');
|
recordScript('target','unknown.dat',null,'hash',10,'manual');
|
||||||
@@ -45,5 +46,24 @@ describe('server detail data', () => {
|
|||||||
expect(Object.fromEntries(body.scripts.map((file: {relPath:string;kind:string}) => [file.relPath,file.kind]))).toEqual({
|
expect(Object.fromEntries(body.scripts.map((file: {relPath:string;kind:string}) => [file.relPath,file.kind]))).toEqual({
|
||||||
'dedicated_zm.cfg':'config','main.gsc':'script','native.bin':'plugin','unknown.dat':'file'
|
'dedicated_zm.cfg':'config','main.gsc':'script','native.bin':'plugin','unknown.dat':'file'
|
||||||
});
|
});
|
||||||
|
expect(body.scripts.find((file: { relPath: string }) => file.relPath === 'native.bin')).toMatchObject({
|
||||||
|
artifactId: script.id, version: version.version, releaseVersion: 'v1.0.0', sha256: version.sha256
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it.each([['native.bin', 'file'], ['native.dll', 'plugin']])('omits saved artifact metadata for modified %s and falls back to its extension', async (path, kind) => {
|
||||||
|
const { db } = await import('../../src/lib/server/db/index.js');
|
||||||
|
db().exec("INSERT INTO servers (name) VALUES ('target')");
|
||||||
|
const { createScript } = await import('../../src/lib/server/fleet/scripts.js');
|
||||||
|
const { recordScript } = await import('../../src/lib/server/fleet/inventory.js');
|
||||||
|
const { version } = createScript({ name:'Plugin', kind:'plugin', releaseVersion:'v1.0.0', targetRelPath:path, content:Buffer.from('plugin') });
|
||||||
|
const content = Buffer.from('modified plugin');
|
||||||
|
const sha256 = createHash('sha256').update(content).digest('hex');
|
||||||
|
recordScript('target',path,version.id,sha256,content.length,'manual');
|
||||||
|
const { GET } = await import('../../src/routes/api/servers/[name]/scripts/+server.js');
|
||||||
|
const body = await (await GET({ params: {name:'target'} })).json();
|
||||||
|
expect(body.scripts).toEqual([expect.objectContaining({
|
||||||
|
relPath: path, kind, artifactId: null, version: null, releaseVersion: null,
|
||||||
|
scriptVersionId: version.id, sha256, size: content.length, source: 'manual'
|
||||||
|
})]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user