Skip to content

Commit

Permalink
Add more unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed May 20, 2020
1 parent 39025c9 commit 9f7612e
Show file tree
Hide file tree
Showing 9 changed files with 367 additions and 133 deletions.
61 changes: 33 additions & 28 deletions test/lib/widgets/storage/common_partition_attrs_test.rb
Expand Up @@ -19,37 +19,16 @@

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

describe Y2Autoinstallation::Widgets::Storage::CommonPartitionAttrs do
include_examples "CWM::CustomWidget"

let(:partitioning) do
Y2Storage::AutoinstProfile::PartitioningSection.new_from_hashes(part_hashes)
end
subject { described_class.new(section) }

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

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 { described_class.new(drive.partitions.first) }

let(:section) do
Y2Storage::AutoinstProfile::PartitionSection.new
end

describe "#contents" do
it "constains a widget to set the create option" do
widget = subject.contents.nested_find do |w|
Expand Down Expand Up @@ -92,9 +71,7 @@
end
end

describe "#values" do
let(:partition_uuid) { "6dab21de-f0e1-4cab-8b60-0332f06f4f28" }

shared_context "mock widgets" do
let(:create_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::Create, value: "false")
end
Expand All @@ -104,11 +81,14 @@
let(:resize_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::Resize, value: "true")
end
let(:size_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::Size, value: "1TB")
end
let(:partition_nr_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::PartitionNr, value: 131)
end
let(:uuid_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::Uuid, value: partition_uuid)
instance_double(Y2Autoinstallation::Widgets::Storage::Uuid, value: "partition-uuid")
end

before do
Expand All @@ -118,11 +98,32 @@
.and_return(format_widget)
allow(Y2Autoinstallation::Widgets::Storage::Resize).to receive(:new)
.and_return(resize_widget)
allow(Y2Autoinstallation::Widgets::Storage::Size).to receive(:new)
.and_return(size_widget)
allow(Y2Autoinstallation::Widgets::Storage::PartitionNr).to receive(:new)
.and_return(partition_nr_widget)
allow(Y2Autoinstallation::Widgets::Storage::Uuid).to receive(:new)
.and_return(uuid_widget)
end
end

describe "#init" do
include_context "mock widgets"

it "sets initial values" do
expect(create_widget).to receive(:value=)
expect(format_widget).to receive(:value=)
expect(resize_widget).to receive(:value=)
expect(size_widget).to receive(:value=)
expect(partition_nr_widget).to receive(:value=)
expect(uuid_widget).to receive(:value=)

subject.init
end
end

describe "#values" do
include_context "mock widgets"

it "includes create" do
expect(subject.values).to include("create" => "false")
Expand All @@ -136,12 +137,16 @@
expect(subject.values).to include("resize" => "true")
end

it "includes size" do
expect(subject.values).to include("size" => "1TB")
end

it "includes partition_nr" do
expect(subject.values).to include("partition_nr" => 131)
end

it "includes uuid" do
expect(subject.values).to include("uuid" => partition_uuid)
expect(subject.values).to include("uuid" => "partition-uuid")
end
end
end
32 changes: 20 additions & 12 deletions test/lib/widgets/storage/encryption_attrs_test.rb
Expand Up @@ -31,21 +31,29 @@

include_examples "CWM::CustomWidget"

describe "#values" do
let(:crypt_fs_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::CryptFs, value: true)
end
let(:crypt_key_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::CryptKey, value: "xxxxx")
end
let(:crypt_fs_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::CryptFs, value: true)
end
let(:crypt_key_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::CryptKey, value: "xxxxx")
end

before do
allow(Y2Autoinstallation::Widgets::Storage::CryptFs).to receive(:new)
.and_return(crypt_fs_widget)
allow(Y2Autoinstallation::Widgets::Storage::CryptKey).to receive(:new)
.and_return(crypt_key_widget)
before do
allow(Y2Autoinstallation::Widgets::Storage::CryptFs).to receive(:new)
.and_return(crypt_fs_widget)
allow(Y2Autoinstallation::Widgets::Storage::CryptKey).to receive(:new)
.and_return(crypt_key_widget)
end

describe "#init" do
it "sets initial values" do
expect(crypt_fs_widget).to receive(:value=)
expect(crypt_key_widget).to receive(:value=)
widget.init
end
end

describe "#values" do
it "includes crypt_fs" do
expect(widget.values).to include("crypt_fs" => true)
end
Expand Down
68 changes: 40 additions & 28 deletions test/lib/widgets/storage/filesystem_attrs_test.rb
Expand Up @@ -31,36 +31,48 @@

include_examples "CWM::CustomWidget"

describe "#values" do
let(:label_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::Label, value: "mydata")
end
let(:mount_point_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::Mount, value: "swap")
end
let(:mountby_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::Mount, value: :label)
end
let(:mkfs_options_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::MkfsOptions, value: "-I 128")
end
let(:fstopt_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::Fstopt, value: "ro,noatime,user")
end
let(:label_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::Label, value: "mydata")
end
let(:mount_point_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::Mount, value: "swap")
end
let(:mountby_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::Mount, value: :label)
end
let(:mkfs_options_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::MkfsOptions, value: "-I 128")
end
let(:fstopt_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::Fstopt, value: "ro,noatime,user")
end

before do
allow(Y2Autoinstallation::Widgets::Storage::Label).to receive(:new)
.and_return(label_widget)
allow(Y2Autoinstallation::Widgets::Storage::Mount).to receive(:new)
.and_return(mount_point_widget)
allow(Y2Autoinstallation::Widgets::Storage::Mountby).to receive(:new)
.and_return(mountby_widget)
allow(Y2Autoinstallation::Widgets::Storage::MkfsOptions).to receive(:new)
.and_return(mkfs_options_widget)
allow(Y2Autoinstallation::Widgets::Storage::Fstopt).to receive(:new)
.and_return(fstopt_widget)
end

describe "#init" do
it "sets initial values" do
expect(label_widget).to receive(:value=)
expect(mount_point_widget).to receive(:value=)
expect(mountby_widget).to receive(:value=)
expect(mkfs_options_widget).to receive(:value=)
expect(fstopt_widget).to receive(:value=)

before do
allow(Y2Autoinstallation::Widgets::Storage::Label).to receive(:new)
.and_return(label_widget)
allow(Y2Autoinstallation::Widgets::Storage::Mount).to receive(:new)
.and_return(mount_point_widget)
allow(Y2Autoinstallation::Widgets::Storage::Mountby).to receive(:new)
.and_return(mountby_widget)
allow(Y2Autoinstallation::Widgets::Storage::MkfsOptions).to receive(:new)
.and_return(mkfs_options_widget)
allow(Y2Autoinstallation::Widgets::Storage::Fstopt).to receive(:new)
.and_return(fstopt_widget)
widget.init
end
end

describe "#values" do
it "includes label" do
expect(widget.values).to include("label" => "mydata")
end
Expand All @@ -77,7 +89,7 @@
expect(widget.values).to include("mkfs_options" => "-I 128")
end

it "includes fstopt" do
it "includes fstab options" do
expect(widget.values).to include("fstab_options" => "ro,noatime,user")
end
end
Expand Down
16 changes: 6 additions & 10 deletions test/lib/widgets/storage/lvm_page_test.rb
Expand Up @@ -90,17 +90,13 @@
end
end

describe "#values" do
it "includes device" do
expect(lvm_page.values).to include("device" => device)
end

it "includes pesize" do
expect(lvm_page.values).to include("pesize" => pesize)
end
describe "#store" do
it "sets the section values" do
subject.store

it "includes keep_unknown_lv" do
expect(lvm_page.values).to include("keep_unknown_lv" => keep_unknown_lv)
expect(drive.device).to eq(device)
expect(drive.pesize).to eq(pesize)
expect(drive.keep_unknown_lv).to eq(keep_unknown_lv)
end
end
end
68 changes: 39 additions & 29 deletions test/lib/widgets/storage/lvm_partition_attrs_test.rb
Expand Up @@ -27,40 +27,50 @@

include_examples "CWM::CustomWidget"

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

let(:lv_name_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::LvName, value: "lv-home")
end
let(:pool_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::Pool, value: false)
end
let(:used_pool_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::UsedPool, value: "my_thin_pool")
end
let(:stripes_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::Stripes, value: 2)
end
let(:stripesize_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::Stripesize, value: 4)
end

describe "#values" do
let(:lv_name_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::LvName, value: "lv-home")
end
let(:pool_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::Pool, value: false)
end
let(:used_pool_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::UsedPool, value: "my_thin_pool")
end
let(:stripes_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::Stripes, value: 2)
end
let(:stripesize_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::Stripesize, value: 4)
end
before do
allow(Y2Autoinstallation::Widgets::Storage::LvName).to receive(:new)
.and_return(lv_name_widget)
allow(Y2Autoinstallation::Widgets::Storage::Pool).to receive(:new)
.and_return(pool_widget)
allow(Y2Autoinstallation::Widgets::Storage::UsedPool).to receive(:new)
.and_return(used_pool_widget)
allow(Y2Autoinstallation::Widgets::Storage::Stripes).to receive(:new)
.and_return(stripes_widget)
allow(Y2Autoinstallation::Widgets::Storage::Stripesize).to receive(:new)
.and_return(stripesize_widget)
end

before do
allow(Y2Autoinstallation::Widgets::Storage::LvName).to receive(:new)
.and_return(lv_name_widget)
allow(Y2Autoinstallation::Widgets::Storage::Pool).to receive(:new)
.and_return(pool_widget)
allow(Y2Autoinstallation::Widgets::Storage::UsedPool).to receive(:new)
.and_return(used_pool_widget)
allow(Y2Autoinstallation::Widgets::Storage::Stripes).to receive(:new)
.and_return(stripes_widget)
allow(Y2Autoinstallation::Widgets::Storage::Stripesize).to receive(:new)
.and_return(stripesize_widget)
describe "#init" do
it "sets initial values" do
expect(lv_name_widget).to receive(:value=)
expect(pool_widget).to receive(:value=)
expect(used_pool_widget).to receive(:value=)
expect(stripes_widget).to receive(:value=)
expect(stripesize_widget).to receive(:value=)

widget.init
end
end

describe "#values" do
it "includes lv_name" do
expect(widget.values).to include("lv_name" => "lv-home")
end
Expand Down
7 changes: 4 additions & 3 deletions test/lib/widgets/storage/lvm_pv_attrs_test.rb
Expand Up @@ -35,7 +35,8 @@
Y2Storage::AutoinstProfile::PartitioningSection.new_from_hashes(
[
{ "type" => :CT_DISK, "partitions" => [{}] },
{ "device" => "/dev/system", "type" => :CT_LVM, "pesize" => "64" }
{ "type" => :CT_LVM, "device" => "/dev/system" },
{ "type" => :CT_LVM, "device" => "/dev/data" }
]
)
end
Expand All @@ -55,7 +56,7 @@

describe "#init" do
it "sets the available lvm groups" do
expect(lvm_group_widget).to receive(:items=).with(["system"])
expect(lvm_group_widget).to receive(:items=).with(["system", "data"])
widget.init
end

Expand All @@ -67,7 +68,7 @@

describe "#values" do
it "includes `lvm_group`" do
expect(widget.values).to match(a_hash_including("lvm_group" => anything))
expect(widget.values).to include("lvm_group" => anything)
end
end
end

0 comments on commit 9f7612e

Please sign in to comment.