Skip to content

Commit

Permalink
Add a class to get product specs from libzypp
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Oct 4, 2021
1 parent ba53fd4 commit c1cc9b9
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/lib/y2packager/product_spec_readers/libzypp.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) [2021] 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 "y2packager/product"
require "y2packager/product_spec"

module Y2Packager
module ProductSpecReaders
class Libzypp
def products
Y2Packager::Product.available_base_products.map do |prod|
Y2Packager::ProductSpec.new(
name: prod.name,
display_name: prod.display_name,
version: prod.version,
arch: prod.arch&.to_sym, # TODO: use a symbol (?)
base: prod.category == :base,
order: prod.order
)
end
end
end
end
end
55 changes: 55 additions & 0 deletions test/lib/product_spec_readers/libzypp_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright (c) [2021] 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 "y2packager/product_spec_readers/libzypp"
require "y2packager/product"

describe Y2Packager::ProductSpecReaders::Libzypp do
subject(:reader) { described_class.new }

describe "#products" do
let(:sles) do
Y2Packager::Product.new(
name: "SLES", display_name: "SUSE Linux Enterprise Server", order: 1, version: "15.3",
arch: :x86_64
)
end

let(:sled) do
Y2Packager::Product.new(
name: "SLED", display_name: "SUSE Linux Enterprise Desktop", order: 2, version: "15.3",
arch: :x86_64
)
end

before do
allow(Y2Packager::Product).to receive(:available_base_products).and_return([sles, sled])
end

it "returns an spec for each product" do
specs = reader.products
sles_spec, sled_spec = specs
expect(sles_spec.name).to eq(sles.name)
expect(sles_spec.display_name).to eq(sles.display_name)
expect(sled_spec.name).to eq(sled.name)
expect(sled_spec.display_name).to eq(sled.display_name)
end
end
end

0 comments on commit c1cc9b9

Please sign in to comment.