Skip to content

Commit

Permalink
Added unit tests for the new code
Browse files Browse the repository at this point in the history
test package management init and displaying the progress
  • Loading branch information
lslezak committed Aug 23, 2016
1 parent 6bb0a5a commit 81e57d7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/lib/installation/clients/inst_update_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ def main
log.info("Trying installer update")
installer_updated = update_installer

finish_packager

if installer_updated
# Indicates that the installer was updated.
::FileUtils.touch(update_flag_file)
Expand All @@ -79,6 +77,7 @@ def main
:next
end
ensure
finish_packager
finish_progress
end

Expand Down
50 changes: 49 additions & 1 deletion test/inst_update_installer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def import(_args); end
let(:ay_profile) { double("Yast::Profile", current: profile) }

before do
allow(Yast::GetInstArgs).to receive(:going_back).and_return(false)
allow(Yast::Pkg).to receive(:GetArchitecture).and_return(arch)
allow(Yast::Mode).to receive(:auto).and_return(false)
allow(Yast::NetworkService).to receive(:isNetworkRunning).and_return(network_running)
Expand Down Expand Up @@ -67,7 +68,54 @@ def import(_args); end
end
end

context "when update is enabled" do
it "intializes the package management" do
# override the global stub
expect(subject).to receive(:initialize_packager).and_call_original

url = "cd:///"
expect(Yast::Pkg).to receive(:SetTextLocale)
expect(Yast::Packages).to receive(:ImportGPGKeys)
expect(Yast::InstURL).to receive(:installInf2Url).and_return(url)
expect(Yast::Pkg).to receive(:SourceCreateBase).with(url, "").and_return(0)

# just a shortcut to avoid mocking the whole update
allow(subject).to receive(:self_update_enabled?).and_return(false)
subject.main
end

it "cleans up the package management at the end" do
# override the global stub
expect(subject).to receive(:finish_packager).and_call_original

expect(Yast::Pkg).to receive(:SourceGetCurrent).and_return([0])
expect(Yast::Pkg).to receive(:SourceDelete).with(0)
expect(Yast::Pkg).to receive(:SourceSaveAll)

# just a shortcut to avoid mocking the whole update
allow(subject).to receive(:self_update_enabled?).and_return(false)
subject.main
end

it "displays a progress" do
expect(Yast::Wizard).to receive(:CreateDialog)
expect(Yast::Progress).to receive(:New)
expect(Yast::Progress).to receive(:NextStage)

# just a shortcut to avoid mocking the whole update
allow(subject).to receive(:self_update_enabled?).and_return(false)
subject.main
end

it "finishes the progress at the end" do
expect(Yast::Progress).to receive(:Finish)
expect(Yast::Wizard).to receive(:CloseDialog)

# just a shortcut to avoid mocking the whole update
allow(subject).to receive(:self_update_enabled?).and_return(false)
subject.main
end

context "when update URL is configured in control.xml" do
before do
allow(Yast::ProductFeatures).to receive(:GetStringFeature).and_return(url)
end
Expand Down

0 comments on commit 81e57d7

Please sign in to comment.