Skip to content

Commit

Permalink
Take into account socket for state and substate
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Jul 24, 2018
1 parent 1658def commit f90d97f
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 10 deletions.
32 changes: 22 additions & 10 deletions library/systemd/src/lib/yast2/system_service.rb
Expand Up @@ -60,16 +60,6 @@ class SystemService
# if no action has been requested yet.
attr_reader :action

# @!method state
#
# @return [String]
def_delegator :@service, :active_state, :state

# @!method substate
#
# @return [String]
def_delegator :@service, :sub_state, :substate

# @!method support_reload?
#
# @return [Boolean]
Expand Down Expand Up @@ -107,6 +97,28 @@ def initialize(service)
@errors = {}
end

# State of the service
#
# In case the service is not active but socket, the socket state is considered
#
# @return [String]
def state
return socket.active_state if socket_active? && !service.active?

service.active_state
end

# Substate of the service
#
# In case the service is not active but socket, the socket substate is considered
#
# @return [String]
def substate
return socket.sub_state if socket_active? && !service.active?

service.sub_state
end

# Gets the current start_mode (as read from the system)
#
# @return [Symbol] :on_boot, :on_demand, :manual
Expand Down
70 changes: 70 additions & 0 deletions library/systemd/test/yast2/system_service_test.rb
Expand Up @@ -94,6 +94,76 @@
end
end

describe "#state" do
before do
allow(service).to receive(:active_state).and_return("service state")
allow(socket).to receive(:active_state).and_return("socket state")
end

context "when the service is not active" do
let(:service_active) { false }

context "and the socket is active" do
let(:socket_active) { true }

it "returns the socket state" do
expect(system_service.state).to eq("socket state")
end
end

context "and the socket is not active" do
let(:socket_active) { false }

it "returns the service state" do
expect(system_service.state).to eq("service state")
end
end
end

context "when the service is active" do
let(:service_active) { true }

it "returns the service state" do
expect(system_service.state).to eq("service state")
end
end
end

describe "#substate" do
before do
allow(service).to receive(:sub_state).and_return("service substate")
allow(socket).to receive(:sub_state).and_return("socket substate")
end

context "when the service is not active" do
let(:service_active) { false }

context "and the socket is active" do
let(:socket_active) { true }

it "returns the socket substate" do
expect(system_service.substate).to eq("socket substate")
end
end

context "and the socket is not active" do
let(:socket_active) { false }

it "returns the service substate" do
expect(system_service.substate).to eq("service substate")
end
end
end

context "when the service is active" do
let(:service_active) { true }

it "returns the service substate" do
expect(system_service.substate).to eq("service substate")
end
end
end

describe "#current_start_mode" do
context "when the service is enabled" do
let(:service_enabled) { true }
Expand Down

0 comments on commit f90d97f

Please sign in to comment.