Skip to content

Commit

Permalink
fix(api): storage widget showing 0 when host mount is explicit
Browse files Browse the repository at this point in the history
- add testing for storage data
  • Loading branch information
MauriceNino committed Aug 28, 2022
1 parent 538fdc6 commit c413305
Show file tree
Hide file tree
Showing 22 changed files with 459 additions and 92 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
18 changes: 18 additions & 0 deletions apps/api/__TESTS__/dynamic-info.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { expect } from 'chai';
import { mapToStorageOutput } from '../src/dynamic-info';
import { TEST_CASE_1 } from './test-cases';

describe('Dynamic Info', () => {
describe('Storage', () => {
it('Test Case 1', () => {
const output = mapToStorageOutput(
TEST_CASE_1.layout,
//@ts-ignore
TEST_CASE_1.blocks,
TEST_CASE_1.sizes
);

expect(output).to.deep.equal({ layout: [{ load: 185203033088 }] });
});
});
});
18 changes: 18 additions & 0 deletions apps/api/__TESTS__/static-info.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { expect } from 'chai';
import { mapToStorageLayout } from '../src/static-info';
import { TEST_CASE_1 } from './test-cases';

describe('Static Info', () => {
describe('Storage', () => {
it('Test Case 1', () => {
const output = mapToStorageLayout(
TEST_CASE_1.disks,
//@ts-ignore
TEST_CASE_1.blocks,
TEST_CASE_1.sizes
);

expect(output).to.deep.equal(TEST_CASE_1.layout);
});
});
});
184 changes: 184 additions & 0 deletions apps/api/__TESTS__/test-cases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
export const TEST_CASE_1 = {
disks: [
{
device: '/dev/sda',
type: 'HD',
name: 'QEMU HARDDISK ',
vendor: 'QEMU',
size: 429496729600,
bytesPerSector: null,
totalCylinders: null,
totalHeads: null,
totalSectors: null,
totalTracks: null,
tracksPerCylinder: null,
sectorsPerTrack: null,
firmwareRevision: '2.5+',
serialNum: '',
interfaceType: '',
smartStatus: 'unknown',
temperature: null,
},
],
sizes: [
{
fs: 'overlay',
type: 'overlay',
size: 429236563968,
used: 185197596672,
available: 244022190080,
use: 43.15,
mount: '/',
},
{
fs: '/dev/sda1',
type: 'ext4',
size: 429236563968,
used: 185197596672,
available: 244022190080,
use: 43.15,
mount: '/mnt/host',
},
{
fs: '/dev/sda15',
type: 'vfat',
size: 109422592,
used: 5436416,
available: 103986176,
use: 4.97,
mount: '/mnt/host/boot/efi',
},
{
fs: '/dev/loop3',
type: 'squashfs',
size: 49283072,
used: 49283072,
available: 0,
use: 100,
mount: '/mnt/host/snap/snapd/16010',
},
{
fs: '/dev/loop6',
type: 'squashfs',
size: 49283072,
used: 49283072,
available: 0,
use: 100,
mount: '/mnt/host/snap/snapd/16292',
},
{
fs: '/dev/loop5',
type: 'squashfs',
size: 108134400,
used: 108134400,
available: 0,
use: 100,
mount: '/mnt/host/snap/lxd/23367',
},
{
fs: '/dev/loop2',
type: 'squashfs',
size: 65011712,
used: 65011712,
available: 0,
use: 100,
mount: '/mnt/host/snap/core20/1593',
},
{
fs: '/dev/loop4',
type: 'squashfs',
size: 65011712,
used: 65011712,
available: 0,
use: 100,
mount: '/mnt/host/snap/core20/1611',
},
{
fs: '/dev/loop7',
type: 'squashfs',
size: 114032640,
used: 114032640,
available: 0,
use: 100,
mount: '/mnt/host/snap/lxd/23537',
},
],
blocks: [
{
name: 'sda',
type: 'disk',
fsType: '',
mount: '',
size: 429496729600,
physical: 'HDD',
uuid: '',
label: '',
model: 'QEMU HARDDISK ',
serial: '',
removable: false,
protocol: '',
group: undefined,
},
{
name: 'sda1',
type: 'part',
fsType: 'ext4',
mount: '/mnt/host',
size: 429380320768,
physical: '',
uuid: '43d2b5d9-3af2-48e8-908f-9b975e8974d6',
label: 'cloudimg-rootfs',
model: '',
serial: '',
removable: false,
protocol: '',
group: undefined,
},
{
name: 'sda14',
type: 'part',
fsType: '',
mount: '',
size: 4194304,
physical: '',
uuid: '',
label: '',
model: '',
serial: '',
removable: false,
protocol: '',
group: undefined,
},
{
name: 'sda15',
type: 'part',
fsType: 'vfat',
mount: '/mnt/host/boot/efi',
size: 111149056,
physical: '',
uuid: '9DDD-AECA',
label: 'UEFI',
model: '',
serial: '',
removable: false,
protocol: '',
group: undefined,
},
{
name: 'sr0',
type: 'rom',
fsType: 'iso9660',
mount: '',
size: 4194304,
physical: 'CD/DVD',
uuid: '2021-12-31-15-47-20-00',
label: 'cidata',
model: 'QEMU DVD-ROM ',
serial: '',
removable: true,
protocol: 'ata',
group: undefined,
},
],
layout: [{ device: 'sda', brand: 'QEMU', size: 429496729600, type: 'HD' }],
};
16 changes: 16 additions & 0 deletions apps/api/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable */
export default {
displayName: 'api',
preset: '../../jest.preset.js',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
},
},
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/temp-api',
};
16 changes: 14 additions & 2 deletions apps/api/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"options": {
"outputPath": "dist/apps/api",
"main": "apps/api/src/index.ts",
"tsConfig": "apps/api/tsconfig.json"
"tsConfig": "apps/api/tsconfig.app.json"
},
"configurations": {
"production": {
Expand Down Expand Up @@ -38,16 +38,28 @@
"lintFilePatterns": ["apps/api/**/*.ts"]
}
},
"test": {
"format": {
"executor": "nx:run-commands",
"options": {
"cwd": "apps/api",
"command": "prettier --check ."
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["coverage/apps/api"],
"options": {
"jestConfig": "apps/api/jest.config.ts",
"passWithNoTests": true
},
"dependsOn": [
{
"target": "lint",
"projects": "self"
},
{
"target": "format",
"projects": "self"
}
]
}
Expand Down
Loading

0 comments on commit c413305

Please sign in to comment.