Skip to content

Commit

Permalink
Add AutoinstSize#unlimited?
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Nov 28, 2017
1 parent d8dd9d5 commit aa0de40
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib/y2storage/proposal/autoinst_devices_planner.rb
Expand Up @@ -371,7 +371,7 @@ def assign_size_to_partition(disk, partition, part_section)

partition.min_size = size_info.min
partition.max_size = size_info.max
partition.weight = 1 if size_info.max == DiskSize.unlimited
partition.weight = 1 if size_info.unlimited?
true
end

Expand All @@ -395,7 +395,7 @@ def assign_size_to_lv(vg, lv, lv_section)
lv.min_size = size_info.min
lv.max_size = size_info.max
end
lv.weight = 1 if size_info.max == DiskSize.unlimited
lv.weight = 1 if size_info.unlimited?

true
end
Expand Down
7 changes: 7 additions & 0 deletions src/lib/y2storage/proposal/autoinst_size.rb
Expand Up @@ -42,6 +42,13 @@ def initialize(value, min: nil, max: nil, weight: nil, percentage: nil)
@weight = weight
@percentage = percentage
end

# Determines whether the size is unlimited
#
# @return [Boolean] +true+ if unlimited; +false+ otherwise.
def unlimited?
!!max && max.unlimited?
end
end
end
end
55 changes: 55 additions & 0 deletions test/y2storage/proposal/autoinst_size_test.rb
@@ -0,0 +1,55 @@
#!/usr/bin/env rspec
# encoding: utf-8

# Copyright (c) [2017] 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 "../spec_helper"
require "y2storage/proposal/autoinst_size"

describe Y2Storage::Proposal::AutoinstSize do

subject(:autoinst_size) { described_class.new("10GB", max: max) }

describe "#unlimited?" do
context "when max size is unlimited" do
let(:max) { Y2Storage::DiskSize.unlimited }

it "returns true" do
expect(autoinst_size).to be_unlimited
end
end

context "when max size is nil" do
let(:max) { nil }

it "returns false" do
expect(autoinst_size).to_not be_unlimited
end
end

context "when max size is not unlimited" do
let(:max) { Y2Storage::DiskSize.GiB(10) }

it "returns false" do
expect(autoinst_size).to_not be_unlimited
end
end
end
end

0 comments on commit aa0de40

Please sign in to comment.