diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2018-07-06 12:23:53 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2018-07-06 12:36:15 -0700 |
commit | e2f21177cae1da7dc462a8f17a3f73e5c915cba0 (patch) | |
tree | c49e14b68003a54b812b786007bc31383fe03b3a /spec/unit/provider | |
parent | c35434e190f2fb5a48c94c577070af82d6ec0743 (diff) | |
download | chef-e2f21177cae1da7dc462a8f17a3f73e5c915cba0.tar.gz |
rebase + squash
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'spec/unit/provider')
-rw-r--r-- | spec/unit/provider/apt_repository_spec.rb | 14 | ||||
-rw-r--r-- | spec/unit/provider/apt_update_spec.rb | 14 | ||||
-rw-r--r-- | spec/unit/provider/cron/unix_spec.rb | 8 | ||||
-rw-r--r-- | spec/unit/provider/ifconfig_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/provider/mdadm_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/provider/mount/aix_spec.rb | 14 | ||||
-rw-r--r-- | spec/unit/provider/mount/mount_spec.rb | 24 | ||||
-rw-r--r-- | spec/unit/provider/mount/solaris_spec.rb | 172 | ||||
-rw-r--r-- | spec/unit/provider/osx_profile_spec.rb | 6 | ||||
-rw-r--r-- | spec/unit/provider/systemd_unit_spec.rb | 261 |
10 files changed, 261 insertions, 260 deletions
diff --git a/spec/unit/provider/apt_repository_spec.rb b/spec/unit/provider/apt_repository_spec.rb index 79b871eb6c..1601e9f629 100644 --- a/spec/unit/provider/apt_repository_spec.rb +++ b/spec/unit/provider/apt_repository_spec.rb @@ -1,6 +1,6 @@ # # Author:: Thom May (<thom@chef.io>) -# Copyright:: 2016-2017, Chef Software, Inc. +# Copyright:: 2016-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -55,7 +55,7 @@ describe Chef::Provider::AptRepository do end let(:apt_key_finger_cmd) do - "apt-key adv --list-public-keys --with-fingerprint --with-colons" + %w{apt-key adv --list-public-keys --with-fingerprint --with-colons} end let(:apt_key_finger) do @@ -106,12 +106,12 @@ C5986B4F1257FFA86632CBA746181433FBB75451 describe "#extract_fingerprints_from_cmd" do it "runs the desired command" do expect(provider).to receive(:shell_out).and_return(apt_key_finger) - provider.extract_fingerprints_from_cmd(apt_key_finger_cmd) + provider.extract_fingerprints_from_cmd(*apt_key_finger_cmd) end it "returns a list of key fingerprints" do expect(provider).to receive(:shell_out).and_return(apt_key_finger) - expect(provider.extract_fingerprints_from_cmd(apt_key_finger_cmd)).to eql(apt_fingerprints) + expect(provider.extract_fingerprints_from_cmd(*apt_key_finger_cmd)).to eql(apt_fingerprints) end end @@ -124,21 +124,21 @@ C5986B4F1257FFA86632CBA746181433FBB75451 describe "#no_new_keys?" do before do - allow(provider).to receive(:extract_fingerprints_from_cmd).with(apt_key_finger_cmd).and_return(apt_fingerprints) + allow(provider).to receive(:extract_fingerprints_from_cmd).with(*apt_key_finger_cmd).and_return(apt_fingerprints) end let(:file) { "/tmp/remote-gpg-keyfile" } it "matches a set of keys" do allow(provider).to receive(:extract_fingerprints_from_cmd) - .with("gpg --with-fingerprint --with-colons #{file}") + .with("gpg", "--with-fingerprint", "--with-colons", file) .and_return(Array(apt_fingerprints.first)) expect(provider.no_new_keys?(file)).to be_truthy end it "notices missing keys" do allow(provider).to receive(:extract_fingerprints_from_cmd) - .with("gpg --with-fingerprint --with-colons #{file}") + .with("gpg", "--with-fingerprint", "--with-colons", file) .and_return(%w{ F36A89E33CC1BD0F71079007327574EE02A818DD }) expect(provider.no_new_keys?(file)).to be_falsey end diff --git a/spec/unit/provider/apt_update_spec.rb b/spec/unit/provider/apt_update_spec.rb index 35a47c45e5..5cd327b66b 100644 --- a/spec/unit/provider/apt_update_spec.rb +++ b/spec/unit/provider/apt_update_spec.rb @@ -37,6 +37,8 @@ describe Chef::Provider::AptUpdate do Chef::Provider::AptUpdate.new(new_resource, run_context) end + let(:apt_update_cmd) { %w{apt-get -q update} } + it "responds to load_current_resource" do expect(provider).to respond_to(:load_current_resource) end @@ -45,7 +47,7 @@ describe Chef::Provider::AptUpdate do before do FileUtils.rmdir config_dir expect(File.exist?(config_dir)).to be false - allow_any_instance_of(Chef::Provider::Execute).to receive(:shell_out!).with("apt-get -q update", anything()) + allow_any_instance_of(Chef::Provider::Execute).to receive(:shell_out_compacted!).with(*apt_update_cmd, anything()) end it "should create the directory" do @@ -64,7 +66,7 @@ describe Chef::Provider::AptUpdate do describe "#action_update" do it "should update the apt cache" do provider.load_current_resource - expect_any_instance_of(Chef::Provider::Execute).to receive(:shell_out!).with("apt-get -q update", anything()) + expect_any_instance_of(Chef::Provider::Execute).to receive(:shell_out_compacted!).with(*apt_update_cmd, anything()) provider.run_action(:update) expect(new_resource).to be_updated_by_last_action end @@ -79,14 +81,14 @@ describe Chef::Provider::AptUpdate do it "should run if the time stamp is old" do expect(File).to receive(:mtime).with("#{stamp_dir}/update-success-stamp").and_return(Time.now - 86_500) - expect_any_instance_of(Chef::Provider::Execute).to receive(:shell_out!).with("apt-get -q update", anything()) + expect_any_instance_of(Chef::Provider::Execute).to receive(:shell_out_compacted!).with(*apt_update_cmd, anything()) provider.run_action(:periodic) expect(new_resource).to be_updated_by_last_action end it "should not run if the time stamp is new" do expect(File).to receive(:mtime).with("#{stamp_dir}/update-success-stamp").and_return(Time.now) - expect_any_instance_of(Chef::Provider::Execute).not_to receive(:shell_out!).with("apt-get -q update", anything()) + expect_any_instance_of(Chef::Provider::Execute).not_to receive(:shell_out_compacted!).with(*apt_update_cmd, anything()) provider.run_action(:periodic) expect(new_resource).to_not be_updated_by_last_action end @@ -98,14 +100,14 @@ describe Chef::Provider::AptUpdate do it "should run if the time stamp is old" do expect(File).to receive(:mtime).with("#{stamp_dir}/update-success-stamp").and_return(Time.now - 500) - expect_any_instance_of(Chef::Provider::Execute).to receive(:shell_out!).with("apt-get -q update", anything()) + expect_any_instance_of(Chef::Provider::Execute).to receive(:shell_out_compacted!).with(*apt_update_cmd, anything()) provider.run_action(:periodic) expect(new_resource).to be_updated_by_last_action end it "should not run if the time stamp is new" do expect(File).to receive(:mtime).with("#{stamp_dir}/update-success-stamp").and_return(Time.now - 300) - expect_any_instance_of(Chef::Provider::Execute).not_to receive(:shell_out!).with("apt-get -q update", anything()) + expect_any_instance_of(Chef::Provider::Execute).not_to receive(:shell_out_compacted!).with(*apt_update_cmd, anything()) provider.run_action(:periodic) expect(new_resource).to_not be_updated_by_last_action end diff --git a/spec/unit/provider/cron/unix_spec.rb b/spec/unit/provider/cron/unix_spec.rb index c77b0e0528..c8ef82e37a 100644 --- a/spec/unit/provider/cron/unix_spec.rb +++ b/spec/unit/provider/cron/unix_spec.rb @@ -66,12 +66,12 @@ describe Chef::Provider::Cron::Unix do before do allow(logger).to receive(:trace) allow(shell_out).to receive(:format_for_exception).and_return("formatted command output") - allow(provider).to receive(:shell_out).with("/usr/bin/crontab -l", user: username).and_return(shell_out) + allow(provider).to receive(:shell_out_compacted).with("/usr/bin/crontab", "-l", user: username).and_return(shell_out) end it "should call crontab -l with the user" do provider.send(:read_crontab) - expect(provider).to have_received(:shell_out).with("/usr/bin/crontab -l", user: username) + expect(provider).to have_received(:shell_out_compacted).with("/usr/bin/crontab", "-l", user: username) end it "should return the contents of the crontab" do @@ -119,12 +119,12 @@ describe Chef::Provider::Cron::Unix do expect(tempfile).to receive(:chmod).with(420) expect(tempfile).to receive(:close!) allow(tempfile).to receive(:<<) - allow(provider).to receive(:shell_out).with("/usr/bin/crontab #{tempfile.path}", user: username).and_return(shell_out) + allow(provider).to receive(:shell_out_compacted).with("/usr/bin/crontab", tempfile.path, user: username).and_return(shell_out) end it "should call crontab for the user" do provider.send(:write_crontab, "Foo") - expect(provider).to have_received(:shell_out).with("/usr/bin/crontab #{tempfile.path}", user: username) + expect(provider).to have_received(:shell_out_compacted).with("/usr/bin/crontab", tempfile.path, user: username) end it "should call crontab with a file containing the crontab" do diff --git a/spec/unit/provider/ifconfig_spec.rb b/spec/unit/provider/ifconfig_spec.rb index 0b8db90428..8c63a3e46e 100644 --- a/spec/unit/provider/ifconfig_spec.rb +++ b/spec/unit/provider/ifconfig_spec.rb @@ -1,6 +1,6 @@ # # Author:: Prajakta Purohit (prajakta@chef.io) -# Copyright:: Copyright 2008-2016, Chef Software Inc. +# Copyright:: Copyright 2008-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -50,7 +50,7 @@ EOS ifconfig = double(stdout: "", exitstatus: 1) allow(@provider).to receive(:shell_out_compacted).and_return(ifconfig) ifconfig_version = double(stdout: "", stderr: net_tools_version, exitstatus: 4) - allow(@provider).to receive(:shell_out_compacted).with("ifconfig --version").and_return(ifconfig_version) + allow(@provider).to receive(:shell_out_compacted).with("ifconfig", "--version").and_return(ifconfig_version) @provider.load_current_resource end it "should track state of ifconfig failure" do diff --git a/spec/unit/provider/mdadm_spec.rb b/spec/unit/provider/mdadm_spec.rb index 17824c4fb8..d79c1b35db 100644 --- a/spec/unit/provider/mdadm_spec.rb +++ b/spec/unit/provider/mdadm_spec.rb @@ -39,13 +39,13 @@ describe Chef::Provider::Mdadm do end it "determines that the metadevice exists when mdadm exit code is zero" do - allow(@provider).to receive(:shell_out!).with("mdadm --detail --test /dev/md1", returns: [0, 4]).and_return(OpenStruct.new(status: 0)) + allow(@provider).to receive(:shell_out_compacted!).with("mdadm", "--detail", "--test", "/dev/md1", returns: [0, 4]).and_return(OpenStruct.new(status: 0)) @provider.load_current_resource expect(@provider.current_resource.exists).to be_truthy end it "determines that the metadevice does not exist when mdadm exit code is 4" do - allow(@provider).to receive(:shell_out!).with("mdadm --detail --test /dev/md1", returns: [0, 4]).and_return(OpenStruct.new(status: 4)) + allow(@provider).to receive(:shell_out_compacted!).with("mdadm", "--detail", "--test", "/dev/md1", returns: [0, 4]).and_return(OpenStruct.new(status: 4)) @provider.load_current_resource expect(@provider.current_resource.exists).to be_falsey end diff --git a/spec/unit/provider/mount/aix_spec.rb b/spec/unit/provider/mount/aix_spec.rb index 80a83130e9..b472e60710 100644 --- a/spec/unit/provider/mount/aix_spec.rb +++ b/spec/unit/provider/mount/aix_spec.rb @@ -1,6 +1,6 @@ # # Author:: Kaustubh Deorukhkar (<kaustubh@clogeny.com>) -# Copyright:: Copyright 2013-2016, Chef Software Inc. +# Copyright:: Copyright 2013-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -71,12 +71,12 @@ WRONG def stub_mounted(provider, mounted_output) response = double("Mixlib::ShellOut command", exitstatus: 0, stdout: mounted_output, stderr: "") - expect(provider).to receive(:shell_out!).with("mount").and_return(response) + expect(provider).to receive(:shell_out_compacted!).with("mount").and_return(response) end def stub_enabled(provider, enabled_output) response = double("Mixlib::ShellOut command", exitstatus: 0, stdout: enabled_output, stderr: "") - expect(provider).to receive(:shell_out).with("lsfs -c #{@new_resource.mount_point}").and_return(response) + expect(provider).to receive(:shell_out_compacted).with("lsfs", "-c", @new_resource.mount_point).and_return(response) end def stub_mounted_enabled(provider, mounted_output, enabled_output) @@ -145,7 +145,7 @@ WRONG it "should mount resource if it is not mounted" do stub_mounted_enabled(@provider, @unmounted_output, "") - expect(@provider).to receive(:shell_out!).with("mount -v #{@new_resource.fstype} #{@new_resource.device} #{@new_resource.mount_point}") + expect(@provider).to receive(:shell_out_compacted!).with("mount", "-v", @new_resource.fstype, @new_resource.device, @new_resource.mount_point) @provider.run_action(:mount) end @@ -163,7 +163,7 @@ WRONG it "should umount resource if it is already mounted" do stub_mounted_enabled(@provider, @mounted_output, "") - expect(@provider).to receive(:shell_out!).with("umount #{@new_resource.mount_point}") + expect(@provider).to receive(:shell_out_compacted!).with("umount", @new_resource.mount_point) @provider.run_action(:umount) end @@ -182,7 +182,7 @@ WRONG @new_resource.supports({ remount: true }) stub_mounted_enabled(@provider, @mounted_output, "") - expect(@provider).to receive(:shell_out!).with("mount -o remount #{@new_resource.device} #{@new_resource.mount_point}") + expect(@provider).to receive(:shell_out_compacted!).with("mount", "-o", "remount", @new_resource.device, @new_resource.mount_point) @provider.run_action(:remount) end @@ -192,7 +192,7 @@ WRONG @new_resource.options("nodev,rw") stub_mounted_enabled(@provider, @mounted_output, "") - expect(@provider).to receive(:shell_out!).with("mount -o remount,nodev,rw #{@new_resource.device} #{@new_resource.mount_point}") + expect(@provider).to receive(:shell_out_compacted!).with("mount", "-o", "remount,nodev,rw", @new_resource.device, @new_resource.mount_point) @provider.run_action(:remount) end diff --git a/spec/unit/provider/mount/mount_spec.rb b/spec/unit/provider/mount/mount_spec.rb index 562dbcdc5d..2af3c93fc9 100644 --- a/spec/unit/provider/mount/mount_spec.rb +++ b/spec/unit/provider/mount/mount_spec.rb @@ -1,6 +1,6 @@ # # Author:: Joshua Timberman (<joshua@chef.io>) -# Copyright:: Copyright 2008-2016, Chef Software Inc. +# Copyright:: Copyright 2008-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -42,7 +42,7 @@ describe Chef::Provider::Mount::Mount do describe "when discovering the current fs state" do before do - allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(stdout: "")) + allow(@provider).to receive(:shell_out_compacted!).and_return(OpenStruct.new(stdout: "")) allow(::File).to receive(:foreach).with("/etc/fstab") end @@ -58,7 +58,7 @@ describe Chef::Provider::Mount::Mount do @new_resource.device_type :uuid @new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a" @stdout_findfs = double("STDOUT", first: "/dev/sdz1") - expect(@provider).to receive(:shell_out).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_return(@status) + expect(@provider).to receive(:shell_out_compacted).with("/sbin/findfs", "UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_return(@status) @provider.load_current_resource @provider.mountable? end @@ -97,7 +97,7 @@ describe Chef::Provider::Mount::Mount do status = double(stdout: "", exitstatus: 1) @new_resource.device_type :uuid @new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a" - expect(@provider).to receive(:shell_out).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_return(status) + expect(@provider).to receive(:shell_out_compacted).with("/sbin/findfs", "UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_return(status) expect(::File).to receive(:exists?).with("").and_return(false) expect { @provider.load_current_resource(); @provider.mountable? }.to raise_error(Chef::Exceptions::Mount) end @@ -295,14 +295,14 @@ describe Chef::Provider::Mount::Mount do describe "mount_fs" do it "should mount the filesystem if it is not mounted" do - expect(@provider).to receive(:shell_out!).with("mount -t ext3 -o defaults /dev/sdz1 /tmp/foo") + expect(@provider).to receive(:shell_out_compacted!).with("mount", "-t", "ext3", "-o", "defaults", "/dev/sdz1", "/tmp/foo") @provider.mount_fs() end it "should mount the filesystem with options if options were passed" do options = "rw,noexec,noauto" @new_resource.options(%w{rw noexec noauto}) - expect(@provider).to receive(:shell_out!).with("mount -t ext3 -o rw,noexec,noauto /dev/sdz1 /tmp/foo") + expect(@provider).to receive(:shell_out_compacted!).with("mount", "-t", "ext3", "-o", "rw,noexec,noauto", "/dev/sdz1", "/tmp/foo") @provider.mount_fs() end @@ -310,10 +310,10 @@ describe Chef::Provider::Mount::Mount do status = double(stdout: "/dev/sdz1\n", exitstatus: 1) @new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a" @new_resource.device_type :uuid - allow(@provider).to receive(:shell_out).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_return(status) + allow(@provider).to receive(:shell_out_compacted).with("/sbin/findfs", "UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_return(status) @stdout_mock = double("stdout mock") allow(@stdout_mock).to receive(:each).and_yield("#{@new_resource.device} on #{@new_resource.mount_point}") - expect(@provider).to receive(:shell_out!).with("mount -t #{@new_resource.fstype} -o defaults -U #{@new_resource.device} #{@new_resource.mount_point}").and_return(@stdout_mock) + expect(@provider).to receive(:shell_out_compacted!).with("mount", "-t", @new_resource.fstype, "-o", "defaults", "-U", @new_resource.device, @new_resource.mount_point).and_return(@stdout_mock) @provider.mount_fs() end @@ -328,7 +328,7 @@ describe Chef::Provider::Mount::Mount do describe "umount_fs" do it "should umount the filesystem if it is mounted" do @current_resource.mounted(true) - expect(@provider).to receive(:shell_out!).with("umount /tmp/foo") + expect(@provider).to receive(:shell_out!).with("umount", "/tmp/foo") @provider.umount_fs() end @@ -343,7 +343,7 @@ describe Chef::Provider::Mount::Mount do it "should use mount -o remount if remount is supported" do @new_resource.supports({ remount: true }) @current_resource.mounted(true) - expect(@provider).to receive(:shell_out!).with("mount -o remount,defaults #{@new_resource.mount_point}") + expect(@provider).to receive(:shell_out_compacted!).with("mount", "-o", "remount,defaults", @new_resource.mount_point) @provider.remount_fs end @@ -352,7 +352,7 @@ describe Chef::Provider::Mount::Mount do options = "rw,noexec,noauto" @new_resource.options(%w{rw noexec noauto}) @current_resource.mounted(true) - expect(@provider).to receive(:shell_out!).with("mount -o remount,rw,noexec,noauto #{@new_resource.mount_point}") + expect(@provider).to receive(:shell_out_compacted!).with("mount", "-o", "remount,rw,noexec,noauto", @new_resource.mount_point) @provider.remount_fs end @@ -500,7 +500,7 @@ describe Chef::Provider::Mount::Mount do it "should update the existing line" do @current_resource.enabled(true) status = double(stdout: "/dev/sdz1\n", exitstatus: 1) - expect(@provider).to receive(:shell_out).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_return(status) + expect(@provider).to receive(:shell_out_compacted).with("/sbin/findfs", "UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_return(status) filesystems = [%q{/dev/sdy1 /tmp/foo ext3 defaults 1 2}, %q{/dev/sdz1 /tmp/foo ext3 defaults 1 2}].join("\n") diff --git a/spec/unit/provider/mount/solaris_spec.rb b/spec/unit/provider/mount/solaris_spec.rb index e489b9001a..4e73bc77b5 100644 --- a/spec/unit/provider/mount/solaris_spec.rb +++ b/spec/unit/provider/mount/solaris_spec.rb @@ -1,6 +1,6 @@ # # Author:: Lamont Granquist (<lamont@chef.io>) -# Copyright:: Copyright 2008-2016, Chef Software, Inc. +# Copyright:: Copyright 2008-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -57,22 +57,22 @@ describe Chef::Provider::Mount::Solaris, :unix_only do end let(:vfstab_file_contents) do - <<-EOF.gsub /^\s*/, "" - #device device mount FS fsck mount mount - #to mount to fsck point type pass at boot options - # - fd - /dev/fd fd - no - - /proc - /proc proc - no - - # swap - /dev/dsk/c0t0d0s1 - - swap - no - - # root - /dev/dsk/c0t0d0s0 /dev/rdsk/c0t0d0s0 / ufs 1 no - - # tmpfs - swap - /tmp tmpfs - yes - - # nfs - cartman:/share2 - /cartman nfs - yes rw,soft - # ufs - /dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - + <<~EOF + #device device mount FS fsck mount mount + #to mount to fsck point type pass at boot options + # + fd - /dev/fd fd - no - + /proc - /proc proc - no - + # swap + /dev/dsk/c0t0d0s1 - - swap - no - + # root + /dev/dsk/c0t0d0s0 /dev/rdsk/c0t0d0s0 / ufs 1 no - + # tmpfs + swap - /tmp tmpfs - yes - + # nfs + cartman:/share2 - /cartman nfs - yes rw,soft + # ufs + /dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - EOF end @@ -84,15 +84,15 @@ describe Chef::Provider::Mount::Solaris, :unix_only do end let(:mount_output) do - <<-EOF.gsub /^\s*/, "" - /dev/dsk/c0t0d0s0 on / type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200000 on Tue Jul 31 22:34:46 2012 - /dev/dsk/c0t2d0s7 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012 + <<~EOF + /dev/dsk/c0t0d0s0 on / type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200000 on Tue Jul 31 22:34:46 2012 + /dev/dsk/c0t2d0s7 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012 EOF end before do stub_const("Chef::Provider::Mount::Solaris::VFSTAB", vfstab_file.path ) - allow(provider).to receive(:shell_out!).with("mount -v").and_return(OpenStruct.new(stdout: mount_output)) + allow(provider).to receive(:shell_out_compacted!).with("mount", "-v").and_return(OpenStruct.new(stdout: mount_output)) allow(File).to receive(:symlink?).with(device).and_return(false) allow(File).to receive(:exist?).and_call_original # Tempfile.open on ruby 1.8.7 calls File.exist? allow(File).to receive(:exist?).with(device).and_return(true) @@ -215,22 +215,22 @@ describe Chef::Provider::Mount::Solaris, :unix_only do context "when loading a normal UFS filesystem with noauto, don't mount at boot" do let(:vfstab_file_contents) do - <<-EOF.gsub /^\s*/, "" - #device device mount FS fsck mount mount - #to mount to fsck point type pass at boot options - # - fd - /dev/fd fd - no - - /proc - /proc proc - no - - # swap - /dev/dsk/c0t0d0s1 - - swap - no - - # root - /dev/dsk/c0t0d0s0 /dev/rdsk/c0t0d0s0 / ufs 1 no - - # tmpfs - swap - /tmp tmpfs - yes - - # nfs - cartman:/share2 - /cartman nfs - yes rw,soft - # ufs - /dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 no - + <<~EOF + #device device mount FS fsck mount mount + #to mount to fsck point type pass at boot options + # + fd - /dev/fd fd - no - + /proc - /proc proc - no - + # swap + /dev/dsk/c0t0d0s1 - - swap - no - + # root + /dev/dsk/c0t0d0s0 /dev/rdsk/c0t0d0s0 / ufs 1 no - + # tmpfs + swap - /tmp tmpfs - yes - + # nfs + cartman:/share2 - /cartman nfs - yes rw,soft + # ufs + /dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 no - EOF end @@ -245,13 +245,13 @@ describe Chef::Provider::Mount::Solaris, :unix_only do context "when the device is an smbfs mount" do let(:mount_output) do - <<-EOF.gsub /^\s*/, "" - //solarsystem/tmp on /mnt type smbfs read/write/setuid/devices/dev=5080000 on Tue Mar 29 11:40:18 2011 + <<~EOF + //solarsystem/tmp on /mnt type smbfs read/write/setuid/devices/dev=5080000 on Tue Mar 29 11:40:18 2011 EOF end let(:vfstab_file_contents) do - <<-EOF.gsub /^\s*/, "" - //WORKGROUP;username:password@host/share - /mountpoint smbfs - no fileperms=0777,dirperms=0777 + <<~EOF + //WORKGROUP;username:password@host/share - /mountpoint smbfs - no fileperms=0777,dirperms=0777 EOF end @@ -264,14 +264,14 @@ describe Chef::Provider::Mount::Solaris, :unix_only do context "when the device is an NFS mount" do let(:mount_output) do - <<-EOF.gsub /^\s*/, "" - cartman:/share2 on /cartman type nfs rsize=32768,wsize=32768,NFSv4,dev=4000004 on Tue Mar 29 11:40:18 2011 + <<~EOF + cartman:/share2 on /cartman type nfs rsize=32768,wsize=32768,NFSv4,dev=4000004 on Tue Mar 29 11:40:18 2011 EOF end let(:vfstab_file_contents) do - <<-EOF.gsub /^\s*/, "" - cartman:/share2 - /cartman nfs - yes rw,soft + <<~EOF + cartman:/share2 - /cartman nfs - yes rw,soft EOF end @@ -335,14 +335,14 @@ describe Chef::Provider::Mount::Solaris, :unix_only do let(:target) { "/dev/mapper/target" } let(:mount_output) do - <<-EOF.gsub /^\s*/, "" - #{target} on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012 + <<~EOF + #{target} on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012 EOF end let(:vfstab_file_contents) do - <<-EOF.gsub /^\s*/, "" - #{target} /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - + <<~EOF + #{target} /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - EOF end @@ -372,14 +372,14 @@ describe Chef::Provider::Mount::Solaris, :unix_only do let(:absolute_target) { File.expand_path(target, File.dirname(device)) } let(:mount_output) do - <<-EOF.gsub /^\s*/, "" - #{absolute_target} on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012 + <<~EOF + #{absolute_target} on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012 EOF end let(:vfstab_file_contents) do - <<-EOF.gsub /^\s*/, "" - #{absolute_target} /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - + <<~EOF + #{absolute_target} /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - EOF end @@ -405,9 +405,9 @@ describe Chef::Provider::Mount::Solaris, :unix_only do context "when the matching mount point is last in the mounts list" do let(:mount_output) do - <<-EOF.gsub /^\s*/, "" - /dev/dsk/c0t0d0s0 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200000 on Tue Jul 31 22:34:46 2012 - /dev/dsk/c0t2d0s7 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012 + <<~EOF + /dev/dsk/c0t0d0s0 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200000 on Tue Jul 31 22:34:46 2012 + /dev/dsk/c0t2d0s7 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012 EOF end it "should set mounted true" do @@ -418,9 +418,9 @@ describe Chef::Provider::Mount::Solaris, :unix_only do context "when the matching mount point is not last in the mounts list" do let(:mount_output) do - <<-EOF.gsub /^\s*/, "" - /dev/dsk/c0t2d0s7 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012 - /dev/dsk/c0t0d0s0 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200000 on Tue Jul 31 22:34:46 2012 + <<~EOF + /dev/dsk/c0t2d0s7 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012 + /dev/dsk/c0t0d0s0 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200000 on Tue Jul 31 22:34:46 2012 EOF end it "should set mounted false" do @@ -431,8 +431,8 @@ describe Chef::Provider::Mount::Solaris, :unix_only do context "when the matching mount point is not in the mounts list (mountpoint wrong)" do let(:mount_output) do - <<-EOF.gsub /^\s*/, "" - /dev/dsk/c0t2d0s7 on /mnt/foob type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012 + <<~EOF + /dev/dsk/c0t2d0s7 on /mnt/foob type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012 EOF end it "should set mounted false" do @@ -443,8 +443,8 @@ describe Chef::Provider::Mount::Solaris, :unix_only do context "when the matching mount point is not in the mounts list (raw device wrong)" do let(:mount_output) do - <<-EOF.gsub /^\s*/, "" - /dev/dsk/c0t2d0s72 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012 + <<~EOF + /dev/dsk/c0t2d0s72 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012 EOF end it "should set mounted false" do @@ -455,9 +455,9 @@ describe Chef::Provider::Mount::Solaris, :unix_only do context "when the mount point is last in fstab" do let(:vfstab_file_contents) do - <<-EOF.gsub /^\s*/, "" - /dev/dsk/c0t2d0s72 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - - /dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - + <<~EOF + /dev/dsk/c0t2d0s72 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - + /dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - EOF end @@ -469,9 +469,9 @@ describe Chef::Provider::Mount::Solaris, :unix_only do context "when the mount point is not last in fstab and is a substring of another mount" do let(:vfstab_file_contents) do - <<-EOF.gsub /^\s*/, "" - /dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - - /dev/dsk/c0t2d0s72 /dev/rdsk/c0t2d0s7 /mnt/foo/bar ufs 2 yes - + <<~EOF + /dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - + /dev/dsk/c0t2d0s72 /dev/rdsk/c0t2d0s7 /mnt/foo/bar ufs 2 yes - EOF end @@ -483,9 +483,9 @@ describe Chef::Provider::Mount::Solaris, :unix_only do context "when the mount point is not last in fstab" do let(:vfstab_file_contents) do - <<-EOF.gsub /^\s*/, "" - /dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - - /dev/dsk/c0t2d0s72 /dev/rdsk/c0t2d0s72 /mnt/foo ufs 2 yes - + <<~EOF + /dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - + /dev/dsk/c0t2d0s72 /dev/rdsk/c0t2d0s72 /mnt/foo ufs 2 yes - EOF end @@ -497,8 +497,8 @@ describe Chef::Provider::Mount::Solaris, :unix_only do context "when the mount point is not in fstab, but the mountpoint is a substring of one that is" do let(:vfstab_file_contents) do - <<-EOF.gsub /^\s*/, "" - /dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foob ufs 2 yes - + <<~EOF + /dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foob ufs 2 yes - EOF end @@ -510,8 +510,8 @@ describe Chef::Provider::Mount::Solaris, :unix_only do context "when the mount point is not in fstab, but the device is a substring of one that is" do let(:vfstab_file_contents) do - <<-EOF.gsub /^\s*/, "" - /dev/dsk/c0t2d0s72 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - + <<~EOF + /dev/dsk/c0t2d0s72 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - EOF end @@ -523,8 +523,8 @@ describe Chef::Provider::Mount::Solaris, :unix_only do context "when the mountpoint line is commented out" do let(:vfstab_file_contents) do - <<-EOF.gsub /^\s*/, "" - #/dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - + <<~EOF + #/dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - EOF end @@ -538,28 +538,28 @@ describe Chef::Provider::Mount::Solaris, :unix_only do context "after the mount's state has been discovered" do describe "mount_fs" do it "should mount the filesystem" do - expect(provider).to receive(:shell_out!).with("mount -F #{fstype} #{device} #{mountpoint}") + expect(provider).to receive(:shell_out_compacted!).with("mount", "-F", fstype, device, mountpoint) provider.mount_fs() end it "should mount the filesystem with options if options were passed" do options = "logging,noatime,largefiles,nosuid,rw,quota" new_resource.options(options.split(/,/)) - expect(provider).to receive(:shell_out!).with("mount -F #{fstype} -o #{options} #{device} #{mountpoint}") + expect(provider).to receive(:shell_out_compacted!).with("mount", "-F", fstype, "-o", options, device, mountpoint) provider.mount_fs() end it "should delete the 'noauto' magic option" do options = "rw,noauto" new_resource.options(%w{rw noauto}) - expect(provider).to receive(:shell_out!).with("mount -F #{fstype} -o rw #{device} #{mountpoint}") + expect(provider).to receive(:shell_out_compacted!).with("mount", "-F", fstype, "-o", "rw", device, mountpoint) provider.mount_fs() end end describe "umount_fs" do it "should umount the filesystem if it is mounted" do - expect(provider).to receive(:shell_out!).with("umount #{mountpoint}") + expect(provider).to receive(:shell_out_compacted!).with("umount", mountpoint) provider.umount_fs() end end @@ -567,7 +567,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do describe "remount_fs without options and do not mount at boot" do it "should use mount -o remount" do new_resource.options(%w{noauto}) - expect(provider).to receive(:shell_out!).with("mount -o remount #{new_resource.mount_point}") + expect(provider).to receive(:shell_out_compacted!).with("mount", "-o", "remount", new_resource.mount_point) provider.remount_fs end end @@ -575,7 +575,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do describe "remount_fs with options and do not mount at boot" do it "should use mount -o remount,rw" do new_resource.options(%w{rw noauto}) - expect(provider).to receive(:shell_out!).with("mount -o remount,rw #{new_resource.mount_point}") + expect(provider).to receive(:shell_out_compacted!).with("mount", "-o", "remount,rw", new_resource.mount_point) provider.remount_fs end end @@ -583,7 +583,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do describe "remount_fs with options and mount at boot" do it "should use mount -o remount,rw" do new_resource.options(%w{rw}) - expect(provider).to receive(:shell_out!).with("mount -o remount,rw #{new_resource.mount_point}") + expect(provider).to receive(:shell_out_compacted!).with("mount", "-o", "remount,rw", new_resource.mount_point) provider.remount_fs end end @@ -591,7 +591,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do describe "remount_fs without options and mount at boot" do it "should use mount -o remount" do new_resource.options([]) - expect(provider).to receive(:shell_out!).with("mount -o remount #{new_resource.mount_point}") + expect(provider).to receive(:shell_out_compacted!).with("mount", "-o", "remount", new_resource.mount_point) provider.remount_fs end end diff --git a/spec/unit/provider/osx_profile_spec.rb b/spec/unit/provider/osx_profile_spec.rb index dce52fd598..624ef8cca9 100644 --- a/spec/unit/provider/osx_profile_spec.rb +++ b/spec/unit/provider/osx_profile_spec.rb @@ -116,7 +116,7 @@ describe Chef::Provider::OsxProfile do allow(provider).to receive(:generate_tempfile).and_return(tempfile) allow(provider).to receive(:get_installed_profiles).and_call_original allow(provider).to receive(:read_plist).and_return(all_profiles) - expect(provider).to receive(:shell_out!).with("profiles -P -o '/tmp/allprofiles.plist'") + expect(provider).to receive(:shell_out_compacted!).with("profiles", "-P", "-o", "/tmp/allprofiles.plist") provider.load_current_resource end @@ -164,7 +164,7 @@ describe Chef::Provider::OsxProfile do all_profiles["_computerlevel"][1]["ProfileUUID"] = "1781fbec-3325-565f-9022-9bb39245d4dd" provider.load_current_resource allow(provider).to receive(:write_profile_to_disk).and_return(profile_path) - expect(provider).to receive(:shell_out).with("profiles -I -F '#{profile_path}'").and_return(shell_out_success) + expect(provider).to receive(:shell_out_compacted).with("profiles", "-I", "-F", profile_path).and_return(shell_out_success) provider.action_install() end @@ -248,7 +248,7 @@ describe Chef::Provider::OsxProfile do new_resource.identifier "com.testprofile.screensaver" new_resource.action(:remove) provider.load_current_resource - expect(provider).to receive(:shell_out).with("profiles -R -p '#{new_resource.identifier}'").and_return(shell_out_success) + expect(provider).to receive(:shell_out_compacted).with("profiles", "-R", "-p", new_resource.identifier).and_return(shell_out_success) provider.action_remove() end end diff --git a/spec/unit/provider/systemd_unit_spec.rb b/spec/unit/provider/systemd_unit_spec.rb index 93f624933f..00f39d0fd9 100644 --- a/spec/unit/provider/systemd_unit_spec.rb +++ b/spec/unit/provider/systemd_unit_spec.rb @@ -24,7 +24,6 @@ describe Chef::Provider::SystemdUnit do let(:events) { Chef::EventDispatch::Dispatcher.new } let(:run_context) { Chef::RunContext.new(node, {}, events) } let(:unit_name) { "sysstat-collect\\x2d.timer" } - let(:unit_name_escaped) { "sysstat-collect\\\\x2d.timer" } let(:user_name) { "joe" } let(:current_resource) { Chef::Resource::SystemdUnit.new(unit_name) } let(:new_resource) { Chef::Resource::SystemdUnit.new(unit_name) } @@ -285,9 +284,9 @@ describe Chef::Provider::SystemdUnit do new_resource.user("joe") allow(provider).to receive(:manage_unit_file).with(:create) expect(new_resource.triggers_reload).to eq true - allow(provider).to receive(:shell_out!) - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --user daemon-reload", **user_cmd_opts, default_env: false) + allow(provider).to receive(:shell_out_compacted!) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--user", "daemon-reload", **user_cmd_opts, default_env: false) provider.action_create end @@ -298,9 +297,9 @@ describe Chef::Provider::SystemdUnit do .and_return(true) allow(provider).to receive(:manage_unit_file).with(:delete) expect(new_resource.triggers_reload).to eq true - allow(provider).to receive(:shell_out!) - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --user daemon-reload", **user_cmd_opts, default_env: false) + allow(provider).to receive(:shell_out_compacted!) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--user", "daemon-reload", **user_cmd_opts, default_env: false) provider.action_delete end @@ -308,9 +307,9 @@ describe Chef::Provider::SystemdUnit do new_resource.user("joe") new_resource.triggers_reload(false) allow(provider).to receive(:manage_unit_file).with(:create) - allow(provider).to receive(:shell_out!) - expect(provider).to_not receive(:shell_out!) - .with("#{systemctl_path} --user daemon-reload", **user_cmd_opts, default_env: false) + allow(provider).to receive(:shell_out_compacted!) + expect(provider).to_not receive(:shell_out_compacted!) + .with(systemctl_path, "--user", "daemon-reload", **user_cmd_opts, default_env: false) provider.action_create end @@ -321,9 +320,9 @@ describe Chef::Provider::SystemdUnit do .with(unit_path_user) .and_return(true) allow(provider).to receive(:manage_unit_file).with(:delete) - allow(provider).to receive(:shell_out!) - expect(provider).to_not receive(:shell_out!) - .with("#{systemctl_path} --user daemon-reload", **user_cmd_opts, default_env: false) + allow(provider).to receive(:shell_out_compacted!) + expect(provider).to_not receive(:shell_out_compacted!) + .with(systemctl_path, "--user", "daemon-reload", **user_cmd_opts, default_env: false) provider.action_delete end @@ -352,16 +351,16 @@ describe Chef::Provider::SystemdUnit do it "presets the unit" do new_resource.user("joe") - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --user preset #{unit_name_escaped}", **user_cmd_opts, default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--user", "preset", unit_name, **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("#{systemctl_path} --user revert #{unit_name_escaped}", **user_cmd_opts, default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--user", "revert", unit_name, **user_cmd_opts) .and_return(shell_out_success) provider.action_revert end @@ -371,9 +370,9 @@ describe Chef::Provider::SystemdUnit do it "triggers a daemon-reload when creating a unit with triggers_reload" do allow(provider).to receive(:manage_unit_file).with(:create) expect(new_resource.triggers_reload).to eq true - allow(provider).to receive(:shell_out!) - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --system daemon-reload", default_env: false) + allow(provider).to receive(:shell_out_compacted!) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--system", "daemon-reload", default_env: false) provider.action_create end @@ -383,18 +382,18 @@ describe Chef::Provider::SystemdUnit do .and_return(true) allow(provider).to receive(:manage_unit_file).with(:delete) expect(new_resource.triggers_reload).to eq true - allow(provider).to receive(:shell_out!) - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --system daemon-reload", default_env: false) + allow(provider).to receive(:shell_out_compacted!) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--system", "daemon-reload", default_env: false) provider.action_delete end it "does not trigger a daemon-reload when creating a unit without triggers_reload" do new_resource.triggers_reload(false) allow(provider).to receive(:manage_unit_file).with(:create) - allow(provider).to receive(:shell_out!) - expect(provider).to_not receive(:shell_out!) - .with("#{systemctl_path} --system daemon-reload", default_env: false) + allow(provider).to receive(:shell_out_compacted!) + expect(provider).to_not receive(:shell_out_compacted!) + .with(systemctl_path, "--system", "daemon-reload", default_env: false) provider.action_create end @@ -404,9 +403,9 @@ describe Chef::Provider::SystemdUnit do .with(unit_path_system) .and_return(true) allow(provider).to receive(:manage_unit_file).with(:delete) - allow(provider).to receive(:shell_out!) - expect(provider).to_not receive(:shell_out!) - .with("#{systemctl_path} --system daemon-reload", default_env: false) + allow(provider).to receive(:shell_out_compacted!) + expect(provider).to_not receive(:shell_out_compacted!) + .with(systemctl_path, "--system", "daemon-reload", default_env: false) provider.action_delete end it "deletes the file when it exists" do @@ -431,15 +430,15 @@ describe Chef::Provider::SystemdUnit do end it "presets the unit" do - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --system preset #{unit_name_escaped}", default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--system", "preset", unit_name) .and_return(shell_out_success) provider.action_preset end it "reverts the unit" do - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --system revert #{unit_name_escaped}", default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--system", "revert", unit_name) .and_return(shell_out_success) provider.action_revert end @@ -450,8 +449,8 @@ describe Chef::Provider::SystemdUnit 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("#{systemctl_path} --user reenable #{unit_name_escaped}", **user_cmd_opts, default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--user", "reenable", unit_name, **user_cmd_opts) .and_return(shell_out_success) provider.action_reenable end @@ -459,8 +458,8 @@ describe Chef::Provider::SystemdUnit do it "enables the unit when it is disabled" do current_resource.user(user_name) current_resource.enabled(false) - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --user enable #{unit_name_escaped}", **user_cmd_opts, default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--user", "enable", unit_name, **user_cmd_opts) .and_return(shell_out_success) provider.action_enable end @@ -468,22 +467,22 @@ describe Chef::Provider::SystemdUnit do it "does not enable the unit when it is enabled" do current_resource.user(user_name) current_resource.enabled(true) - expect(provider).not_to receive(:shell_out!) + expect(provider).not_to receive(:shell_out_compacted!) provider.action_enable end it "does not enable the unit when it is static" do current_resource.user(user_name) current_resource.static(true) - expect(provider).not_to receive(:shell_out!) + expect(provider).not_to receive(:shell_out_compacted!) provider.action_enable end it "disables the unit when it is enabled" do current_resource.user(user_name) current_resource.enabled(true) - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --user disable #{unit_name_escaped}", **user_cmd_opts, default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--user", "disable", unit_name, **user_cmd_opts) .and_return(shell_out_success) provider.action_disable end @@ -491,64 +490,64 @@ describe Chef::Provider::SystemdUnit do it "does not disable the unit when it is disabled" do current_resource.user(user_name) current_resource.enabled(false) - expect(provider).not_to receive(:shell_out!) + expect(provider).not_to receive(:shell_out_compacted!) provider.action_disable end it "does not disable the unit when it is static" do current_resource.user(user_name) current_resource.static(true) - expect(provider).not_to receive(:shell_out!) + expect(provider).not_to receive(:shell_out_compacted!) provider.action_disable end end context "when no user is specified" do it "reenables the unit" do - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --system reenable #{unit_name_escaped}", default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--system", "reenable", unit_name) .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("#{systemctl_path} --system enable #{unit_name_escaped}", default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--system", "enable", unit_name) .and_return(shell_out_success) provider.action_enable end it "does not enable the unit when it is enabled" do current_resource.enabled(true) - expect(provider).not_to receive(:shell_out!) + expect(provider).not_to receive(:shell_out_compacted!) provider.action_enable end it "does not enable the unit when it is static" do current_resource.static(true) - expect(provider).not_to receive(:shell_out!) + expect(provider).not_to receive(:shell_out_compacted!) provider.action_enable end it "disables the unit when it is enabled" do current_resource.enabled(true) - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --system disable #{unit_name_escaped}", default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--system", "disable", unit_name) .and_return(shell_out_success) provider.action_disable end it "does not disable the unit when it is disabled" do current_resource.enabled(false) - expect(provider).not_to receive(:shell_out!) + expect(provider).not_to receive(:shell_out_compacted!) provider.action_disable end it "does not disable the unit when it is static" do current_resource.user(user_name) current_resource.static(true) - expect(provider).not_to receive(:shell_out!) + expect(provider).not_to receive(:shell_out_compacted!) provider.action_disable end end @@ -559,8 +558,8 @@ describe Chef::Provider::SystemdUnit do it "masks the unit when it is unmasked" do current_resource.user(user_name) current_resource.masked(false) - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --user mask #{unit_name_escaped}", **user_cmd_opts, default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--user", "mask", unit_name, **user_cmd_opts) .and_return(shell_out_success) provider.action_mask end @@ -568,15 +567,15 @@ describe Chef::Provider::SystemdUnit do it "does not mask the unit when it is masked" do current_resource.user(user_name) current_resource.masked(true) - expect(provider).not_to receive(:shell_out!) + expect(provider).not_to receive(:shell_out_compacted!) provider.action_mask end it "unmasks the unit when it is masked" do current_resource.user(user_name) current_resource.masked(true) - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --user unmask #{unit_name_escaped}", **user_cmd_opts, default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--user", "unmask", unit_name, **user_cmd_opts) .and_return(shell_out_success) provider.action_unmask end @@ -584,7 +583,7 @@ describe Chef::Provider::SystemdUnit do it "does not unmask the unit when it is unmasked" do current_resource.user(user_name) current_resource.masked(false) - expect(provider).not_to receive(:shell_out!) + expect(provider).not_to receive(:shell_out_compacted!) provider.action_unmask end end @@ -592,29 +591,29 @@ describe Chef::Provider::SystemdUnit do context "when no user is specified" do it "masks the unit when it is unmasked" do current_resource.masked(false) - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --system mask #{unit_name_escaped}", default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--system", "mask", unit_name) .and_return(shell_out_success) provider.action_mask end it "does not mask the unit when it is masked" do current_resource.masked(true) - expect(provider).not_to receive(:shell_out!) + expect(provider).not_to receive(:shell_out_compacted!) provider.action_mask end it "unmasks the unit when it is masked" do current_resource.masked(true) - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --system unmask #{unit_name_escaped}", default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--system", "unmask", unit_name) .and_return(shell_out_success) provider.action_unmask end it "does not unmask the unit when it is unmasked" do current_resource.masked(false) - expect(provider).not_to receive(:shell_out!) + expect(provider).not_to receive(:shell_out_compacted!) provider.action_unmask end end @@ -625,8 +624,8 @@ describe Chef::Provider::SystemdUnit do it "starts the unit when it is inactive" do current_resource.user(user_name) current_resource.active(false) - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --user start #{unit_name_escaped}", **user_cmd_opts, default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--user", "start", unit_name, **user_cmd_opts, default_env: false) .and_return(shell_out_success) provider.action_start end @@ -634,15 +633,15 @@ describe Chef::Provider::SystemdUnit do it "does not start the unit when it is active" do current_resource.user(user_name) current_resource.active(true) - expect(provider).not_to receive(:shell_out!) + expect(provider).not_to receive(:shell_out_compacted!) provider.action_start end it "stops the unit when it is active" do current_resource.user(user_name) current_resource.active(true) - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --user stop #{unit_name_escaped}", **user_cmd_opts, default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--user", "stop", unit_name, **user_cmd_opts, default_env: false) .and_return(shell_out_success) provider.action_stop end @@ -650,7 +649,7 @@ describe Chef::Provider::SystemdUnit do it "does not stop the unit when it is inactive" do current_resource.user(user_name) current_resource.active(false) - expect(provider).not_to receive(:shell_out!) + expect(provider).not_to receive(:shell_out_compacted!) provider.action_stop end end @@ -658,29 +657,29 @@ describe Chef::Provider::SystemdUnit do context "when no user is specified" do it "starts the unit when it is inactive" do current_resource.active(false) - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --system start #{unit_name_escaped}", default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--system", "start", unit_name, default_env: false) .and_return(shell_out_success) provider.action_start end it "does not start the unit when it is active" do current_resource.active(true) - expect(provider).to_not receive(:shell_out!) + expect(provider).to_not receive(:shell_out_compacted!) provider.action_start end it "stops the unit when it is active" do current_resource.active(true) - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --system stop #{unit_name_escaped}", default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--system", "stop", unit_name, default_env: false) .and_return(shell_out_success) provider.action_stop end it "does not stop the unit when it is inactive" do current_resource.active(false) - expect(provider).not_to receive(:shell_out!) + expect(provider).not_to receive(:shell_out_compacted!) provider.action_stop end end @@ -690,8 +689,8 @@ describe Chef::Provider::SystemdUnit do context "when a user is specified" do it "restarts the unit" do current_resource.user(user_name) - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --user restart #{unit_name_escaped}", **user_cmd_opts, default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--user", "restart", unit_name, **user_cmd_opts, default_env: false) .and_return(shell_out_success) provider.action_restart end @@ -699,8 +698,8 @@ describe Chef::Provider::SystemdUnit do it "reloads the unit if active" do current_resource.user(user_name) current_resource.active(true) - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --user reload #{unit_name_escaped}", **user_cmd_opts, default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--user", "reload", unit_name, **user_cmd_opts, default_env: false) .and_return(shell_out_success) provider.action_reload end @@ -708,30 +707,30 @@ describe Chef::Provider::SystemdUnit do it "does not reload if the unit is inactive" do current_resource.user(user_name) current_resource.active(false) - expect(provider).not_to receive(:shell_out!) + expect(provider).not_to receive(:shell_out_compacted!) provider.action_reload end end context "when no user is specified" do it "restarts the unit" do - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --system restart #{unit_name_escaped}", default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--system", "restart", unit_name, default_env: false) .and_return(shell_out_success) provider.action_restart end it "reloads the unit if active" do current_resource.active(true) - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --system reload #{unit_name_escaped}", default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--system", "reload", unit_name, default_env: false) .and_return(shell_out_success) provider.action_reload end it "does not reload the unit if inactive" do current_resource.active(false) - expect(provider).not_to receive(:shell_out!) + expect(provider).not_to receive(:shell_out_compacted!) provider.action_reload end end @@ -741,8 +740,8 @@ describe Chef::Provider::SystemdUnit do context "when a user is specified" do it "try-restarts the unit" do current_resource.user(user_name) - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --user try-restart #{unit_name_escaped}", **user_cmd_opts, default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--user", "try-restart", unit_name, **user_cmd_opts, default_env: false) .and_return(shell_out_success) provider.action_try_restart end @@ -750,8 +749,8 @@ describe Chef::Provider::SystemdUnit do context "when no user is specified" do it "try-restarts the unit" do - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --system try-restart #{unit_name_escaped}", default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--system", "try-restart", unit_name, default_env: false) .and_return(shell_out_success) provider.action_try_restart end @@ -762,8 +761,8 @@ describe Chef::Provider::SystemdUnit do context "when a user is specified" do it "reload-or-restarts the unit" do current_resource.user(user_name) - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --user reload-or-restart #{unit_name_escaped}", **user_cmd_opts, default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--user", "reload-or-restart", unit_name, **user_cmd_opts, default_env: false) .and_return(shell_out_success) provider.action_reload_or_restart end @@ -771,8 +770,8 @@ describe Chef::Provider::SystemdUnit do context "when no user is specified" do it "reload-or-restarts the unit" do - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --system reload-or-restart #{unit_name_escaped}", default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--system", "reload-or-restart", unit_name, default_env: false) .and_return(shell_out_success) provider.action_reload_or_restart end @@ -783,8 +782,8 @@ describe Chef::Provider::SystemdUnit do context "when a user is specified" do it "reload-or-try-restarts the unit" do current_resource.user(user_name) - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --user reload-or-try-restart #{unit_name_escaped}", **user_cmd_opts, default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--user", "reload-or-try-restart", unit_name, **user_cmd_opts, default_env: false) .and_return(shell_out_success) provider.action_reload_or_try_restart end @@ -792,8 +791,8 @@ describe Chef::Provider::SystemdUnit do context "when no user is specified" do it "reload-or-try-restarts the unit" do - expect(provider).to receive(:shell_out!) - .with("#{systemctl_path} --system reload-or-try-restart #{unit_name_escaped}", default_env: false) + expect(provider).to receive(:shell_out_compacted!) + .with(systemctl_path, "--system", "reload-or-try-restart", unit_name, default_env: false) .and_return(shell_out_success) provider.action_reload_or_try_restart end @@ -809,16 +808,16 @@ describe Chef::Provider::SystemdUnit do context "when a user is specified" do it "returns true when unit is active" do current_resource.user(user_name) - expect(provider).to receive(:shell_out) - .with("#{systemctl_path} --user is-active #{unit_name_escaped}", user_cmd_opts) + expect(provider).to receive(:shell_out_compacted) + .with(systemctl_path, "--user", "is-active", unit_name, user_cmd_opts) .and_return(shell_out_success) expect(provider.active?).to be true end it "returns false when unit is inactive" do current_resource.user(user_name) - expect(provider).to receive(:shell_out) - .with("#{systemctl_path} --user is-active #{unit_name_escaped}", user_cmd_opts) + expect(provider).to receive(:shell_out_compacted) + .with(systemctl_path, "--user", "is-active", unit_name, user_cmd_opts) .and_return(shell_out_failure) expect(provider.active?).to be false end @@ -826,15 +825,15 @@ describe Chef::Provider::SystemdUnit do context "when no user is specified" do it "returns true when unit is active" do - expect(provider).to receive(:shell_out) - .with("#{systemctl_path} --system is-active #{unit_name_escaped}", {}) + expect(provider).to receive(:shell_out_compacted) + .with(systemctl_path, "--system", "is-active", unit_name) .and_return(shell_out_success) expect(provider.active?).to be true end it "returns false when unit is not active" do - expect(provider).to receive(:shell_out) - .with("#{systemctl_path} --system is-active #{unit_name_escaped}", {}) + expect(provider).to receive(:shell_out_compacted) + .with(systemctl_path, "--system", "is-active", unit_name) .and_return(shell_out_failure) expect(provider.active?).to be false end @@ -850,16 +849,16 @@ describe Chef::Provider::SystemdUnit do context "when a user is specified" do it "returns true when unit is enabled" do current_resource.user(user_name) - expect(provider).to receive(:shell_out) - .with("#{systemctl_path} --user is-enabled #{unit_name_escaped}", user_cmd_opts) + expect(provider).to receive(:shell_out_compacted) + .with(systemctl_path, "--user", "is-enabled", unit_name, user_cmd_opts) .and_return(shell_out_success) expect(provider.enabled?).to be true end it "returns false when unit is not enabled" do current_resource.user(user_name) - expect(provider).to receive(:shell_out) - .with("#{systemctl_path} --user is-enabled #{unit_name_escaped}", user_cmd_opts) + expect(provider).to receive(:shell_out_compacted) + .with(systemctl_path, "--user", "is-enabled", unit_name, user_cmd_opts) .and_return(shell_out_failure) expect(provider.enabled?).to be false end @@ -867,15 +866,15 @@ describe Chef::Provider::SystemdUnit do context "when no user is specified" do it "returns true when unit is enabled" do - expect(provider).to receive(:shell_out) - .with("#{systemctl_path} --system is-enabled #{unit_name_escaped}", {}) + expect(provider).to receive(:shell_out_compacted) + .with(systemctl_path, "--system", "is-enabled", unit_name) .and_return(shell_out_success) expect(provider.enabled?).to be true end it "returns false when unit is not enabled" do - expect(provider).to receive(:shell_out) - .with("#{systemctl_path} --system is-enabled #{unit_name_escaped}", {}) + expect(provider).to receive(:shell_out_compacted) + .with(systemctl_path, "--system", "is-enabled", unit_name) .and_return(shell_out_failure) expect(provider.enabled?).to be false end @@ -891,16 +890,16 @@ describe Chef::Provider::SystemdUnit do context "when a user is specified" do it "returns true when the unit is masked" do current_resource.user(user_name) - expect(provider).to receive(:shell_out) - .with("#{systemctl_path} --user status #{unit_name_escaped}", user_cmd_opts) + expect(provider).to receive(:shell_out_compacted) + .with(systemctl_path, "--user", "status", unit_name, user_cmd_opts) .and_return(shell_out_masked) expect(provider.masked?).to be true end it "returns false when the unit is not masked" do current_resource.user(user_name) - expect(provider).to receive(:shell_out) - .with("#{systemctl_path} --user status #{unit_name_escaped}", user_cmd_opts) + expect(provider).to receive(:shell_out_compacted) + .with(systemctl_path, "--user", "status", unit_name, user_cmd_opts) .and_return(shell_out_static) expect(provider.masked?).to be false end @@ -908,15 +907,15 @@ describe Chef::Provider::SystemdUnit do context "when no user is specified" do it "returns true when the unit is masked" do - expect(provider).to receive(:shell_out) - .with("#{systemctl_path} --system status #{unit_name_escaped}", {}) + expect(provider).to receive(:shell_out_compacted) + .with(systemctl_path, "--system", "status", unit_name) .and_return(shell_out_masked) expect(provider.masked?).to be true end it "returns false when the unit is not masked" do - expect(provider).to receive(:shell_out) - .with("#{systemctl_path} --system status #{unit_name_escaped}", {}) + expect(provider).to receive(:shell_out_compacted) + .with(systemctl_path, "--system", "status", unit_name) .and_return(shell_out_static) expect(provider.masked?).to be false end @@ -932,16 +931,16 @@ describe Chef::Provider::SystemdUnit do context "when a user is specified" do it "returns true when the unit is static" do current_resource.user(user_name) - expect(provider).to receive(:shell_out) - .with("#{systemctl_path} --user is-enabled #{unit_name_escaped}", user_cmd_opts) + expect(provider).to receive(:shell_out_compacted) + .with(systemctl_path, "--user", "is-enabled", unit_name, user_cmd_opts) .and_return(shell_out_static) expect(provider.static?).to be true end it "returns false when the unit is not static" do current_resource.user(user_name) - expect(provider).to receive(:shell_out) - .with("#{systemctl_path} --user is-enabled #{unit_name_escaped}", user_cmd_opts) + expect(provider).to receive(:shell_out_compacted) + .with(systemctl_path, "--user", "is-enabled", unit_name, user_cmd_opts) .and_return(shell_out_masked) expect(provider.static?).to be false end @@ -949,15 +948,15 @@ describe Chef::Provider::SystemdUnit do context "when no user is specified" do it "returns true when the unit is static" do - expect(provider).to receive(:shell_out) - .with("#{systemctl_path} --system is-enabled #{unit_name_escaped}", {}) + expect(provider).to receive(:shell_out_compacted) + .with(systemctl_path, "--system", "is-enabled", unit_name) .and_return(shell_out_static) expect(provider.static?).to be true end it "returns false when the unit is not static" do - expect(provider).to receive(:shell_out) - .with("#{systemctl_path} --system is-enabled #{unit_name_escaped}", {}) + expect(provider).to receive(:shell_out_compacted) + .with(systemctl_path, "--system", "is-enabled", unit_name) .and_return(shell_out_masked) expect(provider.static?).to be false end |