From e52283e585cdaa95230767bb3c2425c834102716 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Fri, 8 Nov 2024 09:12:33 +0000 Subject: [PATCH] wip --- web/src/storage/model/config/drive.test.ts | 111 ++++++++++++++++++ .../storage/model/config/partition.test.ts | 93 +++++++++++++++ web/src/storage/model/config/partition.ts | 1 + 3 files changed, 205 insertions(+) create mode 100644 web/src/storage/model/config/drive.test.ts create mode 100644 web/src/storage/model/config/partition.test.ts diff --git a/web/src/storage/model/config/drive.test.ts b/web/src/storage/model/config/drive.test.ts new file mode 100644 index 0000000000..5eb7e42568 --- /dev/null +++ b/web/src/storage/model/config/drive.test.ts @@ -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 + } + ] + } + ); + }); +}); diff --git a/web/src/storage/model/config/partition.test.ts b/web/src/storage/model/config/partition.test.ts new file mode 100644 index 0000000000..80bbef349f --- /dev/null +++ b/web/src/storage/model/config/partition.test.ts @@ -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 + } + ); + }); +}); diff --git a/web/src/storage/model/config/partition.ts b/web/src/storage/model/config/partition.ts index 3eab6a94ea..92dccddf24 100644 --- a/web/src/storage/model/config/partition.ts +++ b/web/src/storage/model/config/partition.ts @@ -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,