Skip to content

Commit

Permalink
SystemdService.find_many_at_once does not return nil values
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Aug 9, 2018
1 parent 75b27db commit fbf0b2f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 29 deletions.
6 changes: 1 addition & 5 deletions library/systemd/src/lib/yast2/system_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,9 @@ def build(name)
#
# @param names [Array<String>] service names to find
#
# @raise [NotFoundError] if any service is not found
# @return [Array<SystemService>]
def find_many(names)
systemd_services = Yast::SystemdService.find_many(names)
raise NotFoundError if systemd_services.any?(&:nil?)

systemd_services.map { |s| new(s) }
Yast::SystemdService.find_many(names).map { |s| new(s) }
end
end

Expand Down
7 changes: 3 additions & 4 deletions library/systemd/src/modules/systemd_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,9 @@ def find!(service_name, propmap = {})
property_texts = out.stdout.split("\n\n")
return [] unless snames.size == property_texts.size

snames.zip(property_texts).map do |service_name, property_text|
service = Service.new(service_name, service_propmap, property_text)
next nil if service.properties.not_found?
service
snames.zip(property_texts).each_with_object([]) do |(name, property_text), memo|
service = Service.new(name, service_propmap, property_text)
memo << service unless service.not_found?
end
end

Expand Down
20 changes: 0 additions & 20 deletions library/systemd/test/yast2/system_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,6 @@
expect(system_service.service).to eq(systemd_service)
end
end

context "when the service is not found" do
let(:systemd_service) { nil }

it "raises an exception" do
expect { described_class.find!("cups") }.to raise_error(Yast2::SystemService::NotFoundError)
end
end
end

describe ".build" do
Expand Down Expand Up @@ -129,18 +121,6 @@
expect(system_services).to be_all(Yast2::SystemService)
expect(system_services.map(&:service)).to eq([apparmor, cups])
end

context "when some service is not found" do
before do
allow(Yast::SystemdService).to receive(:find_many).with(["apparmor", "cups"])
.and_return([nil, cups])
end

it "raises an exception" do
expect { described_class.find_many(["apparmor", "cups"]) }
.to raise_error(Yast2::SystemService::NotFoundError)
end
end
end

describe "#state" do
Expand Down

0 comments on commit fbf0b2f

Please sign in to comment.