add disks tests
This commit is contained in:
@@ -175,7 +175,7 @@ async function getDiskUsage(req, res, next) {
|
||||
const [error, result] = await safe(system.getDiskUsage());
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(201, { usage: result }));
|
||||
next(new HttpSuccess(200, { usage: result }));
|
||||
}
|
||||
|
||||
async function updateDiskUsage(req, res, next) {
|
||||
|
||||
@@ -14,7 +14,7 @@ const constants = require('../../constants.js'),
|
||||
settings = require('../../settings.js');
|
||||
|
||||
describe('Cloudron API', function () {
|
||||
const { setup, cleanup, serverUrl, owner, user } = common;
|
||||
const { setup, cleanup, serverUrl, owner, user, waitForTask } = common;
|
||||
|
||||
before(setup);
|
||||
after(cleanup);
|
||||
@@ -369,6 +369,46 @@ describe('Cloudron API', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('disks', function () {
|
||||
it('succeeds', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/cloudron/disks`)
|
||||
.query({ access_token: owner.token });
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.body.disks).to.be.ok();
|
||||
expect(Object.keys(response.body.disks).some(fs => response.body.disks[fs].mountpoint === '/')).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('disk usage', function () {
|
||||
it('get succeeds with no cache', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/cloudron/disk_usage`)
|
||||
.query({ access_token: owner.token })
|
||||
.send({});
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.body).to.eql({ usage: null });
|
||||
});
|
||||
|
||||
it('update the cache', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/cloudron/disk_usage`)
|
||||
.query({ access_token: owner.token });
|
||||
|
||||
expect(response.statusCode).to.equal(201);
|
||||
expect(response.body.taskId).to.be.ok();
|
||||
await waitForTask(response.body.taskId);
|
||||
});
|
||||
|
||||
it('get succeeds with cache', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/cloudron/disk_usage`)
|
||||
.query({ access_token: owner.token })
|
||||
.send({});
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
console.log(response.body);
|
||||
});
|
||||
});
|
||||
|
||||
describe('languages', function () {
|
||||
it('succeeds', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/cloudron/languages`);
|
||||
|
||||
+5
-6
@@ -147,13 +147,12 @@ function getMemoryAllocation(limit) {
|
||||
return Math.round(Math.round(limit * ratio) / 1048576) * 1048576; // nearest MB
|
||||
}
|
||||
|
||||
function getDiskUsage() {
|
||||
const output = safe.JSON.parse(safe.fs.readFileSync(paths.DISK_USAGE_FILE, 'utf8'));
|
||||
return output;
|
||||
async function getDiskUsage() {
|
||||
return safe.JSON.parse(safe.fs.readFileSync(paths.DISK_USAGE_FILE, 'utf8'));
|
||||
}
|
||||
|
||||
async function updateDiskUsage(progressCallback) {
|
||||
assert.strictEqual(progressCallback, 'function');
|
||||
assert.strictEqual(typeof progressCallback, 'function');
|
||||
|
||||
const disks = await getDisks();
|
||||
const filesystems = Object.keys(disks);
|
||||
@@ -169,8 +168,8 @@ async function updateDiskUsage(progressCallback) {
|
||||
|
||||
for (const content of disk.contents) {
|
||||
progressCallback({ message: `Checking du of ${JSON.stringify(content)}`});
|
||||
if (content.type === 'docker') {
|
||||
content.usage = (await docker.du()).LayersSize;
|
||||
if (content.id === 'docker') {
|
||||
content.usage = (await docker.df()).LayersSize;
|
||||
} else {
|
||||
content.usage = await du(content.path, { exclude: content.exclude });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user