Skip to content

Commit

Permalink
Add unit-tests for AddOnProducts.Export
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Jul 16, 2020
1 parent f8c2169 commit abc0635
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions test/addon_others_test.rb
Expand Up @@ -44,7 +44,7 @@

let(:repo_hash) do
{ "alias" => "user defined",
"url" => "http://xxx.url",
"url" => "http://xxx.url?foo=bar",
"name" => "user_defined",
"priority" => 19,
"product_dir" => "/" }
Expand All @@ -57,6 +57,8 @@
.and_return(installed_products)
allow(Yast::Pkg).to receive(:SourceGetCurrent).with(true)
.and_return([0, 1, 2, 3, 4])
allow(subject).to receive(:require).with("registration/registration")
.and_raise(LoadError)
end

describe "#Read" do
Expand All @@ -72,7 +74,6 @@
end

describe "#Export" do

context "installed products and add-ons are available" do
let(:ret) do
{ "media_url" => repo_hash["url"],
Expand All @@ -82,12 +83,42 @@
"product_dir" => repo_hash["product_dir"] }
end

it "returns an array of user defined repos in AY format" do
before do
allow(Yast::Pkg).to receive(:SourceGeneralData).with(4)
.and_return(repo_hash)
end

it "returns an array of user defined repos in AY format" do
Yast::AddOnOthers.Read()
expect(Yast::AddOnOthers.Export).to eq("add_on_others" => [ret])
end

context "when an add-on is registered" do
let(:registration_module) do
double("Registration::Registration", new: registration)
end

let(:registration) do
instance_double("Registration::Registration", activated_products: [product])
end

let(:product) do
double("SUSE::Connect::Remote::Product", repositories: [scc_repo])
end

let(:scc_repo) do
{ "url" => "http://xxx.url" }
end

before do
allow(subject).to receive(:require).with("registration/registration")
stub_const("Registration::Registration", registration_module)
end

it "does not export such an addon" do
expect(Yast::AddOnOthers.Export).to eq("add_on_others" => [])
end
end
end
end
end

0 comments on commit abc0635

Please sign in to comment.