From 9376a7247a53ffd2f72e8a9e3ea8827b09eb882c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ladislav=20Slez=C3=A1k?= Date: Tue, 5 Dec 2023 13:50:37 +0100 Subject: [PATCH] Added unit test --- service/.rubocop.yml | 4 ++ service/lib/agama/software/manager.rb | 4 +- service/lib/agama/software/product_builder.rb | 2 +- service/test/agama/software/manager_test.rb | 62 ++++++++++++++++++- 4 files changed, 67 insertions(+), 5 deletions(-) diff --git a/service/.rubocop.yml b/service/.rubocop.yml index ed2faf80db..137ea30537 100644 --- a/service/.rubocop.yml +++ b/service/.rubocop.yml @@ -24,3 +24,7 @@ Metrics/BlockLength: # assignment in method calls is used to document some params Lint/UselessAssignment: Enabled: false + +# be less strict +Metrics/AbcSize: + Max: 32 diff --git a/service/lib/agama/software/manager.rb b/service/lib/agama/software/manager.rb index 68296ab1ef..9c2aeb8cf9 100644 --- a/service/lib/agama/software/manager.rb +++ b/service/lib/agama/software/manager.rb @@ -215,8 +215,8 @@ def patterns(filtered) patterns = patterns.select(&:user_visible) if filtered # only display the configured patterns - if product.user_patterns - patterns.select! {|p| product.user_patterns.include?(p.name)} + if product.user_patterns && filtered + patterns.select! { |p| product.user_patterns.include?(p.name) } end patterns diff --git a/service/lib/agama/software/product_builder.rb b/service/lib/agama/software/product_builder.rb index 7ee3d270ca..c048be304e 100644 --- a/service/lib/agama/software/product_builder.rb +++ b/service/lib/agama/software/product_builder.rb @@ -81,7 +81,7 @@ def product_data_from_config(id) optional_patterns: config.arch_elements_from( id, "software", "optional_patterns", property: :pattern ), - user_patterns: config.arch_elements_from( + user_patterns: config.arch_elements_from( id, "software", "user_patterns", property: :pattern, default: nil ) } diff --git a/service/test/agama/software/manager_test.rb b/service/test/agama/software/manager_test.rb index f899ab64b3..1603656c4f 100644 --- a/service/test/agama/software/manager_test.rb +++ b/service/test/agama/software/manager_test.rb @@ -229,12 +229,70 @@ describe "#products" do it "returns the list of known products" do products = subject.products - expect(products.size).to eq(3) + expect(products.size).to eq(4) expect(products).to all(be_a(Agama::Software::Product)) expect(products).to contain_exactly( an_object_having_attributes(id: "ALP-Dolomite"), an_object_having_attributes(id: "Tumbleweed"), - an_object_having_attributes(id: "Leap16") + an_object_having_attributes(id: "MicroOS"), + an_object_having_attributes(id: "MicroOS-Desktop") + ) + end + end + + describe "#patterns" do + it "returns only the specified patterns" do + expect(Y2Packager::Resolvable).to receive(:find).and_return( + [ + double( + arch: "x86_64", + category: "Base Technologies", + description: "YaST tools for installing your system.", + icon: "./yast", + kind: :pattern, + name: "yast2_install_wf", + order: "1240", + source: 0, + summary: "YaST Installation Packages", + user_visible: false, + version: "20220411-1.4" + ), + double( + arch: "x86_64", + category: "Base Technologies", + description: "YaST tools for basic system administration.", + icon: "./yast", + kind: :pattern, + name: "yast2_basis", + order: "1220", + source: 0, + summary: "YaST Base Utilities", + user_visible: true, + version: "20220411-1.4" + ), + double( + arch: "noarch", + category: "Graphical Environments", + description: + "Packages providing the Plasma desktop environment and " \ + "applications from KDE.", + icon: "./pattern-kde", + kind: :pattern, + name: "kde", + order: "1110", + source: 0, + summary: "KDE Applications and Plasma 5 Desktop", + user_visible: true, + version: "20230801-1.1" + ) + ] + ) + + allow(subject.product).to receive(:user_patterns).and_return(["kde"]) + patterns = subject.patterns(true) + + expect(patterns).to contain_exactly( + an_object_having_attributes(name: "kde") ) end end