Skip to content

Commit

Permalink
fix(api): remove appendix from raid label when it is not a dupe
Browse files Browse the repository at this point in the history
for #514
  • Loading branch information
MauriceNino committed Jan 6, 2023
1 parent 173848b commit 23bbc05
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions apps/api/__TESTS__/dynamic-info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('Dynamic Info', () => {
beforeEach(() => {
CONFIG.running_in_docker = true;
});

describe('Storage', () => {
it('Test Case 1', () => {
const output = new DynamicStorageMapper(
Expand Down
8 changes: 4 additions & 4 deletions apps/api/__TESTS__/static-info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import {
const toStorageInp = (inp: TestCase) =>
[inp.disks, inp.blocks, inp.sizes] as const;

beforeEach(() => {
CONFIG.running_in_docker = true;
});

describe('Static Info', () => {
beforeEach(() => {
CONFIG.running_in_docker = true;
});

describe('Storage', () => {
it('Test Case 1', () => {
const output = mapToStorageLayout(...toStorageInp(TEST_CASE_1));
Expand Down
4 changes: 2 additions & 2 deletions apps/api/__TESTS__/test-cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5137,14 +5137,14 @@ export const TEST_CASE_14 = {
{
brand: 'Samsung',
device: 'nvme0n1',
raidGroup: 'archlinux-latest-64-minimal:0',
raidGroup: 'archlinux-latest-64-minimal',
size: 512110190592,
type: 'NVMe',
},
{
brand: 'Samsung',
device: 'nvme1n1',
raidGroup: 'archlinux-latest-64-minimal:0',
raidGroup: 'archlinux-latest-64-minimal',
size: 512110190592,
type: 'NVMe',
},
Expand Down
17 changes: 11 additions & 6 deletions apps/api/src/data/storage/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,23 @@ const getVirtualMountsLayout = (sizes: Size[]) =>

const getRaidLabel = (deviceName: string, allRaidBlocks: Block[]) => {
const raidBlocks = allRaidBlocks.filter(m => m.name.startsWith(deviceName));
const uuids = raidBlocks.map(rb => rb.uuid);

if (raidBlocks.length > 0) {
const isSplit = raidBlocks[0].label.includes(':');

if (isSplit) {
const splitLabel = raidBlocks[0].label.split(':')[0];
const hasUniqueName = !allRaidBlocks.some(member => {
const startSame = member.label.split(':')[0] === splitLabel;
const isSame = member.label === raidBlocks[0].label;

return startSame && !isSame;
});
const hasUniqueName = !allRaidBlocks
.filter(
rb => !rb.name.startsWith(deviceName) && !uuids.includes(rb.uuid)
)
.some(rb => {
const startSame = rb.label.split(':')[0] === splitLabel;
const isSame = rb.label === raidBlocks[0].label;

return startSame && !isSame;
});

return hasUniqueName ? splitLabel : raidBlocks[0].label;
} else {
Expand Down

0 comments on commit 23bbc05

Please sign in to comment.