Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Dec 9, 2021
1 parent 5b22eb8 commit 3b715bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 51 deletions.
2 changes: 2 additions & 0 deletions src/lib/registration/sw_mgmt.rb
Expand Up @@ -132,6 +132,8 @@ def self.check_repositories
# @return [Hash,nil] with pkg-binding format; return nil if the
# given self_update_id is empty
def self.installer_update_base_product(self_update_id, version = "")
return if self_update_id.empty?

product_info = {
"name" => self_update_id,
"arch" => Yast::Arch.rpm_arch,
Expand Down
31 changes: 12 additions & 19 deletions test/registration_spec.rb
Expand Up @@ -215,6 +215,7 @@

describe "#get_updates_list" do
let(:self_update_id) { "SLES" }
let(:self_update_version) { "15.4" }
let(:base_product) { { "name" => "base" } }
let(:installer_update_base_product) { { "name" => self_update_id } }
let(:remote_product) { { "name" => "base" } }
Expand All @@ -233,34 +234,26 @@
end

context "when the control file defines a self_update_id" do
it "returns updates list from the server for the self update id" do
it "returns updates list from the server for the self update id and version" do
allow(Yast::ProductFeatures).to receive(:GetStringFeature)
.with("globals", "self_update_id").and_return(self_update_id)
expect(Registration::SwMgmt).to receive(:installer_update_base_product)
.with(self_update_id).and_return(installer_update_base_product)
expect(Registration::SwMgmt).to receive(:remote_product)
.with(installer_update_base_product).and_return(installer_update_base_product)
expect(suse_connect).to receive(:list_installer_updates)
.with(installer_update_base_product, anything)
.and_return(updates)
expect(subject.get_updates_list).to eq(updates)
end
end

context "when the control file does not define a self_update_id" do
it "returns updates list from the server for the base product" do
allow(Yast::ProductFeatures).to receive(:GetStringFeature)
.with("globals", "self_update_id").and_return("")
expect(Registration::SwMgmt).to receive(:remote_product).with(base_product)
.and_return(remote_product)
expect(suse_connect).to receive(:list_installer_updates).with(remote_product, anything)
.and_return(updates)
.with("globals", "self_update_version").and_return(self_update_version)
expect(suse_connect).to receive(:list_installer_updates) do |product, _options|
expect(product.identifier).to eq("SLES")
expect(product.version).to eq("15.4")
updates
end
expect(subject.get_updates_list).to eq(updates)
end
end

context "when an exception connecting to the server takes place" do
before do
allow(Yast::ProductFeatures).to receive(:GetStringFeature)
.with("globals", "self_update_id").and_return(self_update_id)
allow(Yast::ProductFeatures).to receive(:GetStringFeature)
.with("globals", "self_update_version").and_return(self_update_version)
allow(suse_connect).to receive(:list_installer_updates).and_raise(Timeout::Error)
end

Expand Down
37 changes: 5 additions & 32 deletions test/sw_mgmt_spec.rb
Expand Up @@ -123,42 +123,15 @@
end

describe ".installer_update_base_product" do
let(:base_product) do
instance_double(Y2Packager::ProductSpec, name: "dummy", version: "15.0", arch: "x86_64")
end
let(:base_products) { [base_product] }

before do
allow(Y2Packager::ProductSpec).to receive(:base_products).and_return(base_products)
allow(Y2Packager::MediumType).to receive(:online?).and_return(false)
allow(Y2Packager::MediumType).to receive(:offline?).and_return(false)
end

it "returns nil if the given self_update_id is empty" do
expect(subject.installer_update_base_product("")).to eq(nil)
end

context "when there is no base product available" do
let(:base_products) { [] }

it "returns nil" do
allow(Y2Packager::ProductSpec).to receive(:base_products).and_return([])
expect(subject.installer_update_base_product("self_update_id")).to eq(nil)
end
end

context "when there is some product available" do
it "returns a hash with the product keys 'name', 'version', 'arch' and 'release_type' " do
product = subject.installer_update_base_product("self_update_id")
expect(product).to be_a(Hash)
expect(product.keys.size).to eq(4)
expect(product).to include("name", "version", "arch", "release_type")
end

it "uses the given self_update_id as the product name returned" do
product = subject.installer_update_base_product("self_update_id")
expect(product["name"]).to eq("self_update_id")
end
it "returns the product hash" do
expect(subject.installer_update_base_product("SLES", "15.4")).to include(
"name" => "SLES",
"version" => "15.4"
)
end
end

Expand Down

0 comments on commit 3b715bd

Please sign in to comment.