Skip to content
Permalink
Browse files

Rename licenses handlers/fetchers from :rpm to :libzypp

  • Loading branch information...
imobachgs committed Apr 5, 2018
1 parent ca36cfb commit 67ea5dd5d83ea40be2df2d28035caaecf8a825eb
@@ -54,12 +54,12 @@ y2rns_fetchers_DATA = \
y2licenses_fetchersdir = "${yast2dir}/lib/y2packager/licenses_fetchers"
y2licenses_fetchers_DATA = \
lib/y2packager/licenses_fetchers/base.rb \
lib/y2packager/licenses_fetchers/rpm.rb
lib/y2packager/licenses_fetchers/libzypp.rb

y2licenses_handlersdir = "${yast2dir}/lib/y2packager/licenses_handlers"
y2licenses_handlers_DATA = \
lib/y2packager/licenses_handlers/base.rb \
lib/y2packager/licenses_handlers/rpm.rb
lib/y2packager/licenses_handlers/libzypp.rb

EXTRA_DIST = $(module_DATA) $(ynclude_DATA) $(ylib_DATA) $(y2packager_DATA) $(y2rns_fetchers_DATA) \
$(y2licenses_fetchers_DATA) $(y2licenses_handlers_DATA)
@@ -36,9 +36,9 @@ class << self
# This method uses a cache to return the same license if it was already
# used for another product.
#
# @param product_name [String] Product's name
# @param source [:rpm,nil] Source to get the license from. For the time being,
# only :rpm is supported.
# @param product_name [String] Product's name
# @param source [:libzypp,nil] Source to get the license from. For the time being,
# only :libzypp is supported.
# @param content [String] License content. If this argument is given, this
# string is used as the license's content (and `source` is ignored).
# @return [License]
@@ -79,9 +79,9 @@ def cache
#
# Bear in mind that `fetcher` will be ignored if `content` is specified.
#
# @param fetcher [:rpm] Fetcher to retrieve licenses information. For the time
# being, only :rpm is supported.
# @param content [String] License content. If this argument is given, this
# @param fetcher [:libzypp] Fetcher to retrieve licenses information. For the time
# being, only :libzypp is supported.
# @param content [String] License content. If this argument is given, this
# string is used as the license's content (and `source` is ignored).
def initialize(fetcher: nil, content: nil)
@accepted = false
@@ -11,7 +11,7 @@
# ------------------------------------------------------------------------------

require "yast"
require "y2packager/licenses_fetchers/rpm"
require "y2packager/licenses_fetchers/libzypp"

module Y2Packager
# This module contains licenses fetchers
@@ -21,8 +21,8 @@ module Y2Packager
module LicensesFetchers
# Return the licenses proper fetcher for a given source
#
# @param source [:rpm,nil] Source to fetch license from (only :rpm is supported)
# @param product_name [String] Product's name
# @param source [:libzypp,nil] Source to fetch license from (only :rpm is supported)
# @param product_name [String] Product's name
def self.for(source, product_name)
klass = const_get(source.to_s.capitalize)
klass.new(product_name)
@@ -16,7 +16,7 @@ module Y2Packager
module LicensesFetchers
# This class is responsible for obtaining the license and license content
# of a given product from libzypp.
class Rpm < Base
class Libzypp < Base
# Return the license text to be confirmed
#
# @param lang [String] Language
@@ -10,7 +10,7 @@
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# ------------------------------------------------------------------------------

require "y2packager/licenses_handlers/rpm"
require "y2packager/licenses_handlers/libzypp"

module Y2Packager
# This module contains licenses handlers
@@ -21,8 +21,8 @@ module Y2Packager
module LicensesHandlers
# Return the licenses proper fetcher for a given source
#
# @param source [:rpm,nil] Source to fetch license from (only :rpm is supported)
# @param product_name [String] Product's name
# @param source [:libzypp,nil] Source to fetch license from (only :libzypp is supported)
# @param product_name [String] Product's name
# @return [Object]
def self.for(source, product_name)
klass = const_get(source.to_s.capitalize)
@@ -18,7 +18,7 @@ module Y2Packager
module LicensesHandlers
# This class is responsible for interacting with libzypp in order to get/set
# the license acceptance status for a given product
class Rpm < Base
class Libzypp < Base
# Determine whether the license should be accepted or not
#
# @return [Boolean] true if the license acceptance is required
@@ -199,7 +199,7 @@ def label
# @param lang [String] Language
# @return [ProductLicense,nil] Product's license; nil if the license was not found.
def license
@license ||= ProductLicense.find(name, source: :rpm)
@license ||= ProductLicense.find(name, source: :libzypp)
end

# Return the license text to be confirmed
@@ -49,9 +49,9 @@ class << self
#
# This method uses a cache to return an already fetched product license.
#
# @param product_name [String] Product's name
# @param source [:rpm,nil] Source to get the license from. For the time being,
# only :rpm is really supported.
# @param product_name [String] Product's name
# @param source [:libzypp,nil] Source to get the license from. For the time being,
# only :libzypp is really supported.
# @return [ProductLicense]
def find(product_name, source: nil, content: nil)
return cache[product_name] if cache[product_name]
@@ -74,7 +74,7 @@ def clear_cache
#
# @param product_name [String] Product name to get licenses for
# @param source [Symbol] Backend to use when syncing the licenses acceptance status
# (only :rpm is supported)
# (only :libzypp is supported)
def initialize(product_name, license, source: nil)
@product_name = product_name
@license = license
@@ -19,20 +19,20 @@
subject(:license) { Y2Packager::License.new(fetcher: fetcher) }

let(:fetcher) do
instance_double(Y2Packager::LicensesFetchers::Rpm, content: "license")
instance_double(Y2Packager::LicensesFetchers::Libzypp, content: "license")
end

before do
described_class.clear_cache
allow(Y2Packager::LicensesFetchers::Rpm).to receive(:new).and_return(fetcher)
allow(Y2Packager::LicensesFetchers::Libzypp).to receive(:new).and_return(fetcher)
end

describe ".find" do
context "when a source is given" do
it "uses a fetcher to build the license" do
expect(Y2Packager::License).to receive(:new).with(fetcher: fetcher, content: nil)
.and_return(license)
expect(described_class.find("SLES", source: :rpm)).to be(license)
expect(described_class.find("SLES", source: :libzypp)).to be(license)
end
end

@@ -46,8 +46,8 @@

context "when a license with the same ID was already retrieved" do
it "returns the already retrieved instance" do
sles_license = described_class.find("SLES", source: :rpm)
sled_license = described_class.find("SLED", source: :rpm)
sles_license = described_class.find("SLES", source: :libzypp)
sled_license = described_class.find("SLED", source: :libzypp)
expect(sles_license).to be(sled_license)
end
end
@@ -58,8 +58,8 @@
end

it "returns a new license instance" do
sles_license = described_class.find("SLES", source: :rpm)
sled_license = described_class.find("SLED", source: :rpm)
sles_license = described_class.find("SLES", source: :libzypp)
sled_license = described_class.find("SLED", source: :libzypp)
expect(sles_license).to_not be(sled_license)
expect(sles_license.id).to_not eq(sled_license.id)
end
@@ -15,7 +15,7 @@

require "y2packager/product_license"

describe Y2Packager::LicensesHandlers::Rpm do
describe Y2Packager::LicensesHandlers::Libzypp do
subject(:handler) { described_class.new(product_name) }

let(:product_name) { "SLES" }
@@ -31,17 +31,17 @@
end

it "returns a product license for the given product" do
expect(Y2Packager::License).to receive(:find).with("SLES", source: :rpm, content: nil)
expect(Y2Packager::License).to receive(:find).with("SLES", source: :libzypp, content: nil)
.and_return(license)
product_license = described_class.find("SLES", source: :rpm)
product_license = described_class.find("SLES", source: :libzypp)
expect(product_license).to be_a(Y2Packager::ProductLicense)
expect(product_license.license).to eq(license)
end

context "when the product license was already found" do
it "returns the already found instance" do
cached_product_license = described_class.find("SLES", source: :rpm)
product_license = described_class.find("SLES", source: :rpm)
cached_product_license = described_class.find("SLES", source: :libzypp)
product_license = described_class.find("SLES", source: :libzypp)
expect(product_license).to be(cached_product_license)
end
end
@@ -52,7 +52,7 @@
end

it "returns nil" do
expect(described_class.find("SLES", source: :rpm)).to be_nil
expect(described_class.find("SLES", source: :libzypp)).to be_nil
end
end

@@ -192,7 +192,7 @@
end

it "returns the product license" do
expect(Y2Packager::ProductLicense).to receive(:find).with(product.name, source: :rpm)
expect(Y2Packager::ProductLicense).to receive(:find).with(product.name, source: :libzypp)
.and_return(product_license)
expect(product.license).to be(product_license)
end

0 comments on commit 67ea5dd

Please sign in to comment.
You can’t perform that action at this time.