summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavide Cavalca <dcavalca@fb.com>2016-03-04 15:24:20 -0800
committerDavide Cavalca <dcavalca@fb.com>2016-03-04 15:24:20 -0800
commit656386a80ceaa0f39302761764892d11cb804587 (patch)
treec19cb963a8c729e6f6a1e331c7412414053c191e
parent0174356f01fa20d643042004b20e4d76e0fe0735 (diff)
downloadchef-656386a80ceaa0f39302761764892d11cb804587.tar.gz
add a test for user services
-rw-r--r--spec/unit/provider/service/systemd_service_spec.rb42
1 files changed, 34 insertions, 8 deletions
diff --git a/spec/unit/provider/service/systemd_service_spec.rb b/spec/unit/provider/service/systemd_service_spec.rb
index b4a5015f58..06614442fe 100644
--- a/spec/unit/provider/service/systemd_service_spec.rb
+++ b/spec/unit/provider/service/systemd_service_spec.rb
@@ -21,7 +21,16 @@ require "spec_helper"
describe Chef::Provider::Service::Systemd do
- let(:node) { Chef::Node.new }
+ let(:node) {
+ node = Chef::Node.new
+ node.default["etc"] = Hash.new
+ node.default["etc"]["passwd"] = {
+ "joe" => {
+ "uid" => 10000
+ }
+ }
+ node
+ }
let(:events) { Chef::EventDispatch::Dispatcher.new }
@@ -171,15 +180,32 @@ describe Chef::Provider::Service::Systemd do
provider.start_service
end
- it "should call '#{systemctl_path} --system start service_name' if no start command is specified" do
- expect(provider).to receive(:shell_out_with_systems_locale!).with("#{systemctl_path} --system start #{service_name}", {}).and_return(shell_out_success)
- provider.start_service
+ context "when a user is not specified" do
+ it "should call '#{systemctl_path} --system start service_name' if no start command is specified" do
+ expect(provider).to receive(:shell_out_with_systems_locale!).with("#{systemctl_path} --system start #{service_name}", {}).and_return(shell_out_success)
+ provider.start_service
+ end
+
+ it "should not call '#{systemctl_path} --system start service_name' if it is already running" do
+ current_resource.running(true)
+ expect(provider).not_to receive(:shell_out_with_systems_locale!).with("#{systemctl_path} --system start #{service_name}", {})
+ provider.start_service
+ end
end
- it "should not call '#{systemctl_path} --system start service_name' if it is already running" do
- current_resource.running(true)
- expect(provider).not_to receive(:shell_out_with_systems_locale!).with("#{systemctl_path} --system start #{service_name}", {})
- provider.start_service
+ context "when a user is specified" do
+ it "should call '#{systemctl_path} --user start service_name' if no start command is specified" do
+ current_resource.user("joe")
+ expect(provider).to receive(:shell_out_with_systems_locale!).with("#{systemctl_path} --user start #{service_name}", {"environment"=>{"DBUS_SESSION_BUS_ADDRESS"=>"unix:path=/run/user/10000/bus"}, "user" => "joe"}).and_return(shell_out_success)
+ provider.start_service
+ end
+
+ it "should not call '#{systemctl_path} --user start service_name' if it is already running" do
+ current_resource.running(true)
+ current_resource.user("joe")
+ expect(provider).not_to receive(:shell_out_with_systems_locale!).with("#{systemctl_path} --user start #{service_name}", {"environment"=>{"DBUS_SESSION_BUS_ADDRESS"=>"unix:path=/run/user/10000/bus"}, "user" => "joe"})
+ provider.start_service
+ end
end
it "should call the restart command if one is specified" do