Skip to content

Commit

Permalink
Fixed unit tests, verifying doubles, fixed handling of invalid XML (#2)
Browse files Browse the repository at this point in the history
* Fixed unit tests, verifying doubles, fixed handling of invalid XML

* Enable RSpec verifying doubles

* Error logging
  • Loading branch information
lslezak committed Jan 19, 2022
1 parent 999e5c6 commit 4295da6
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 16 deletions.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--color --format doc
11 changes: 11 additions & 0 deletions package/sap-installation-wizard.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
-------------------------------------------------------------------
Wed Jan 19 13:50:46 UTC 2022 - Ladislav Slezák <lslezak@suse.cz>

- Unit tests:
- Enable RSpec verifying doubles to ensue that the mocked
methods really exist (bsc#1194784)
- Fixed to actually pass
- Run them during RPM build
- Do not crash if the partitioning XML is not valid
- 4.4.1

-------------------------------------------------------------------
Tue Jan 18 14:42:07 UTC 2022 - Ladislav Slezák <lslezak@suse.cz>

Expand Down
4 changes: 2 additions & 2 deletions package/sap-installation-wizard.spec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Name: sap-installation-wizard
Summary: Installation wizard for SAP applications
License: GPL-2.0+
Group: System/YaST
Version: 4.4.0
Version: 4.4.1
Release: 0
PreReq: /bin/mkdir %insserv_prereq %fillup_prereq yast2
BuildRequires: yast2
Expand Down Expand Up @@ -67,7 +67,7 @@ Authors:
%setup -q

%check
#rake test:unit
rake test:unit

%build

Expand Down
3 changes: 3 additions & 0 deletions src/lib/y2sap/clients/create_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ def read_partitioning

profile = Yast::XML.XMLToYCPFile(filename)
profile && profile["partitioning"]
rescue Yast::XMLDeserializationError
log.error("Cannot parse XML file #{filename}")
nil
end

# Select a disk with to use
Expand Down
24 changes: 20 additions & 4 deletions test/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
require "yast"
require "yast/rspec"

# configure RSpec
RSpec.configure do |config|
config.mock_with :rspec do |c|
# https://relishapp.com/rspec/rspec-mocks/v/3-0/docs/verifying-doubles/partial-doubles
c.verify_partial_doubles = true
end
end

if ENV["COVERAGE"]
require "simplecov"
SimpleCov.start do
Expand All @@ -38,12 +46,20 @@
# track all ruby files under src
SimpleCov.track_files("#{SRC_PATH}/lib/**/*.rb")

# use coveralls for on-line code coverage reporting at Travis CI
if ENV["TRAVIS"]
require "coveralls"
# additionally use the LCOV format for on-line code coverage reporting at CI
if ENV["CI"] || ENV["COVERAGE_LCOV"]
require "simplecov-lcov"

SimpleCov::Formatter::LcovFormatter.config do |c|
c.report_with_single_file = true
# this is the default Coveralls GitHub Action location
# https://github.com/marketplace/actions/coveralls-github-action
c.single_report_path = "coverage/lcov.info"
end

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
SimpleCov::Formatter::LcovFormatter
]
end
end
5 changes: 3 additions & 2 deletions test/y2sap/clients/create_storage_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
end
let(:issues_list) { [] }

let(:usr) { instance_double(Y2Storage::Filesystems::BlkFilesystem, mount_point: "/usr") }
let(:usr) { instance_double(Y2Storage::Filesystems::BlkFilesystem, mount_path: "/usr") }
let(:filesystems) { [usr] }

describe "#main" do
Expand Down Expand Up @@ -191,7 +191,7 @@

context "when any wanted mount point already exist" do
let(:hana_data) do
instance_double(Y2Storage::Filesystems::BlkFilesystem, mount_point: "/hana/data")
instance_double(Y2Storage::Filesystems::BlkFilesystem, mount_path: "/hana/data")
end
let(:filesystems) { [usr, hana_data] }

Expand All @@ -205,6 +205,7 @@
end

it "logs existing mount points" do
allow(client.log).to receive(:info).and_call_original
expect(client.log).to receive(:info).with(/\/hana\/data/).and_call_original
client.main
end
Expand Down
19 changes: 13 additions & 6 deletions test/y2sap/media_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@

describe Y2Sap::Media do
context "no sysconfig file exist" do
subject { described_class.new }
before do
change_scr_root("/")
end
it "reads the default base configuration" do
expect(subject.mount_point).to eq "/mnt"
expect(subject.inst_mode).to eq "manual"
Expand All @@ -47,8 +43,12 @@
end
context "sysconfig file does exist" do
subject { described_class.new }
before do
around do |example|
# change the SCR root to a testing directory
change_scr_root(File.join(DATA_PATH, "system"))
example.run
# restore it back
reset_scr_root
end
it "reads the base configuration from sysconfig file" do
expect(subject.mount_point).to eq "/tmp/mnt"
Expand All @@ -62,9 +62,16 @@
before do
allow(Yast::SCR).to receive(:Execute).with(Yast::Path.new(".target.bash_output"), /du/)
.and_return(out)
end

around do |example|
# change the SCR root to a testing directory
change_scr_root(File.join(DATA_PATH, "system"))
subject { described_class.new }
example.run
# restore it back
reset_scr_root
end

it "reads the tech size of /etc" do
expect(subject.tech_size("/etc")).to eq(200)
end
Expand Down
7 changes: 5 additions & 2 deletions test/y2sap/products_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
context "no sysconfig file exist" do
let(:media) { Y2Sap::Media.new }
before do
change_scr_root("/")
subject.media.product_definitions = DATA_PATH + "/system/etc/sap-installation-wizard.xml"
end
it "check the initalization of global variables" do
Expand Down Expand Up @@ -61,9 +60,13 @@
end
context "sysconfig file does exist" do
let(:media) { Y2Sap::Media.new }
before do
around do |example|
# change the SCR root to a testing directory
change_scr_root(File.join(DATA_PATH, "system"))
subject.media.product_definitions = DATA_PATH + "/system/etc/sap-installation-wizard.xml"
example.run
# restore it back
reset_scr_root
end
it "reads the base configuration from sysconfig file" do
expect(subject.media.mount_point).to eq "/tmp/mnt"
Expand Down

0 comments on commit 4295da6

Please sign in to comment.