Skip to content

Commit

Permalink
Adapt existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ancorgs authored and dgdavid committed May 20, 2020
1 parent f848c1e commit b3e1a39
Show file tree
Hide file tree
Showing 13 changed files with 181 additions and 169 deletions.
133 changes: 133 additions & 0 deletions test/lib/presenters/partition_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Copyright (c) [2020] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# 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.

require_relative "../../test_helper"
require "autoinstall/presenters"
require "y2storage/autoinst_profile/partitioning_section"
require "y2storage/autoinst_profile/partition_section"

describe Y2Autoinstallation::Presenters::Partition do
let(:partitioning) do
Y2Storage::AutoinstProfile::PartitioningSection.new_from_hashes(part_hashes)
end

let(:part_hashes) do
[{ "type" => :CT_DISK }]
end

let(:section) { Y2Storage::AutoinstProfile::PartitionSection.new }

let(:drive_section) do
sect = partitioning.drives.first
sect.partitions << section
sect
end

let(:drive) { Y2Autoinstallation::Presenters::Drive.new(drive_section) }

subject { drive.partitions.first }

describe "#update" do
context "when file system attributes are given" do
let(:values) do
{ filesystem: :ext4, mount: "/home" }
end

it "sets the file system attributes" do
subject.update(values)
expect(subject.section.filesystem).to eq(:ext4)
expect(subject.section.mount).to eq("/home")
end

it "clears non filesystem specific attributes" do
subject.update(values)
expect(subject.section.raid_name).to be_nil
end
end

context "when RAID attributes are given" do
let(:values) do
{ raid_name: "/dev/md1" }
end

it "sets the RAID attributes" do
subject.update(values)
expect(section.raid_name).to eq("/dev/md1")
end

it "clears non RAID specific attributes" do
subject.update(values)
expect(section.filesystem).to be_nil
expect(section.mount).to be_nil
end
end
end

describe "#usage" do
let(:section) do
Y2Storage::AutoinstProfile::PartitionSection.new_from_hashes(attrs)
end

context "when the section refers to a file system" do
let(:attrs) { { filesystem: :ext4 } }

it "returns :filesystem" do
expect(subject.usage).to eq(:filesystem)
end
end

context "when the section refers to a RAID member" do
let(:attrs) { { raid_name: "/dev/md0" } }

it "returns :raid" do
expect(subject.usage).to eq(:raid)
end
end

context "when the section refers to an LVM PV" do
let(:attrs) { { lvm_group: "system" } }

it "returns :lvm_pv" do
expect(subject.usage).to eq(:lvm_pv)
end
end
end

describe "#available_lvm_groups" do
context "when there are no LVM drive sections" do
it "returns an empty collection" do
expect(subject.available_lvm_groups).to eq([])
end
end

context "when there are LVM drive section" do
let(:part_hashes) do
[
{ "type" => :CT_DISK },
{ "type" => :CT_LVM, "device" => "/dev/vg-0" },
{ "type" => :CT_LVM, "device" => "/dev/vg-1" }
]
end

it "returns a collection of LVM drive sections device" do
expect(subject.available_lvm_groups).to eq(["vg-0", "vg-1"])
end
end
end
end
104 changes: 3 additions & 101 deletions test/lib/storage_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

require_relative "../test_helper"
require "autoinstall/storage_controller"
require "autoinstall/presenters"
require "y2storage/autoinst_profile/partitioning_section"
require "y2storage/autoinst_profile/partition_section"

Expand All @@ -29,110 +30,11 @@
Y2Storage::AutoinstProfile::PartitioningSection.new_from_hashes([])
end

describe "#add" do
describe "#add_drive" do
it "adds a new section with the given type" do
subject.add_drive(:disk)
subject.add_drive(Y2Autoinstallation::Presenters::DriveType::DISK)
new_drive = partitioning.drives.first
expect(new_drive.type).to eq(:CT_DISK)
end
end

describe "#update_partition" do
let(:section) do
Y2Storage::AutoinstProfile::PartitionSection.new_from_hashes(
filesystem: :btrfs,
mount: "/",
raid_name: "/dev/md0"
)
end

context "when file system attributes are given" do
let(:values) do
{ filesystem: :ext4, mount: "/home" }
end

it "sets the file system attributes" do
subject.update_partition(section, values)
expect(section.filesystem).to eq(:ext4)
expect(section.mount).to eq("/home")
end

it "clears non filesystem specific attributes" do
subject.update_partition(section, values)
expect(section.raid_name).to be_nil
end
end

context "when RAID attributes are given" do
let(:values) do
{ raid_name: "/dev/md1" }
end

it "sets the RAID attributes" do
subject.update_partition(section, values)
expect(section.raid_name).to eq("/dev/md1")
end

it "clears non RAID specific attributes" do
subject.update_partition(section, values)
expect(section.filesystem).to be_nil
expect(section.mount).to be_nil
end
end
end

describe "#partition_usage" do
let(:section) do
Y2Storage::AutoinstProfile::PartitionSection.new_from_hashes(attrs)
end

context "when the section refers to a file system" do
let(:attrs) { { filesystem: :ext4 } }

it "returns :filesystem" do
expect(subject.partition_usage(section)).to eq(:filesystem)
end
end

context "when the section refers to a RAID member" do
let(:attrs) { { raid_name: "/dev/md0" } }

it "returns :raid" do
expect(subject.partition_usage(section)).to eq(:raid)
end
end

context "when the section refers to an LVM PV" do
let(:attrs) { { lvm_group: "system" } }

it "returns :lvm_pv" do
expect(subject.partition_usage(section)).to eq(:lvm_pv)
end
end
end

describe "#lvm_devices" do
context "when there are no LVM drive sections" do
it "returns an empty collection" do
expect(subject.lvm_devices).to eq([])
end
end

context "when there are LVM drive section" do
before do
subject.add_drive(:lvm)
subject.add_drive(:lvm)

vg0 = subject.partitioning.drives[0]
vg1 = subject.partitioning.drives[1]

subject.update_drive(vg0, device: "/dev/vg-0")
subject.update_drive(vg1, device: "/dev/vg-1")
end

it "returns a collection of LVM drive sections device" do
expect(subject.lvm_devices).to eq(["vg-0", "vg-1"])
end
end
end
end
17 changes: 6 additions & 11 deletions test/lib/widgets/storage/add_children_button_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,25 @@
# find current contact information at www.suse.com.

require_relative "../../../test_helper"
require "autoinstall/widgets/storage/add_children_button"
require "autoinstall/widgets/storage/add_partition_button"
require "autoinstall/storage_controller"
require "cwm/rspec"

describe Y2Autoinstallation::Widgets::Storage::AddChildrenButton do
subject(:widget) { described_class.new(controller, section) }
describe Y2Autoinstallation::Widgets::Storage::AddPartitionButton do
subject(:widget) { described_class.new(controller) }

include_examples "CWM::PushButton"

let(:controller) { Y2Autoinstallation::StorageController.new(partitioning) }
let(:partitioning) do
Y2Storage::AutoinstProfile::PartitioningSection.new_from_hashes([])
end
let(:section) do
Y2Storage::AutoinstProfile::DriveSection.new_from_hashes(
type: :CT_DISK,
filesystem: :btrfs,
mount: "/home"
Y2Storage::AutoinstProfile::PartitioningSection.new_from_hashes(
[{ type: :CT_DISK, device: "/dev/sda" }]
)
end

describe "#handle" do
it "adds new partition section" do
expect(controller).to receive(:add_partition).with(section)
expect(controller).to receive(:add_partition)
widget.handle
end
end
Expand Down
22 changes: 10 additions & 12 deletions test/lib/widgets/storage/add_drive_button_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,33 @@
end

describe "#handle" do
let(:event) do
{ "ID" => :"add_#{type.to_sym}" }
end

context "adding a disk" do
let(:event) do
{ "ID" => :add_disk }
end
let(:type) { Y2Autoinstallation::Presenters::DriveType::DISK }

it "adds a disk drive section" do
expect(controller).to receive(:add_drive).with(:disk)
expect(controller).to receive(:add_drive).with(type)
subject.handle(event)
end
end

context "adding a RAID" do
let(:event) do
{ "ID" => :add_raid }
end
let(:type) { Y2Autoinstallation::Presenters::DriveType::RAID }

it "adds a RAID drive section" do
expect(controller).to receive(:add_drive).with(:raid)
expect(controller).to receive(:add_drive).with(type)
subject.handle(event)
end
end

context "adding an LVM" do
let(:event) do
{ "ID" => :add_lvm }
end
let(:type) { Y2Autoinstallation::Presenters::DriveType::LVM }

it "adds an LVM drive section" do
expect(controller).to receive(:add_drive).with(:lvm)
expect(controller).to receive(:add_drive).with(type)
subject.handle(event)
end
end
Expand Down
9 changes: 4 additions & 5 deletions test/lib/widgets/storage/disk_page_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

require_relative "../../../test_helper"
require "autoinstall/widgets/storage/disk_page"
require "autoinstall/storage_controller"
require "autoinstall/presenters"
require "y2storage/autoinst_profile"
require "cwm/rspec"

describe Y2Autoinstallation::Widgets::Storage::DiskPage do
subject { described_class.new(controller, drive) }
subject { described_class.new(drive) }

include_examples "CWM::Page"

Expand All @@ -33,8 +33,7 @@
[{ "type" => :CT_DISK }]
)
end
let(:drive) { partitioning.drives.first }
let(:controller) { Y2Autoinstallation::StorageController.new(partitioning) }
let(:drive) { Y2Autoinstallation::Presenters::Drive.new(partitioning.drives.first) }

let(:disk_device_widget) do
instance_double(
Expand Down Expand Up @@ -92,7 +91,7 @@
let(:device) { "" }

it "does not include the device" do
expect(subject.label).to eq("Disk")
expect(subject.label).to eq("Drive (Disk)")
end
end
end
Expand Down
7 changes: 1 addition & 6 deletions test/lib/widgets/storage/filesystem_attrs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,11 @@

require_relative "../../../test_helper"
require "y2storage"
require "autoinstall/storage_controller"
require "autoinstall/widgets/storage/filesystem_attrs"
require "cwm/rspec"

describe Y2Autoinstallation::Widgets::Storage::FilesystemAttrs do
subject { described_class.new(controller, section) }

let(:controller) do
instance_double(Y2Autoinstallation::StorageController)
end
subject { described_class.new(section) }

let(:section) do
Y2Storage::AutoinstProfile::PartitionSection.new
Expand Down
Loading

0 comments on commit b3e1a39

Please sign in to comment.