diff options
author | Thom May <thom@may.lt> | 2018-02-12 19:10:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-12 19:10:47 +0100 |
commit | 3bd5d2a6be60c392aba534e217ac8f9a05704d40 (patch) | |
tree | acaf585045efdb4be42daecc1b9c2117a8e530d8 /spec | |
parent | a7d56100275045ad44e57386aad86e463788ee85 (diff) | |
parent | eecc7f1b297fd610ae9217b48baa0b05ccafaaf4 (diff) | |
download | chef-3bd5d2a6be60c392aba534e217ac8f9a05704d40.tar.gz |
Merge pull request #6835 from nathwill/sd-moar-actions
add additional systemd_unit actions
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/provider/systemd_unit_spec.rb | 51 | ||||
-rw-r--r-- | spec/unit/resource/systemd_unit_spec.rb | 5 |
2 files changed, 52 insertions, 4 deletions
diff --git a/spec/unit/provider/systemd_unit_spec.rb b/spec/unit/provider/systemd_unit_spec.rb index 8e19503814..15d5944992 100644 --- a/spec/unit/provider/systemd_unit_spec.rb +++ b/spec/unit/provider/systemd_unit_spec.rb @@ -1,6 +1,6 @@ # # Author:: Nathan Williams (<nath.e.will@gmail.com>) -# Copyright:: Copyright (c), Nathan Williams +# Copyright:: Copyright 2016-2018, Nathan Williams # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -250,7 +250,7 @@ describe Chef::Provider::SystemdUnit do .and_return(systemctl_path) end - describe "creates/deletes the unit" do + describe "creates/deletes/presets/reverts the unit" do it "creates the unit file when it does not exist" do allow(provider).to receive(:manage_unit_file) .with(:create) @@ -345,6 +345,22 @@ describe Chef::Provider::SystemdUnit do expect(provider).to_not receive(:manage_unit_file) provider.action_delete end + + it "presets the unit" do + new_resource.user("joe") + expect(provider).to receive(:shell_out_with_systems_locale!) + .with("#{systemctl_path} --user preset #{unit_name_escaped}", user_cmd_opts) + .and_return(shell_out_success) + provider.action_preset + end + + it "reverts the unit" do + new_resource.user("joe") + expect(provider).to receive(:shell_out_with_systems_locale!) + .with("#{systemctl_path} --user revert #{unit_name_escaped}", user_cmd_opts) + .and_return(shell_out_success) + provider.action_revert + end end context "when no user is specified" do @@ -368,11 +384,33 @@ describe Chef::Provider::SystemdUnit do expect(provider).to_not receive(:manage_unit_file) provider.action_delete end + + it "presets the unit" do + expect(provider).to receive(:shell_out_with_systems_locale!) + .with("#{systemctl_path} --system preset #{unit_name_escaped}", {}) + .and_return(shell_out_success) + provider.action_preset + end + + it "reverts the unit" do + expect(provider).to receive(:shell_out_with_systems_locale!) + .with("#{systemctl_path} --system revert #{unit_name_escaped}", {}) + .and_return(shell_out_success) + provider.action_revert + end end end - describe "enables/disables the unit" do + describe "enables/disables/reenables the unit" do context "when a user is specified" do + it "reenables the unit" do + current_resource.user(user_name) + expect(provider).to receive(:shell_out_with_systems_locale!) + .with("#{systemctl_path} --user reenable #{unit_name_escaped}", user_cmd_opts) + .and_return(shell_out_success) + provider.action_reenable + end + it "enables the unit when it is disabled" do current_resource.user(user_name) current_resource.enabled(false) @@ -421,6 +459,13 @@ describe Chef::Provider::SystemdUnit do end context "when no user is specified" do + it "reenables the unit" do + expect(provider).to receive(:shell_out_with_systems_locale!) + .with("#{systemctl_path} --system reenable #{unit_name_escaped}", {}) + .and_return(shell_out_success) + provider.action_reenable + end + it "enables the unit when it is disabled" do current_resource.enabled(false) expect(provider).to receive(:shell_out_with_systems_locale!) diff --git a/spec/unit/resource/systemd_unit_spec.rb b/spec/unit/resource/systemd_unit_spec.rb index 15b792e6bf..9d156402a1 100644 --- a/spec/unit/resource/systemd_unit_spec.rb +++ b/spec/unit/resource/systemd_unit_spec.rb @@ -1,6 +1,6 @@ # # Author:: Nathan Williams (<nath.e.will@gmail.com>) -# Copyright:: Copyright 2016, Nathan Williams +# Copyright:: Copyright 2016-2018, Nathan Williams # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -46,8 +46,11 @@ describe Chef::Resource::SystemdUnit do it "supports appropriate unit actions" do expect { resource.action :create }.not_to raise_error expect { resource.action :delete }.not_to raise_error + expect { resource.action :preset }.not_to raise_error + expect { resource.action :revert }.not_to raise_error expect { resource.action :enable }.not_to raise_error expect { resource.action :disable }.not_to raise_error + expect { resource.action :reenable }.not_to raise_error expect { resource.action :mask }.not_to raise_error expect { resource.action :unmask }.not_to raise_error expect { resource.action :start }.not_to raise_error |