Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Apr 3, 2015
1 parent d1aa523 commit d55305b
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/lib/registration/ui/media_addon_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ def register_base
:next
end

def register_addons
known_reg_codes = Storage::RegCodes.instance.reg_codes
registration_ui.register_addons(Addon.selected, known_reg_codes)
end

def load_remote_addons
registration_ui.get_available_addons == :cancel ? :cancel : :next
end
Expand All @@ -132,6 +127,11 @@ def select_media_addons
# no SCC add-on selected => no registration
Addon.selected.empty? ? :finish : :next
end

def register_addons
known_reg_codes = Storage::RegCodes.instance.reg_codes
registration_ui.register_addons(Addon.selected, known_reg_codes)
end
end
end
end
49 changes: 49 additions & 0 deletions test/media_addon_workflow_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#! /usr/bin/env rspec

require_relative "spec_helper"
require "yaml"

describe "Registration::UI::MediaAddonWorkflow" do
describe ".run" do
let(:repo) { 42 }
# sle-module-legacy product
let(:products) { [YAML.load_file(fixtures_file("products_legacy_installation.yml")).first] }
let(:remote_addons) { YAML.load_file(fixtures_file("available_addons.yml")) }

before do
expect(Registration::UrlHelpers).to receive(:registration_url)
end

it "registeres the addon from media" do
expect(Registration::SwMgmt).to receive(:init).and_return(true)
expect(Yast::Pkg).to receive(:SourceLoad)
expect(Registration::SwMgmt).to receive(:products_from_repo).with(repo).and_return(products)
expect(Registration::Registration).to receive(:is_registered?).and_return(true)
expect_any_instance_of(Registration::RegistrationUI).to receive(:get_available_addons)
.and_return(remote_addons)
expect(Registration::SwMgmt).to receive(:select_product_addons).with(products, remote_addons)
expect(Registration::Addon).to receive(:selected).twice.and_return([remote_addons.first])
expect(Registration::Addon).to receive(:find_all).and_return(remote_addons)
expect_any_instance_of(Registration::RegistrationUI).to receive(:register_addons)
.and_return(:next)

expect(Registration::UI::MediaAddonWorkflow.run(repo)).to eq(:next)
end

it "aborts when package management initialization fails" do
expect(Registration::SwMgmt).to receive(:init).and_return(false)
expect(Yast::Report).to receive(:Error)

expect(Registration::UI::MediaAddonWorkflow.run(repo)).to eq(:abort)
end

it "skips registation when the media addon does not provide any product" do
expect(Registration::SwMgmt).to receive(:init).and_return(true)
expect(Yast::Pkg).to receive(:SourceLoad)
expect(Registration::SwMgmt).to receive(:products_from_repo).with(repo).and_return([])
expect(Yast::Pkg).to receive(:SourceGeneralData).with(repo).and_return({})

expect(Registration::UI::MediaAddonWorkflow.run(repo)).to eq(:finish)
end
end
end
4 changes: 0 additions & 4 deletions test/ssl_certificate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
# "sha224sum test.der" and "sha256sum test.der" to get SHA224 and SHA256
let(:serial) { "B8:AB:F1:73:E4:1F:10:4D" }
let(:sha1) { "A8:DE:08:B1:57:52:FE:70:DF:D5:31:EA:E3:53:BB:39:EE:01:FF:B9" }
let(:sha224) do
"CA:F3:9F:48:18:93:52:19:78:5B:08:C7:36:CE:8A:7C:18:5D:33:0E:E3:9A:" \
"E9:44:51:EB:F8:5A"
end
let(:sha256) do
"2A:02:DA:EC:A9:FF:4C:B4:A6:C0:57:08:F6:1C:8B:B0:94:FA:F4:60:96:5E:" \
"18:48:CA:84:81:48:60:F3:CB:BF"
Expand Down
18 changes: 18 additions & 0 deletions test/sw_mgmt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@
}
end

describe ".init" do
it "initializes package management and returns true" do
expect(Yast::PackageLock).to receive(:Connect).with(false).and_return("connected" => true)

expect(Yast::PackageCallbacks).to receive(:InitPackageCallbacks)
expect(Yast::Pkg).to receive(:TargetInitialize)
expect(Yast::Pkg).to receive(:TargetLoad)
expect(Yast::Pkg).to receive(:SourceRestore).and_return(true)

expect(Registration::SwMgmt.init).to eq(true)
end

it "returns false when cannot obtain libzypp lock" do
expect(Yast::PackageLock).to receive(:Connect).with(false).and_return("connected" => false)
expect(Registration::SwMgmt.init).to eq(false)
end
end

describe ".service_repos" do
let(:service) { double }

Expand Down

0 comments on commit d55305b

Please sign in to comment.