106 lines
3.4 KiB
JavaScript
106 lines
3.4 KiB
JavaScript
/* jslint node:true */
|
|
/* global it:false */
|
|
/* global describe:false */
|
|
/* global before:false */
|
|
/* global after:false */
|
|
|
|
'use strict';
|
|
|
|
const common = require('./common.js'),
|
|
expect = require('expect.js'),
|
|
nock = require('nock'),
|
|
system = require('../system.js');
|
|
|
|
describe('System', function () {
|
|
const { setup, cleanup } = common;
|
|
|
|
before(async function () {
|
|
await setup();
|
|
if (nock.isActive()) nock.restore(); // required to connect to the docker socket
|
|
});
|
|
after(cleanup);
|
|
|
|
it('can get filesystems', async function () {
|
|
// does not work on archlinux 8!
|
|
if (require('node:child_process').execSync('uname -a').toString().indexOf('-arch') !== -1) return;
|
|
|
|
const filesystems = await system.getFilesystems();
|
|
expect(filesystems).to.be.ok();
|
|
expect(filesystems.some(fs => fs.mountpoint === '/')).to.be(true);
|
|
});
|
|
|
|
it('can get swaps', async function () {
|
|
// does not work on archlinux 8!
|
|
if (require('node:child_process').execSync('uname -a').toString().indexOf('-arch') !== -1) return;
|
|
|
|
const swaps = await system.getSwaps();
|
|
expect(swaps).to.be.ok();
|
|
expect(Object.keys(swaps).some(n => swaps[n].type === 'partition' || swaps[n].type === 'file')).to.be.ok();
|
|
});
|
|
|
|
it('can check for disk space', async function () {
|
|
// does not work on archlinux 8!
|
|
if (require('node:child_process').execSync('uname -a').toString().indexOf('-arch') !== -1) return;
|
|
|
|
await system.checkDiskSpace();
|
|
});
|
|
|
|
it('can get memory', async function () {
|
|
const memory = await system.getMemory();
|
|
expect(memory.memory).to.be.a('number');
|
|
expect(memory.swap).to.be.a('number');
|
|
});
|
|
|
|
it('can get CPUs', async function () {
|
|
const cpus = await system.getCpus();
|
|
expect(cpus).to.be.an(Array);
|
|
expect(cpus[0].model).to.be.a('string');
|
|
});
|
|
|
|
it('can get ubuntu version', async function () {
|
|
const v = await system.getUbuntuVersion();
|
|
expect(v).to.be.ok();
|
|
});
|
|
|
|
it('can get kernel version', async function () {
|
|
const v = await system.getKernelVersion();
|
|
expect(v).to.be.ok();
|
|
});
|
|
|
|
it('can get info', async function () {
|
|
const info = await system.getInfo();
|
|
|
|
expect(info.sysVendor).to.be.a('string');
|
|
expect(info.productName).to.be.a('string');
|
|
expect(info.uptimeSecs).to.be.a('number');
|
|
expect(info.rebootRequired).to.be.a('boolean');
|
|
});
|
|
|
|
it('can get block devices', async function () {
|
|
const devices = await system.getBlockDevices();
|
|
expect(devices).to.be.ok();
|
|
});
|
|
|
|
it('can get filesystems', async function () {
|
|
const filesystems = await system.getFilesystems();
|
|
expect(filesystems.find(v => v.mountpoint === '/')).to.be.ok();
|
|
});
|
|
|
|
it('can get filesystemUsage', async function () {
|
|
const filesystems = await system.getFilesystems();
|
|
const rootFs = filesystems.find(v => v.mountpoint === '/');
|
|
expect(rootFs.filesystem).to.be.ok();
|
|
|
|
const usageTask = await system.getFilesystemUsage(rootFs.filesystem);
|
|
|
|
return new Promise((resolve, reject) => {
|
|
// usageTask.on('data', (type, data) => console.log(type, data));
|
|
usageTask.on('done', (error) => {
|
|
if (error.errorMessage) reject(new Error(error.errorMessage)); else resolve();
|
|
});
|
|
|
|
usageTask.start();
|
|
});
|
|
});
|
|
});
|