Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Nov 8, 2024
1 parent 7e26d2a commit e52283e
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 0 deletions.
111 changes: 111 additions & 0 deletions web/src/storage/model/config/drive.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright (c) [2024] SUSE LLC
*
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, contact SUSE LLC.
*
* To contact SUSE LLC about this file by physical or electronic mail, you may
* find current contact information at www.suse.com.
*/

import * as model from "~/storage/model/config/drive";

describe("#generate", () => {
it("returns a drive object from a drive section", () => {
expect(model.generate(
undefined,
{
search: "/dev/vda",
alias: "test",
filesystem: {
type: "xfs",
path: "/test"
}
}
)).toEqual(
{
name: "/dev/vda",
alias: "test",
filesystem: "xfs",
mountPath: "/test",
snapshots: undefined,
spacePolicy: undefined
}
);

expect(model.generate(
{
partitions: [
{ search: "*", delete: true }
]
},
{
search: "/dev/vda",
alias: "test",
filesystem: {
type: {
btrfs: { snapshots: false }
},
path: "/test"
}
}
)).toEqual(
{
name: "/dev/vda",
alias: "test",
filesystem: "btrfs",
mountPath: "/test",
snapshots: false,
spacePolicy: "delete"
}
);

expect(model.generate(
{
partitions: [
{ search: "*", delete: true },
{ generate: "default" }
]
},
{
search: "/dev/vda",
partitions: [
{ search: "/dev/vda1", delete: true },
{ filesystem: { path: "/" } }
]
}
)).toEqual(
{
name: "/dev/vda",
alias: undefined,
spacePolicy: "delete",
partitions: [
{
name: "/dev/vda1",
delete: true
},
{
name: undefined,
alias: undefined,
filesystem: undefined,
mountPath: "/",
snapshots: undefined,
size: undefined
}
]
}
);
});
});
93 changes: 93 additions & 0 deletions web/src/storage/model/config/partition.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright (c) [2024] SUSE LLC
*
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, contact SUSE LLC.
*
* To contact SUSE LLC about this file by physical or electronic mail, you may
* find current contact information at www.suse.com.
*/

import * as model from "~/storage/model/config/partition";

describe("#generate", () => {
it("returns a partition object from a partition section", () => {
expect(model.generate(
{
search: "/dev/vda1",
delete: true
}
)).toEqual(
{
name: "/dev/vda1",
delete: true
}
);

expect(model.generate(
{
search: "/dev/vda1",
deleteIfNeeded: true,
size: 1024
}
)).toEqual(
{
name: "/dev/vda1",
deleteIfNeeded: true,
size: { min: 1024, max: 1024 }
}
);

expect(model.generate(
{
search: "/dev/vda1",
alias: "test",
filesystem: {
path: "/test",
type: {
btrfs: { snapshots: true }
}
},
size: { min: 0, max: 2048 }
}
)).toEqual(
{
name: "/dev/vda1",
alias: "test",
filesystem: "btrfs",
mountPath: "/test",
snapshots: true,
size: { min: 0, max: 2048 }
}
);

expect(model.generate(
{
filesystem: {
path: "/test",
}
}
)).toEqual(
{
name: undefined,
alias: undefined,
filesystem: undefined,
mountPath: "/test",
snapshots: undefined,
size: undefined
}
);
});
});
1 change: 1 addition & 0 deletions web/src/storage/model/config/partition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class PartitionGenerator {

private fromPartition(partitionConfig: config.Partition): Partition {
return {
name: generateName(partitionConfig),
alias: partitionConfig.alias,
filesystem: generateFilesystem(partitionConfig),
mountPath: partitionConfig.filesystem?.path,
Expand Down

0 comments on commit e52283e

Please sign in to comment.