Skip to content

Commit

Permalink
Ensure Service#call returns the original command result
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Moravec committed May 30, 2014
1 parent 3d8adcf commit 956ce59
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
6 changes: 3 additions & 3 deletions library/runlevel/src/modules/Service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ def call command_name, service_name
else
raise "Command '#{command_name}' not supported"
end
success = service.send(systemd_command)
return failure(command_name, service_name, service.error) unless success
true
result = service.send(systemd_command)
failure(command_name, service_name, service.error) unless result
result
end

# Check if service is active/running
Expand Down
6 changes: 2 additions & 4 deletions library/runlevel/test/service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ def stub_service_with method, result
expect(Service.call('reload', 'sshd')).to be_true
end

it "raises error if command name or service name parameter is missing" do
expect{ Service.call('start') }.to raise_error
end

it "raises error if the command is not recognized" do
expect { Service.call('make-coffee', 'sshd') }.to raise_error
end

it "returns the result of the original result of the command call" do
expect(Service.call('status', 'sshd')).to be_kind_of(String)

stub_service_with(:"try_restart", false)
expect(Service.call('try-restart', "sshd")).to be_false
end
Expand Down

0 comments on commit 956ce59

Please sign in to comment.