From c36c3a7080c4aacac7d8f374f2f63fbcec762a9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ladislav=20Slez=C3=A1k?= Date: Wed, 19 Jan 2022 15:14:17 +0100 Subject: [PATCH 1/3] Fixed unit tests, verifying doubles, fixed handling of invalid XML --- .rspec | 1 + package/sap-installation-wizard.changes | 11 +++++++++++ package/sap-installation-wizard.spec | 4 ++-- src/lib/y2sap/clients/create_storage.rb | 2 ++ test/spec_helper.rb | 16 ++++++++++++---- test/y2sap/clients/create_storage_test.rb | 5 +++-- test/y2sap/media_test.rb | 19 +++++++++++++------ test/y2sap/products_test.rb | 7 +++++-- 8 files changed, 49 insertions(+), 16 deletions(-) create mode 100644 .rspec diff --git a/.rspec b/.rspec new file mode 100644 index 00000000..cc212b25 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--color --format doc diff --git a/package/sap-installation-wizard.changes b/package/sap-installation-wizard.changes index 0054ad37..075f4c67 100644 --- a/package/sap-installation-wizard.changes +++ b/package/sap-installation-wizard.changes @@ -1,3 +1,14 @@ +------------------------------------------------------------------- +Wed Jan 19 13:50:46 UTC 2022 - Ladislav Slezák + +- 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 diff --git a/package/sap-installation-wizard.spec b/package/sap-installation-wizard.spec index 7cd0eb5a..f90880fb 100644 --- a/package/sap-installation-wizard.spec +++ b/package/sap-installation-wizard.spec @@ -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 @@ -67,7 +67,7 @@ Authors: %setup -q %check -#rake test:unit +rake test:unit %build diff --git a/src/lib/y2sap/clients/create_storage.rb b/src/lib/y2sap/clients/create_storage.rb index 4d215713..4c85eb27 100644 --- a/src/lib/y2sap/clients/create_storage.rb +++ b/src/lib/y2sap/clients/create_storage.rb @@ -103,6 +103,8 @@ def read_partitioning profile = Yast::XML.XMLToYCPFile(filename) profile && profile["partitioning"] + rescue Yast::XMLDeserializationError + nil end # Select a disk with to use diff --git a/test/spec_helper.rb b/test/spec_helper.rb index df38a2c7..f148ef6a 100644 --- a/test/spec_helper.rb +++ b/test/spec_helper.rb @@ -38,12 +38,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 diff --git a/test/y2sap/clients/create_storage_test.rb b/test/y2sap/clients/create_storage_test.rb index 917439d8..dd773392 100644 --- a/test/y2sap/clients/create_storage_test.rb +++ b/test/y2sap/clients/create_storage_test.rb @@ -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 @@ -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] } @@ -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 diff --git a/test/y2sap/media_test.rb b/test/y2sap/media_test.rb index 436cac9a..1f5de803 100644 --- a/test/y2sap/media_test.rb +++ b/test/y2sap/media_test.rb @@ -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" @@ -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" @@ -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 diff --git a/test/y2sap/products_test.rb b/test/y2sap/products_test.rb index 22726765..d260449a 100644 --- a/test/y2sap/products_test.rb +++ b/test/y2sap/products_test.rb @@ -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 @@ -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" From 277593b8d530629e63265364a530425b70db146a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ladislav=20Slez=C3=A1k?= Date: Wed, 19 Jan 2022 15:56:13 +0100 Subject: [PATCH 2/3] Enable RSpec verifying doubles --- test/spec_helper.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/spec_helper.rb b/test/spec_helper.rb index f148ef6a..e3b8160d 100644 --- a/test/spec_helper.rb +++ b/test/spec_helper.rb @@ -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 From d7ffb0da59e701a5f80c210d99ba11ca473d80f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ladislav=20Slez=C3=A1k?= Date: Wed, 19 Jan 2022 16:18:23 +0100 Subject: [PATCH 3/3] Error logging --- src/lib/y2sap/clients/create_storage.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/y2sap/clients/create_storage.rb b/src/lib/y2sap/clients/create_storage.rb index 4c85eb27..8ce6119e 100644 --- a/src/lib/y2sap/clients/create_storage.rb +++ b/src/lib/y2sap/clients/create_storage.rb @@ -104,6 +104,7 @@ def read_partitioning profile = Yast::XML.XMLToYCPFile(filename) profile && profile["partitioning"] rescue Yast::XMLDeserializationError + log.error("Cannot parse XML file #{filename}") nil end