Skip to content

Commit

Permalink
Add more tests to UpdateRepositoryFinder
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Feb 13, 2017
1 parent b6a6d72 commit 4e3f653
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/lib/installation/update_repositories_finder.rb
Expand Up @@ -132,7 +132,6 @@ def update_urls_from_connect
ret
end


# Converts the string into an URI if it's valid
#
# It substitutes $arch pattern with the architecture of the current system.
Expand Down
152 changes: 137 additions & 15 deletions test/lib/update_repositories_finder_test.rb
Expand Up @@ -6,6 +6,12 @@
Yast.import "Linuxrc"

describe Installation::UpdateRepositoriesFinder do
# Registration::Storage::InstallationOptions fake
class FakeInstallationOptions
include Singleton
attr_accessor :custom_url
end

describe "#updates" do
let(:url_from_linuxrc) { nil }
let(:url_from_control) { "http://update.opensuse.org/\$arch/42.2" }
Expand All @@ -19,20 +25,17 @@

before do
stub_const("Yast::Profile", ay_profile)
allow(Installation::UpdateRepository).to receive(:new)
.and_return(repo)
allow(Yast::Linuxrc).to receive(:InstallInf).with("SelfUpdate")
.and_return(url_from_linuxrc)
end

context "when URL was specified via Linuxrc" do
let(:url_from_linuxrc) { "http://example.net/sles12/" }

it "returns the custom URL from Linuxrc" do
it "returns the updates repository using the URL from Linuxrc" do
expect(Installation::UpdateRepository).to receive(:new)
.with(URI(url_from_linuxrc), :user)
update = finder.updates.first
expect(update).to eq(repo)
.with(URI(url_from_linuxrc), :user).and_return(repo)
expect(finder.updates).to eq([repo])
end
end

Expand All @@ -44,11 +47,10 @@
allow(Yast::Mode).to receive(:auto).and_return(true)
end

it "returns the custom URL from the profile" do
it "returns the updates repository using the custom URL from the profile" do
expect(Installation::UpdateRepository).to receive(:new)
.with(URI(profile_url), :user)
update = finder.updates.first
expect(update).to eq(repo)
.with(URI(profile_url), :user).and_return(repo)
expect(finder.updates).to eq([repo])
end
end

Expand All @@ -63,11 +65,131 @@
.and_return(nil)
end

it "returns the URL from the control file" do
expect(Installation::UpdateRepository).to receive(:new)
.with(URI(real_url_from_control), :default)
update = finder.updates.first
expect(update).to eq(repo)
context "when system is not registrable" do
before do
hide_const("::Registration::UrlHelpers")
end

it "gets the URL from the control file" do
expect(Installation::UpdateRepository).to receive(:new)
.with(URI(real_url_from_control), :default).and_return(repo)
expect(finder.updates).to eq([repo])
end
end

context "when a SCC/SMT server defines the URL" do
let(:smt0) { double("service", slp_url: "http://update.suse.com") }
let(:smt1) { double("service", slp_url: "http://update.example.net") }

let(:update0) do
OpenStruct.new(
name: "SLES-12-Installer-Updates-0",
url: "http://update.suse.com/updates/sle12/12.2"
)
end

let(:update1) do
OpenStruct.new(
name: "SLES-12-Installer-Updates-1",
url: "http://update.suse.com/updates/sles12/12.2"
)
end

let(:regservice_selection) { Class.new }

let(:url_helpers) { double("url_helpers", registration_url: smt0.slp_url, slp_discovery: []) }
let(:regurl) { nil }

let(:registration) { double("registration", url: smt0.slp_url) }
let(:registration_class) { double("registration_class", new: registration) }

let(:updates) { [update0] }

before do
stub_const("Registration::Registration", registration_class)
stub_const("Registration::UrlHelpers", url_helpers)
stub_const("Registration::UI::RegserviceSelectionDialog", regservice_selection)
stub_const("Registration::Storage::InstallationOptions", FakeInstallationOptions)

allow(url_helpers).to receive(:service_url) { |u| u }
allow(url_helpers).to receive(:boot_reg_url).and_return(regurl)
allow(registration).to receive(:get_updates_list).and_return(updates)
end

it "gets the URL defined by the server" do
expect(Installation::UpdateRepository).to receive(:new)
.with(URI(update0.url), :default).and_return(repo)
expect(finder.updates).to eq([repo])
end

context "when the registration server returns an empty list" do
let(:updates) { [] }

it "falls back to use updates URL defined in the control file" do
expect(Installation::UpdateRepository).to receive(:new)
.with(URI(real_url_from_control), :default).and_return(repo)
expect(finder.updates).to eq([repo])
end
end

context "when more than one SMT server is found via SLP" do
before do
allow(url_helpers).to receive(:slp_discovery).and_return([smt0, smt1])
end

context "if the user selects a SMT server" do
before do
allow(regservice_selection).to receive(:run).and_return(smt0)
end

it "asks the SMT server for the updates URLs" do
expect(registration_class).to receive(:new).with(smt0.slp_url)
.and_return(registration)
expect(Installation::UpdateRepository).to receive(:new)
.with(URI(update0.url), :default).and_return(repo)
finder.updates
end
end

context "if user cancels the dialog" do
before do
allow(regservice_selection).to receive(:run).and_return(:cancel)
end

it "falls back to use updates URL defined in the control file" do
expect(registration).to_not receive(:get_updates_list)
expect(Installation::UpdateRepository).to receive(:new)
.with(URI(real_url_from_control), :default).and_return(repo)
expect(finder.updates).to eq([repo])
end
end
end

context "if users selects the SCC server" do
before do
allow(regservice_selection).to receive(:run).and_return(:scc)
end

it "asks the SCC server for the updates URLs" do
expect(registration_class).to receive(:new).with(nil)
.and_return(registration)
expect(registration).to receive(:get_updates_list)
.and_return([update1])
expect(Installation::UpdateRepository).to receive(:new)
.with(URI(update1.url), :default).and_return(repo)
finder.updates
end
end

context "when a regurl was specified via Linuxrc" do
let(:regurl) { "http://regserver.example.net" }

it "asks the SCC server for the updates URLs" do
expect(registration_class).to receive(:new).with(regurl)
.and_return(registration)
finder.updates
end
end
end
end
end
Expand Down

0 comments on commit 4e3f653

Please sign in to comment.