summaryrefslogtreecommitdiff
path: root/spec/unit/provider
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-12-21 13:36:16 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2016-12-21 13:36:16 -0800
commitd5517ce1e766c096dde16e5c8a10732ee346c5dc (patch)
tree70d8ecf73c8b782cb09ef527c0ec66f1b3787ad1 /spec/unit/provider
parent81e4f3ee85fc4e9bef11c3468dcd1cb8d30f4cea (diff)
downloadchef-d5517ce1e766c096dde16e5c8a10732ee346c5dc.tar.gz
cleanup of group providerlcg/group-provider-cleanup
- consistent use of shell_out_compact! - remove more uses of run_command - some other code cleanup Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'spec/unit/provider')
-rw-r--r--spec/unit/provider/group/dscl_spec.rb16
-rw-r--r--spec/unit/provider/group/gpasswd_spec.rb20
-rw-r--r--spec/unit/provider/group/groupadd_spec.rb16
-rw-r--r--spec/unit/provider/group/groupmod_spec.rb32
-rw-r--r--spec/unit/provider/group/pw_spec.rb22
-rw-r--r--spec/unit/provider/group/suse_spec.rb10
-rw-r--r--spec/unit/provider/group/usermod_spec.rb30
7 files changed, 73 insertions, 73 deletions
diff --git a/spec/unit/provider/group/dscl_spec.rb b/spec/unit/provider/group/dscl_spec.rb
index bc69d7580e..9dc969c352 100644
--- a/spec/unit/provider/group/dscl_spec.rb
+++ b/spec/unit/provider/group/dscl_spec.rb
@@ -28,12 +28,12 @@ describe Chef::Provider::Group::Dscl do
@provider = Chef::Provider::Group::Dscl.new(@new_resource, @run_context)
@provider.current_resource = @current_resource
- @status = double(:stdout => "\n", :stderr => "", :exitstatus => 0)
+ @status = double(stdout: "\n", stderr: "", exitstatus: 0)
allow(@provider).to receive(:shell_out).and_return(@status)
end
it "should run shell_out with the supplied array of arguments appended to the dscl command" do
- expect(@provider).to receive(:shell_out).with("dscl . -cmd /Path arg1 arg2")
+ expect(@provider).to receive(:shell_out).with("dscl", ".", "-cmd", "/Path", "arg1", "arg2")
@provider.dscl("cmd", "/Path", "arg1", "arg2")
end
@@ -57,7 +57,7 @@ describe Chef::Provider::Group::Dscl do
describe "with the dscl command returning a non zero exit status for a delete" do
before do
- @status = double("Process::Status", :exitstatus => 1)
+ @status = double("Process::Status", exitstatus: 1)
allow(@provider).to receive(:dscl).and_return(["cmd", @status, "stdout", "stderr"])
end
@@ -232,20 +232,20 @@ describe Chef::Provider::Group::Dscl do
end
describe "when loading the current system state" do
- before (:each) do
+ before(:each) do
@provider.action = :create
@provider.load_current_resource
@provider.define_resource_requirements
end
it "raises an error if the required binary /usr/bin/dscl doesn't exist" do
- expect(File).to receive(:exists?).with("/usr/bin/dscl").and_return(false)
+ expect(File).to receive(:exist?).with("/usr/bin/dscl").and_return(false)
expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group)
end
it "doesn't raise an error if /usr/bin/dscl exists" do
- allow(File).to receive(:exists?).and_return(true)
+ allow(File).to receive(:exist?).and_return(true)
expect { @provider.process_resource_requirements }.not_to raise_error
end
end
@@ -321,11 +321,11 @@ EOF
end
it "should parse gid properly" do
- allow(File).to receive(:exists?).and_return(true)
+ allow(File).to receive(:exist?).and_return(true)
expect(@current_resource.gid).to eq("999")
end
it "should parse members properly" do
- allow(File).to receive(:exists?).and_return(true)
+ allow(File).to receive(:exist?).and_return(true)
expect(@current_resource.members).to eq(%w{waka bar})
end
end
diff --git a/spec/unit/provider/group/gpasswd_spec.rb b/spec/unit/provider/group/gpasswd_spec.rb
index 16e6ad15ea..add87bf008 100644
--- a/spec/unit/provider/group/gpasswd_spec.rb
+++ b/spec/unit/provider/group/gpasswd_spec.rb
@@ -27,11 +27,11 @@ describe Chef::Provider::Group::Gpasswd, "modify_group_members" do
@new_resource.members %w{lobster rage fist}
@new_resource.append false
@provider = Chef::Provider::Group::Gpasswd.new(@new_resource, @run_context)
- #@provider.stub(:run_command).and_return(true)
+ # @provider.stub(:run_command).and_return(true)
end
describe "when determining the current group state" do
- before (:each) do
+ before(:each) do
@provider.action = :create
@provider.load_current_resource
@provider.define_resource_requirements
@@ -41,13 +41,13 @@ describe Chef::Provider::Group::Gpasswd, "modify_group_members" do
# for Chef::Provider::Group - no need to repeat it here. We'll
# include only what's specific to this provider.
it "should raise an error if the required binary /usr/bin/gpasswd doesn't exist" do
- allow(File).to receive(:exists?).and_return(true)
- expect(File).to receive(:exists?).with("/usr/bin/gpasswd").and_return(false)
+ allow(File).to receive(:exist?).and_return(true)
+ expect(File).to receive(:exist?).with("/usr/bin/gpasswd").and_return(false)
expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group)
end
it "shouldn't raise an error if the required binaries exist" do
- allow(File).to receive(:exists?).and_return(true)
+ allow(File).to receive(:exist?).and_return(true)
expect { @provider.process_resource_requirements }.not_to raise_error
end
end
@@ -66,7 +66,7 @@ describe Chef::Provider::Group::Gpasswd, "modify_group_members" do
it "logs a message and sets group's members to 'none'" do
expect(Chef::Log).to receive(:debug).with("group[wheel] setting group members to: none")
- expect(@provider).to receive(:shell_out!).with("gpasswd -M \"\" wheel")
+ expect(@provider).to receive(:shell_out!).with("gpasswd", "-M", "", "wheel")
@provider.modify_group_members
end
end
@@ -91,7 +91,7 @@ describe Chef::Provider::Group::Gpasswd, "modify_group_members" do
end
it "should run gpasswd with the members joined by ',' followed by the target group" do
- expect(@provider).to receive(:shell_out!).with("gpasswd -M lobster,rage,fist wheel")
+ expect(@provider).to receive(:shell_out!).with("gpasswd", "-M", "lobster,rage,fist", "wheel")
@provider.modify_group_members
end
@@ -104,9 +104,9 @@ describe Chef::Provider::Group::Gpasswd, "modify_group_members" do
it "should run gpasswd individually for each user when the append option is set" do
@new_resource.append(true)
- expect(@provider).to receive(:shell_out!).with("gpasswd -a lobster wheel")
- expect(@provider).to receive(:shell_out!).with("gpasswd -a rage wheel")
- expect(@provider).to receive(:shell_out!).with("gpasswd -a fist wheel")
+ expect(@provider).to receive(:shell_out!).with("gpasswd", "-a", "lobster", "wheel")
+ expect(@provider).to receive(:shell_out!).with("gpasswd", "-a", "rage", "wheel")
+ expect(@provider).to receive(:shell_out!).with("gpasswd", "-a", "fist", "wheel")
@provider.modify_group_members
end
end
diff --git a/spec/unit/provider/group/groupadd_spec.rb b/spec/unit/provider/group/groupadd_spec.rb
index 70a98ff2f5..929dd00450 100644
--- a/spec/unit/provider/group/groupadd_spec.rb
+++ b/spec/unit/provider/group/groupadd_spec.rb
@@ -46,7 +46,7 @@ describe Chef::Provider::Group::Groupadd do
describe "#set_options" do
field_list = {
- :gid => "-g",
+ gid: "-g",
}
field_list.each do |attribute, option|
@@ -168,25 +168,25 @@ describe Chef::Provider::Group::Groupadd do
end
before do
- allow(File).to receive(:exists?).and_return(false)
+ allow(File).to receive(:exist?).and_return(false)
provider.define_resource_requirements
end
it "should raise an error if the required binary /usr/sbin/groupadd doesn't exist" do
- expect(File).to receive(:exists?).with("/usr/sbin/groupadd").and_return(false)
+ expect(File).to receive(:exist?).with("/usr/sbin/groupadd").and_return(false)
expect { provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group)
end
it "should raise an error if the required binary /usr/sbin/groupmod doesn't exist" do
- expect(File).to receive(:exists?).with("/usr/sbin/groupadd").and_return(true)
- expect(File).to receive(:exists?).with("/usr/sbin/groupmod").and_return(false)
+ expect(File).to receive(:exist?).with("/usr/sbin/groupadd").and_return(true)
+ expect(File).to receive(:exist?).with("/usr/sbin/groupmod").and_return(false)
expect { provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group)
end
it "should raise an error if the required binary /usr/sbin/groupdel doesn't exist" do
- expect(File).to receive(:exists?).with("/usr/sbin/groupadd").and_return(true)
- expect(File).to receive(:exists?).with("/usr/sbin/groupmod").and_return(true)
- expect(File).to receive(:exists?).with("/usr/sbin/groupdel").and_return(false)
+ expect(File).to receive(:exist?).with("/usr/sbin/groupadd").and_return(true)
+ expect(File).to receive(:exist?).with("/usr/sbin/groupmod").and_return(true)
+ expect(File).to receive(:exist?).with("/usr/sbin/groupdel").and_return(false)
expect { provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group)
end
diff --git a/spec/unit/provider/group/groupmod_spec.rb b/spec/unit/provider/group/groupmod_spec.rb
index 21d026409e..6629b718d0 100644
--- a/spec/unit/provider/group/groupmod_spec.rb
+++ b/spec/unit/provider/group/groupmod_spec.rb
@@ -33,17 +33,17 @@ describe Chef::Provider::Group::Groupmod do
describe "manage_group" do
describe "when determining the current group state" do
it "should raise an error if the required binary /usr/sbin/group doesn't exist" do
- expect(File).to receive(:exists?).with("/usr/sbin/group").and_return(false)
+ expect(File).to receive(:exist?).with("/usr/sbin/group").and_return(false)
expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Group)
end
it "should raise an error if the required binary /usr/sbin/user doesn't exist" do
- expect(File).to receive(:exists?).with("/usr/sbin/group").and_return(true)
- expect(File).to receive(:exists?).with("/usr/sbin/user").and_return(false)
+ expect(File).to receive(:exist?).with("/usr/sbin/group").and_return(true)
+ expect(File).to receive(:exist?).with("/usr/sbin/user").and_return(false)
expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Group)
end
it "shouldn't raise an error if the required binaries exist" do
- allow(File).to receive(:exists?).and_return(true)
+ allow(File).to receive(:exist?).and_return(true)
expect { @provider.load_current_resource }.not_to raise_error
end
end
@@ -62,9 +62,9 @@ describe Chef::Provider::Group::Groupmod do
it "logs a message and sets group's members to 'none', then removes existing group members" do
expect(Chef::Log).to receive(:debug).with("group[wheel] setting group members to: none")
- expect(@provider).to receive(:shell_out!).with("group mod -n wheel_bak wheel")
- expect(@provider).to receive(:shell_out!).with("group add -g '123' -o wheel")
- expect(@provider).to receive(:shell_out!).with("group del wheel_bak")
+ expect(@provider).to receive(:shell_out!).with("group", "mod", "-n", "wheel_bak", "wheel")
+ expect(@provider).to receive(:shell_out!).with("group", "add", "-g", "123", "-o", "wheel")
+ expect(@provider).to receive(:shell_out!).with("group", "del", "wheel_bak")
@provider.manage_group
end
end
@@ -90,10 +90,10 @@ describe Chef::Provider::Group::Groupmod do
it "updates group membership correctly" do
allow(Chef::Log).to receive(:debug)
- expect(@provider).to receive(:shell_out!).with("group mod -n wheel_bak wheel")
- expect(@provider).to receive(:shell_out!).with("user mod -G wheel lobster")
- expect(@provider).to receive(:shell_out!).with("group add -g '123' -o wheel")
- expect(@provider).to receive(:shell_out!).with("group del wheel_bak")
+ expect(@provider).to receive(:shell_out!).with("group", "mod", "-n", "wheel_bak", "wheel")
+ expect(@provider).to receive(:shell_out!).with("user", "mod", "-G", "wheel", "lobster")
+ expect(@provider).to receive(:shell_out!).with("group", "add", "-g", "123", "-o", "wheel")
+ expect(@provider).to receive(:shell_out!).with("group", "del", "wheel_bak")
@provider.manage_group
end
end
@@ -108,10 +108,10 @@ describe Chef::Provider::Group::Groupmod do
end
it "should run a group add command and some user mod commands" do
- expect(@provider).to receive(:shell_out!).with("group add -g '123' wheel")
- expect(@provider).to receive(:shell_out!).with("user mod -G wheel lobster")
- expect(@provider).to receive(:shell_out!).with("user mod -G wheel rage")
- expect(@provider).to receive(:shell_out!).with("user mod -G wheel fist")
+ expect(@provider).to receive(:shell_out!).with("group", "add", "-g", "123", "wheel")
+ expect(@provider).to receive(:shell_out!).with("user", "mod", "-G", "wheel", "lobster")
+ expect(@provider).to receive(:shell_out!).with("user", "mod", "-G", "wheel", "rage")
+ expect(@provider).to receive(:shell_out!).with("user", "mod", "-G", "wheel", "fist")
@provider.create_group
end
end
@@ -125,7 +125,7 @@ describe Chef::Provider::Group::Groupmod do
end
it "should run a group del command" do
- expect(@provider).to receive(:shell_out!).with("group del wheel")
+ expect(@provider).to receive(:shell_out!).with("group", "del", "wheel")
@provider.remove_group
end
end
diff --git a/spec/unit/provider/group/pw_spec.rb b/spec/unit/provider/group/pw_spec.rb
index 97ffcb3c31..f109ba6ba1 100644
--- a/spec/unit/provider/group/pw_spec.rb
+++ b/spec/unit/provider/group/pw_spec.rb
@@ -37,19 +37,19 @@ describe Chef::Provider::Group::Pw do
describe "when setting options for the pw command" do
it "does not set the gid option if gids match or are unmanaged" do
- expect(@provider.set_options).to eq(" wheel")
+ expect(@provider.set_options).to eq(["wheel"])
end
it "sets the option for gid if it is not nil" do
@new_resource.gid(42)
- expect(@provider.set_options).to eql(" wheel -g '42'")
+ expect(@provider.set_options).to eql(["wheel", "-g", 42])
end
end
describe "when creating a group" do
it "should run pw groupadd with the return of set_options and set_members_option" do
@new_resource.gid(23)
- expect(@provider).to receive(:run_command).with({ :command => "pw groupadd wheel -g '23' -M root,aj" }).and_return(true)
+ expect(@provider).to receive(:shell_out!).with("pw", "groupadd", "wheel", "-g", "23", "-M", "root,aj").and_return(true)
@provider.create_group
end
end
@@ -59,8 +59,8 @@ describe Chef::Provider::Group::Pw do
it "should run pw groupmod with the return of set_options" do
@new_resource.gid(42)
@new_resource.members(["someone"])
- expect(@provider).to receive(:run_command).with({ :command => "pw groupmod wheel -g '42' -m someone" }).and_return(true)
- expect(@provider).to receive(:run_command).with({ :command => "pw groupmod wheel -g '42' -d root,aj" }).and_return(true)
+ expect(@provider).to receive(:shell_out!).with("pw", "groupmod", "wheel", "-g", "42", "-m", "someone").and_return(true)
+ expect(@provider).to receive(:shell_out!).with("pw", "groupmod", "wheel", "-g", "42", "-d", "root,aj").and_return(true)
@provider.manage_group
end
@@ -68,7 +68,7 @@ describe Chef::Provider::Group::Pw do
describe "when removing the group" do
it "should run pw groupdel with the new resources group name" do
- expect(@provider).to receive(:run_command).with({ :command => "pw groupdel wheel" }).and_return(true)
+ expect(@provider).to receive(:shell_out!).with("pw", "groupdel", "wheel").and_return(true)
@provider.remove_group
end
end
@@ -98,7 +98,7 @@ describe Chef::Provider::Group::Pw do
end
it "should set the -d option with the members joined by ','" do
- expect(@provider.set_members_options).to eql([ " -d all,your,base" ])
+ expect(@provider.set_members_options).to eql([ ["-d", "all,your,base"] ])
end
end
@@ -114,24 +114,24 @@ describe Chef::Provider::Group::Pw do
end
it "should set the -m option with the members joined by ','" do
- expect(@provider.set_members_options).to eql([ " -m all,your,base" ])
+ expect(@provider.set_members_options).to eql([[ "-m", "all,your,base" ]])
end
end
end
describe "load_current_resource" do
- before (:each) do
+ before(:each) do
@provider.action = :create
@provider.load_current_resource
@provider.define_resource_requirements
end
it "should raise an error if the required binary /usr/sbin/pw doesn't exist" do
- expect(File).to receive(:exists?).with("/usr/sbin/pw").and_return(false)
+ expect(File).to receive(:exist?).with("/usr/sbin/pw").and_return(false)
expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group)
end
it "shouldn't raise an error if /usr/sbin/pw exists" do
- allow(File).to receive(:exists?).and_return(true)
+ allow(File).to receive(:exist?).and_return(true)
expect { @provider.process_resource_requirements }.not_to raise_error
end
end
diff --git a/spec/unit/provider/group/suse_spec.rb b/spec/unit/provider/group/suse_spec.rb
index da4e8e9155..e61d865b6d 100644
--- a/spec/unit/provider/group/suse_spec.rb
+++ b/spec/unit/provider/group/suse_spec.rb
@@ -7,7 +7,7 @@
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
-#     http://www.apache.org/licenses/LICENSE-2.0
+#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -47,7 +47,7 @@ describe Chef::Provider::Group::Suse do
describe "when determining the current group state" do
before(:each) do
- allow(File).to receive(:exists?).and_return(true)
+ allow(File).to receive(:exist?).and_return(true)
provider.action = :create
provider.define_resource_requirements
end
@@ -56,7 +56,7 @@ describe Chef::Provider::Group::Suse do
# for Chef::Provider::Group - no need to repeat it here. We'll
# include only what's specific to this provider.
it "should raise an error if the required binary /usr/sbin/groupmod doesn't exist" do
- expect(File).to receive(:exists?).with("/usr/sbin/groupmod").and_return(false)
+ expect(File).to receive(:exist?).with("/usr/sbin/groupmod").and_return(false)
expect { provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group)
end
@@ -76,14 +76,14 @@ describe Chef::Provider::Group::Suse do
describe "#add_member" do
it "should call out to groupmod to add user" do
- expect(provider).to receive(:shell_out!).with("groupmod -A new_user new_group")
+ expect(provider).to receive(:shell_out!).with("groupmod", "-A", "new_user", "new_group")
provider.add_member("new_user")
end
end
describe "#remove_member" do
it "should call out to groupmod to remove user" do
- expect(provider).to receive(:shell_out!).with("groupmod -R new_user new_group")
+ expect(provider).to receive(:shell_out!).with("groupmod", "-R", "new_user", "new_group")
provider.remove_member("new_user")
end
end
diff --git a/spec/unit/provider/group/usermod_spec.rb b/spec/unit/provider/group/usermod_spec.rb
index 7bd45c4f1b..c6422b12c9 100644
--- a/spec/unit/provider/group/usermod_spec.rb
+++ b/spec/unit/provider/group/usermod_spec.rb
@@ -46,18 +46,18 @@ describe Chef::Provider::Group::Usermod do
describe "with supplied members" do
platforms = {
- "openbsd" => "-G",
- "netbsd" => "-G",
- "solaris" => "-a -G",
- "suse" => "-a -G",
- "opensuse" => "-a -G",
- "smartos" => "-G",
- "omnios" => "-G",
+ "openbsd" => [ "-G" ],
+ "netbsd" => [ "-G" ],
+ "solaris" => [ "-a", "-G" ],
+ "suse" => [ "-a", "-G" ],
+ "opensuse" => [ "-a", "-G" ],
+ "smartos" => [ "-G" ],
+ "omnios" => [ "-G" ],
}
before do
allow(@new_resource).to receive(:members).and_return(%w{all your base})
- allow(File).to receive(:exists?).and_return(true)
+ allow(File).to receive(:exist?).and_return(true)
end
it "should raise an error when setting the entire group directly" do
@@ -85,9 +85,9 @@ describe Chef::Provider::Group::Usermod do
@provider.current_resource = current_resource
@node.automatic_attrs[:platform] = platform
allow(@new_resource).to receive(:append).and_return(true)
- expect(@provider).to receive(:shell_out!).with("usermod #{flags} wheel all")
- expect(@provider).to receive(:shell_out!).with("usermod #{flags} wheel your")
- expect(@provider).to receive(:shell_out!).with("usermod #{flags} wheel base")
+ expect(@provider).to receive(:shell_out!).with("usermod", *flags, "wheel", "all")
+ expect(@provider).to receive(:shell_out!).with("usermod", *flags, "wheel", "your")
+ expect(@provider).to receive(:shell_out!).with("usermod", *flags, "wheel", "base")
@provider.modify_group_members
end
end
@@ -96,19 +96,19 @@ describe Chef::Provider::Group::Usermod do
describe "when loading the current resource" do
before(:each) do
- allow(File).to receive(:exists?).and_return(false)
+ allow(File).to receive(:exist?).and_return(false)
@provider.action = :create
@provider.define_resource_requirements
end
it "should raise an error if the required binary /usr/sbin/usermod doesn't exist" do
- allow(File).to receive(:exists?).and_return(true)
- expect(File).to receive(:exists?).with("/usr/sbin/usermod").and_return(false)
+ allow(File).to receive(:exist?).and_return(true)
+ expect(File).to receive(:exist?).with("/usr/sbin/usermod").and_return(false)
expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group)
end
it "shouldn't raise an error if the required binaries exist" do
- allow(File).to receive(:exists?).and_return(true)
+ allow(File).to receive(:exist?).and_return(true)
expect { @provider.process_resource_requirements }.not_to raise_error
end
end