Skip to content

Commit

Permalink
Add method SystemService#search_terms
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Jul 6, 2018
1 parent bda20d6 commit af969bb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
16 changes: 14 additions & 2 deletions library/system/src/lib/yast2/system_service.rb
Expand Up @@ -73,7 +73,7 @@ def find(name)
new(Yast::SystemdService.find(name))
end

# Find service names
# Finds service names
#
# This method finds a set of system services. Currently it is just a wrapper around
# SystemdService.find_many.
Expand Down Expand Up @@ -163,7 +163,7 @@ def changed?
!changes.empty?
end

# Return the list of supported start modes
# Returns the list of supported start modes
#
# * :on_boot: The service will be started when the system boots.
# * :manual: The service is disabled and it will be started manually.
Expand All @@ -177,6 +177,18 @@ def start_modes
@start_modes
end

# Terms to search for this service
#
# In case the service has an associated socket, the socket name
# is included as search term.
#
# @return [Array<String>] e.g., #=> ["tftp.service", "tftp.socket"]
def search_terms
terms = [service.id]
terms << socket.id if socket
terms
end

private

# @return [Hash<String,Object>]
Expand Down
22 changes: 22 additions & 0 deletions library/system/test/yast2/system_service_test.rb
Expand Up @@ -336,4 +336,26 @@
end
end
end

describe "#search_terms" do
before do
allow(service).to receive(:id).and_return("cups.service")
end

context "when the service has not associated socket" do
let(:socket) { nil }

it "returns only the service full name" do
expect(system_service.search_terms).to contain_exactly("cups.service")
end
end

context "when the service has an associated socket" do
let(:socket) { instance_double(Yast::SystemdSocketClass::Socket, id: "cups.socket") }

it "returns the service and socket full names" do
expect(system_service.search_terms).to contain_exactly("cups.service", "cups.socket")
end
end
end
end

0 comments on commit af969bb

Please sign in to comment.