Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Aug 2, 2019
1 parent f7e82e7 commit 52e3080
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
16 changes: 15 additions & 1 deletion src/lib/y2packager/clients/inst_repositories_initialization.rb
Expand Up @@ -88,7 +88,14 @@ def init_installation_repositories
# @see https://github.com/yast/yast-packager/blob/7e1a0bbb90823b03c15d92f408036a560dca8aa3/src/modules/Packages.rb#L1876
# @see https://github.com/yast/yast-packager/blob/fbc396df910e297915f9f785fc460e72e30d1948/src/modules/Packages.rb#L1905
def adjust_base_product_selection
if products.size == 1
if forced_base_product
log.info("control.xml wants to force the #{forced_base_product.name} product")

forced_base_product.select
discarded_products = products - [forced_base_product]

log.info("Ignoring the other products: #{discarded_products.map(&:name).join(", ")}")
elsif products.size == 1
products.first.select
else
products.each(&:restore)
Expand All @@ -101,6 +108,13 @@ def adjust_base_product_selection
def products
@products ||= Y2Packager::Product.available_base_products
end

# Return the forced base product (if any)
#
# @return [Y2Product, nil]
def forced_base_product
@forced_base_product ||= Y2Packager::Product.forced_base_product
end
end
end
end
18 changes: 16 additions & 2 deletions test/lib/clients/inst_repositories_initialization_test.rb
Expand Up @@ -7,15 +7,16 @@
subject(:client) { described_class.new }

let(:success) { true }
let(:prod1) { instance_double(Y2Packager::Product, select: nil) }
let(:prod2) { instance_double(Y2Packager::Product, select: nil) }
let(:prod1) { instance_double(Y2Packager::Product, name: "Prod1", select: nil) }
let(:prod2) { instance_double(Y2Packager::Product, name: "Prod2", select: nil) }
let(:products) { [prod1] }

describe "#main" do
before do
allow(Yast::Packages).to receive(:InitializeCatalogs)
allow(Yast::Packages).to receive(:InitializeAddOnProducts)
allow(Yast::Packages).to receive(:InitFailed).and_return(!success)
allow(Y2Packager::Product).to receive(:forced_base_product)
allow(Y2Packager::Product).to receive(:available_base_products).and_return(products)
allow(Y2Packager::SelfUpdateAddonRepo).to receive(:present?).and_return(false)
end
Expand Down Expand Up @@ -63,6 +64,19 @@
end
end

context "when a product is forced to be used" do
let(:products) { [prod1, prod2] }

before do
allow(Y2Packager::Product).to receive(:forced_base_product).and_return(prod2)
end

it "selects the product for installation" do
expect(prod2).to receive(:select)
client.main
end
end

context "when more than one product is available" do
let(:products) { [prod1, prod2] }

Expand Down

0 comments on commit 52e3080

Please sign in to comment.