balena-supervisor/test/38-sys-info.spec.ts
Cameron Diver a2ceb5c931 Refactor system information filtering
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-10-12 15:44:07 +01:00

59 lines
1.5 KiB
TypeScript

import { expect } from 'chai';
import * as sysInfo from '../src/lib/system-info';
describe('System information', () => {
describe('Delta-based filtering', () => {
it('should correctly filter cpu usage', () => {
expect(
sysInfo.filterNonSignificantChanges({ cpu_usage: 21 }, {
cpu_usage: 20,
} as sysInfo.SystemInfo),
).to.deep.equal(['cpu_usage']);
expect(
sysInfo.filterNonSignificantChanges({ cpu_usage: 10 }, {
cpu_usage: 20,
} as sysInfo.SystemInfo),
).to.deep.equal([]);
});
it('should correctly filter cpu temperature', () => {
expect(
sysInfo.filterNonSignificantChanges({ cpu_temp: 21 }, {
cpu_temp: 22,
} as sysInfo.SystemInfo),
).to.deep.equal(['cpu_temp']);
expect(
sysInfo.filterNonSignificantChanges({ cpu_temp: 10 }, {
cpu_temp: 20,
} as sysInfo.SystemInfo),
).to.deep.equal([]);
});
it('should correctly filter memory usage', () => {
expect(
sysInfo.filterNonSignificantChanges({ memory_usage: 21 }, {
memory_usage: 22,
} as sysInfo.SystemInfo),
).to.deep.equal(['memory_usage']);
expect(
sysInfo.filterNonSignificantChanges({ memory_usage: 10 }, {
memory_usage: 20,
} as sysInfo.SystemInfo),
).to.deep.equal([]);
});
it('should not filter if we didnt have a past value', () => {
expect(
sysInfo.filterNonSignificantChanges({}, {
memory_usage: 22,
cpu_usage: 10,
cpu_temp: 5,
} as sysInfo.SystemInfo),
).to.deep.equal([]);
});
});
});