Skip to content

Commit

Permalink
Added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Dec 5, 2023
1 parent 7a19b73 commit 9376a72
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 5 deletions.
4 changes: 4 additions & 0 deletions service/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions service/lib/agama/software/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion service/lib/agama/software/product_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand Down
62 changes: 60 additions & 2 deletions service/test/agama/software/manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9376a72

Please sign in to comment.