Skip to content

Commit

Permalink
Initial unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Nov 21, 2017
1 parent bc9662f commit e642b33
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/lib/registration/addon.rb
Expand Up @@ -44,6 +44,8 @@ def find_all(registration)
def reset!
@cached_addons = nil
@registered = nil
@selected = nil
@auto_selected = nil
end

# list of registered add-ons
Expand Down
17 changes: 10 additions & 7 deletions src/lib/registration/autoyast_addons.rb
Expand Up @@ -11,9 +11,13 @@
# ------------------------------------------------------------------------------
#

require "yast"

module Registration
class AutoyastAddons
attr_accessor :requested_addons, :register_addons
include Yast::I18n

attr_accessor :requested_addons, :selected_addons

def initialize(requested_addons, registration)
self.requested_addons = requested_addons
Expand All @@ -27,21 +31,21 @@ def select
all_addons = registration_ui.get_available_addons

# remove the addons marked as not available
rejected = all_addons.reject!{|a| a.available == false}
rejected = all_addons.reject!{|a| a.available? == false}
log.info("Not available addons: #{rejected.map(&:label).inspect}") if rejected

# select the requested addons from the available addons
self.register_addons = select_addons(all_addons)
self.selected_addons = select_addons(all_addons)
end

def register
regcodes = collect_reg_codes
registration_ui.register_selected_addons(register_addons, regcodes)
registration_ui.register_addons(selected_addons, regcodes)
end

private

attr_writer :register_addons
attr_writer :selected_addons
attr_accessor :registration

# select the requested addons
Expand Down Expand Up @@ -77,8 +81,7 @@ def select_addons(all_addons)
# @return [Array<Registration::Addon>]
def ordered_addons
# include also the automatically selected dependent modules/extensions
ret = Registration::Addon.registration_order(
Registration::Addon.selected + Registration::Addon.auto_selected)
ret = Addon.registration_order(Addon.selected + Addon.auto_selected)

log.info("Addons to register: #{ret.map(&:label).inspect}")

Expand Down
63 changes: 63 additions & 0 deletions test/autoyast_addons_spec.rb
@@ -0,0 +1,63 @@
#! /usr/bin/env rspec

require_relative "spec_helper"
require "yaml"

describe Registration::AutoyastAddons do
let(:registration) { double("registration") }
let(:unsorted_addons) { [
# deliberately in a wrong registration order
{"name" => "sle-module-desktop-applications", "version" => "15", "arch" => "x86_64"},
{"name" => "sle-module-basesystem", "version" => "15", "arch" => "x86_64"}
] }

# depends on the "sle-module-basesystem" which is not listed here
let(:incomplete_addons) { ["name" => "sle-module-desktop-applications", "version" => "15", "arch" => "x86_64"] }

# the expected addons to register in the correct order
let(:expected_registration_order) { ["sle-module-basesystem", "sle-module-desktop-applications"] }

before do
addons = load_yaml_fixture("sle15_addons.yaml")
allow(Registration::Addon).to receive(:find_all).and_return(addons)
allow(registration).to receive(:get_addon_list).and_return(addons)
end

after do
Registration::Addon.reset!
end

describe "#select" do
it "sorts the addons according to their dependencies" do
ayaddons = Registration::AutoyastAddons.new(unsorted_addons, registration)
ayaddons.select

expect(ayaddons.selected_addons.map(&:identifier)).to eq(expected_registration_order)
end

it "automatically selects the dependent addons" do
ayaddons = Registration::AutoyastAddons.new(incomplete_addons, registration)
ayaddons.select

expect(ayaddons.selected_addons.map(&:identifier)).to eq(expected_registration_order)
end
end

describe "#register" do
it "registers the selected addons" do
expect(registration).to receive(:register_product).with({"name"=>"sle-module-basesystem", "reg_code"=>nil, "arch"=>"x86_64", "version"=>"15"}).ordered
expect(registration).to receive(:register_product).with({"name"=>"sle-module-desktop-applications", "reg_code"=>nil, "arch"=>"x86_64", "version"=>"15"}).ordered

ayaddons = Registration::AutoyastAddons.new(unsorted_addons, registration)
ayaddons.select
ayaddons.register

# expect(ayaddons.selected_addons.map(&:identifier)).to eq(expected_registration_order)
end

xit "registers the selected addon using the provided reg. key" do

end
end

end

0 comments on commit e642b33

Please sign in to comment.