20 lines
798 B
TypeScript
20 lines
798 B
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { validateInventory } from '../../src/lib/server/hosts/index.js';
|
|
|
|
describe('host CPU inventory', () => {
|
|
it('accepts older agents without CPU usage', () => {
|
|
expect(validateInventory({ cpuCount: 4 }).cpuUsagePercent).toBeUndefined();
|
|
});
|
|
it.each([0, 0.1, 42.3, 100])('accepts CPU usage %s', (cpuUsagePercent) => {
|
|
expect(validateInventory({ cpuUsagePercent }).cpuUsagePercent).toBe(cpuUsagePercent);
|
|
});
|
|
it.each([-1, 100.1, NaN, Infinity, -Infinity, null, '25', true, {}])(
|
|
'rejects invalid CPU usage %j',
|
|
(cpuUsagePercent) => {
|
|
expect(() => validateInventory({ cpuUsagePercent })).toThrow(
|
|
'Invalid inventory cpuUsagePercent'
|
|
);
|
|
}
|
|
);
|
|
});
|