Files
cloudron-box/src/test/system-test.js
T

106 lines
3.5 KiB
JavaScript
Raw Normal View History

2016-01-25 16:03:12 -08:00
/* jslint node:true */
/* global it:false */
/* global describe:false */
/* global before:false */
/* global after:false */
'use strict';
2021-06-03 12:20:44 -07:00
const common = require('./common.js'),
2019-11-21 12:58:06 -08:00
expect = require('expect.js'),
2025-06-06 15:49:07 +02:00
nock = require('nock'),
2019-11-21 12:58:06 -08:00
system = require('../system.js');
2016-01-25 16:03:12 -08:00
2019-11-21 12:58:06 -08:00
describe('System', function () {
2021-08-13 10:41:10 -07:00
const { setup, cleanup } = common;
2025-06-06 15:49:07 +02:00
before(async function () {
await setup();
if (nock.isActive()) nock.restore(); // required to connect to the docker socket
});
2021-08-13 10:41:10 -07:00
after(cleanup);
2016-01-25 16:03:12 -08:00
2024-11-30 11:46:28 +01:00
it('can get filesystems', async function () {
// does not work on archlinux 8!
if (require('child_process').execSync('uname -a').toString().indexOf('-arch') !== -1) return;
2025-07-16 23:09:06 +02:00
const filesystems = await system.getFilesystems();
expect(filesystems).to.be.ok();
expect(filesystems.some(fs => fs.mountpoint === '/')).to.be(true);
2022-11-04 15:09:37 +01:00
});
it('can get swaps', async function () {
// does not work on archlinux 8!
if (require('child_process').execSync('uname -a').toString().indexOf('-arch') !== -1) return;
const swaps = await system.getSwaps();
expect(swaps).to.be.ok();
2023-12-03 15:05:26 +01:00
expect(Object.keys(swaps).some(n => swaps[n].type === 'partition' || swaps[n].type === 'file')).to.be.ok();
2019-08-19 13:50:44 -07:00
});
2021-08-25 19:41:46 -07:00
it('can check for disk space', async function () {
// does not work on archlinux 8!
if (require('child_process').execSync('uname -a').toString().indexOf('-arch') !== -1) return;
2021-08-25 19:41:46 -07:00
await system.checkDiskSpace();
2016-01-25 16:03:12 -08:00
});
2019-11-21 12:58:06 -08:00
2021-08-25 19:41:46 -07:00
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');
2019-11-21 12:58:06 -08:00
});
2022-10-11 22:58:12 +02:00
2023-12-04 00:23:25 +01:00
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');
});
2023-12-04 00:31:18 +01:00
2025-07-16 23:09:06 +02:00
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();
});
2023-12-04 01:09:42 +01:00
it('can get info', async function () {
const info = await system.getInfo();
2023-12-04 00:31:18 +01:00
2023-12-04 01:09:42 +01:00
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');
2023-12-04 00:31:18 +01:00
});
2025-07-20 10:20:48 +02:00
it('can get block devices', async function () {
const devices = await system.getBlockDevices();
expect(devices.some(d => d.mountpoint === '/')).to.be(true);
});
it('can get filesystems', async function () {
const filesystems = await system.getFilesystems();
expect(filesystems.find(v => v.mountpoint === '/')).to.be.ok();
});
2025-07-16 23:09:06 +02:00
it('can get filesystemUsage', async function () {
const filesystems = await system.getFilesystems();
2025-07-20 10:20:48 +02:00
const rootFs = filesystems.find(v => v.mountpoint === '/');
2025-07-16 23:09:06 +02:00
expect(rootFs.filesystem).to.be.ok();
const usageTask = await system.getFilesystemUsage(rootFs.filesystem);
2023-01-27 21:05:25 +01:00
2025-07-16 23:09:06 +02:00
return new Promise((resolve, reject) => {
2025-07-25 12:08:33 +02:00
// usageTask.on('data', (type, data) => console.log(type, data));
2025-07-16 23:09:06 +02:00
usageTask.on('done', (error) => {
if (error.errorMessage) reject(new Error(error.errorMessage)); else resolve();
});
2023-01-27 21:05:25 +01:00
2025-07-16 23:09:06 +02:00
usageTask.start();
});
2023-01-27 21:05:25 +01:00
});
2016-01-25 16:03:12 -08:00
});