From 0bf5a13051e594f946a90de873bb0495e5f4be22 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Tue, 17 Mar 2015 17:15:11 +0100 Subject: [PATCH] add tests and fix founded issues --- src/modules/BootStorage.rb | 3 ++- test/boot_storage_test.rb | 55 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/modules/BootStorage.rb b/src/modules/BootStorage.rb index be4b81de1..0c95265ad 100644 --- a/src/modules/BootStorage.rb +++ b/src/modules/BootStorage.rb @@ -30,6 +30,7 @@ class BootStorageClass < Module def main textdomain "bootloader" + Yast.import "BootCommon" Yast.import "Storage" Yast.import "StorageDevices" Yast.import "Arch" @@ -419,7 +420,7 @@ def detect_disks log.info "mountPoints #{mp}" log.info "mountdata_boot #{mountdata_boot}" - @RootPartitionDevice = mountdata_root.first || "" + @RootPartitionDevice = mountdata_root ? mountdata_root.first || "" : "" raise "No mountpoint for / !!" if @RootPartitionDevice.empty? # if /boot changed, re-configure location diff --git a/test/boot_storage_test.rb b/test/boot_storage_test.rb index 56178f7d4..3938bc015 100644 --- a/test/boot_storage_test.rb +++ b/test/boot_storage_test.rb @@ -122,4 +122,59 @@ expect(subject.multipath_mapping["/dev/sda"]).to eq "/dev/mapper/3600508b1001c9a84c91492de27962d57" end end + + describe ".detect_disks" do + before do + mock_disk_partition + target_map_stub("storage_lvm.rb") + + allow(Yast::Storage).to receive(:GetMountPoints).and_return( + "/" => ["/dev/vda1"], + "/boot" => ["/dev/vda2"] + ) + end + + it "fills RootPartitionDevice variable" do + subject.RootPartitionDevice = nil + + subject.detect_disks + + expect(subject.RootPartitionDevice).to eq "/dev/vda1" + end + + it "fills BootPartitionDevice variable" do + subject.BootPartitionDevice = nil + + subject.detect_disks + + expect(subject.BootPartitionDevice).to eq "/dev/vda2" + end + + it "sets ExtendedPartitionDevice variable to nil if boot is not logical" do + subject.ExtendedPartitionDevice = nil + + subject.detect_disks + + expect(subject.ExtendedPartitionDevice).to eq nil + end + + # need target map with it + it "sets ExtendedPartitionDevice variable to extended partition if boot is logical" + + it "raises exception if there is no mount point for root" do + allow(Yast::Storage).to receive(:GetMountPoints).and_return({}) + + expect{subject.detect_disks}.to raise_error + end + + it "sets BootCommon.mbrDisk if not already set" do + Yast::BootCommon.mbrDisk = nil + + expect(Yast::BootCommon).to receive(:FindMBRDisk).and_return("/dev/vda") + + subject.detect_disks + + expect(Yast::BootCommon.mbrDisk).to eq "/dev/vda" + end + end end