Skip to content

Commit

Permalink
adapted suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed May 3, 2018
1 parent 277a4f0 commit f4a26ac
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 43 deletions.
2 changes: 1 addition & 1 deletion package/autoyast2.changes
Expand Up @@ -2,7 +2,7 @@
Fri Apr 27 16:24:37 CEST 2018 - schubi@suse.de

- Added general API for reporting errors while parsing the AutoYaST
configuration file (part ob bnc#1089855).
configuration file (part of bnc#1089855).
- 4.0.50

-------------------------------------------------------------------
Expand Down
7 changes: 0 additions & 7 deletions src/lib/autoinstall/autoinst_issues/invalid_value.rb
Expand Up @@ -42,13 +42,6 @@ def initialize(section, attribute, value, description, severity = :warn)
@severity = severity
end

# Return problem severity
#
# @return [Symbol] :warn, :fatal
def severity
@severity
end

# Return the error message to be displayed
#
# @return [String] Error message
Expand Down
7 changes: 5 additions & 2 deletions src/lib/autoinstall/autoinst_issues/issue.rb
Expand Up @@ -8,9 +8,12 @@ module AutoinstIssues
class Issue
include Yast::I18n

# @return [#parent,#section_name] Section where it was detected
# @return [String] Section where it was detected
attr_reader :section

# @return [Symbol] :warn, :fatal problem severity
attr_reader :severity

# Return problem severity
#
# * :fatal: abort the installation.
Expand All @@ -19,7 +22,7 @@ class Issue
# @return [Symbol] Issue severity (:warn, :fatal)
# @raise NotImplementedError
def severity
raise NotImplementedError
@severity || :warn
end

# Return the error message to be displayed
Expand Down
2 changes: 1 addition & 1 deletion src/lib/autoinstall/autoinst_issues/list.rb
Expand Up @@ -57,7 +57,7 @@ def initialize
# @example Adding a problem with additional arguments
# list = List.new
# list.add(:invalid_value, "firewall", "FW_DEV_INT", "1",
# _("Is not supported anymore.")
# _("Is not supported anymore."))
# list.empty? #=> false
#
# @param type [Symbol] Issue type
Expand Down
11 changes: 2 additions & 9 deletions src/lib/autoinstall/autoinst_issues/missing_value.rb
Expand Up @@ -31,6 +31,7 @@ module AutoinstIssues
class MissingValue < Issue
# @return [String] Name of the missing attribute
attr_reader :attr
attr_reader :description

# @param section [String] Section where it was detected
# @param attr [String] Name of the missing attribute
Expand All @@ -45,14 +46,6 @@ def initialize(section, attr, description = "", severity = :warn)
@severity = severity
end

# Fatal problem
#
# @return [Symbol] :fatal, :warn
# @see Issue#severity
def severity
@severity
end

# Return the error message to be displayed
#
# @return [String] Error message
Expand All @@ -62,7 +55,7 @@ def message
# 'attr' is an AutoYaST element
# 'description' has already been translated in other modules.
_("Missing element '%{attr}'. %{description}") %
{ attr: @attr, description: @description }
{ attr: attr, description: description }
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions src/lib/autoinstall/autoinst_issues_presenter.rb
Expand Up @@ -23,6 +23,9 @@
Yast.import "RichText"

module Y2Autoinstallation

# FIXME merge this class with StorageProposalIssuesPresenter class.

# This class converts a list of issues into a message to be shown to users
#
# The message will summarize the list of issues, separating them into non-fatal
Expand Down
44 changes: 22 additions & 22 deletions test/AutoInstall_test.rb
@@ -1,59 +1,59 @@
#!/usr/bin/env rspec

require_relative 'test_helper'
require 'autoinstall/autoinst_issues'
require 'autoinstall/autoinst_issues_presenter'
require 'autoinstall/dialogs/question'
require_relative "test_helper"
require "autoinstall/autoinst_issues"
require "autoinstall/autoinst_issues_presenter"
require "autoinstall/dialogs/question"

Yast.import 'AutoInstall'
Yast.import 'UI'
Yast.import "AutoInstall"
Yast.import "UI"

describe 'Yast::AutoInstall' do
describe "Yast::AutoInstall" do
subject { Yast::AutoInstall }

describe '#pkg_gpg_check' do
let(:data) { { 'CheckPackageResult' => Yast::PkgGpgCheckHandler::CHK_OK } }
describe "#pkg_gpg_check" do
let(:data) { { "CheckPackageResult" => Yast::PkgGpgCheckHandler::CHK_OK } }
let(:profile) { {} }
let(:checker) { double('checker') }
let(:checker) { double("checker") }

before do
allow(Yast::Profile).to receive(:current).and_return(profile)
allow(Yast::PkgGpgCheckHandler).to receive(:new).with(data, profile).and_return(checker)
allow(checker).to receive(:accept?).and_return(accept?)
end

context 'when PkgGpgCheckHandler#accept? returns true' do
context "when PkgGpgCheckHandler#accept? returns true" do
let(:accept?) { true }

it "returns 'I' (ignore)" do
expect(subject.pkg_gpg_check(data)).to eq('I')
expect(subject.pkg_gpg_check(data)).to eq("I")
end
end

context 'when PkgGpgCheckHandler#accept? returns false' do
context "when PkgGpgCheckHandler#accept? returns false" do
let(:accept?) { false }

it 'returns a blank string' do
expect(subject.pkg_gpg_check(data)).to eq('')
it "returns a blank string" do
expect(subject.pkg_gpg_check(data)).to eq("")
end
end
end

describe '#valid_imported_values' do
describe "#valid_imported_values" do
before(:each) do
subject.issues_list = Y2Autoinstallation::AutoinstIssues::List.new
end

context 'when no issue has been found' do
it 'returns true' do
context "when no issue has been found" do
it "returns true" do
expect(subject.valid_imported_values).to eq(true)
end
end

context 'when an issue has been found' do
it 'shows a popup' do
subject.issues_list.add(:invalid_value, 'firewall', 'FW_DEV_INT', '1',
_('Is not supported anymore.'))
context "when an issue has been found" do
it "shows a popup" do
subject.issues_list.add(:invalid_value, "firewall", "FW_DEV_INT", "1",
_("Is not supported anymore."))
expect_any_instance_of(Y2Autoinstallation::Dialogs::Question).to receive(:run).and_return(:ok)
expect(subject.valid_imported_values).to eq(true)
end
Expand Down
2 changes: 1 addition & 1 deletion test/lib/autoinst_issues/invalid_value_test.rb
Expand Up @@ -37,7 +37,7 @@
end
end

describe '#severity' do
describe '#severity which has been set to :fatal while initialisation' do
it 'returns :fatal' do
expect(issue.severity).to eq(:fatal)
end
Expand Down

0 comments on commit f4a26ac

Please sign in to comment.