summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-12-20 16:02:14 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2016-12-20 16:02:14 -0800
commit0d1c3fcd9b866f241464219c99c2274fd5a8ca9b (patch)
tree0c2753e13aab0ff505a53e1d5715949fbee9b349 /spec
parent2628f2dd6232856af02b25c680d9a3e3e1220be5 (diff)
downloadchef-0d1c3fcd9b866f241464219c99c2274fd5a8ca9b.tar.gz
fix groupadd specs and modernize
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/provider/group/groupadd_spec.rb45
1 files changed, 23 insertions, 22 deletions
diff --git a/spec/unit/provider/group/groupadd_spec.rb b/spec/unit/provider/group/groupadd_spec.rb
index 054d953414..2afb35a03f 100644
--- a/spec/unit/provider/group/groupadd_spec.rb
+++ b/spec/unit/provider/group/groupadd_spec.rb
@@ -58,36 +58,37 @@ describe Chef::Provider::Group::Groupadd do
it "should set the option for #{attribute} if the new resources #{attribute} is not null" do
allow(new_resource).to receive(attribute).and_return("wowaweea")
- expect(provider.set_options).to eql(" #{option} '#{new_resource.send(attribute)}' #{new_resource.group_name}")
+ expect(provider.set_options).to eql([ option, "'#{new_resource.send(attribute)}'", new_resource.group_name])
end
end
it "should combine all the possible options" do
- match_string = ""
+ match_array = []
field_list.sort { |a, b| a[0] <=> b[0] }.each do |attribute, option|
allow(new_resource).to receive(attribute).and_return("hola")
- match_string << " #{option} 'hola'"
+ match_array << option
+ match_array << "'hola'"
end
- match_string << " aj"
- expect(provider.set_options).to eql(match_string)
+ match_array << "aj"
+ expect(provider.set_options).to eql(match_array)
end
describe "when we want to create a system group" do
it "should not set groupadd_options '-r' when system is false" do
new_resource.system(false)
- expect(provider.groupadd_options).not_to match(/-r/)
+ expect(provider.groupadd_options).to eq([])
end
it "should set groupadd -r if system is true" do
new_resource.system(true)
- expect(provider.groupadd_options).to eq(" -r")
+ expect(provider.groupadd_options).to eq(["-r"])
end
context "on Solaris" do
before { node.automatic["platform"] = "solaris2" }
it "should not set groupadd -r if system is true" do
new_resource.system(true)
- expect(provider.groupadd_options).not_to match(/-r/)
+ expect(provider.groupadd_options).to eql([])
end
end
end
@@ -95,26 +96,26 @@ describe Chef::Provider::Group::Groupadd do
describe "when we want to create a non_unique gid group" do
it "should not set groupadd_options '-o' when non_unique is false" do
new_resource.non_unique(false)
- expect(provider.groupadd_options).not_to match(/-o/)
+ expect(provider.groupadd_options).to eq([])
end
it "should set groupadd -o if non_unique is true" do
new_resource.non_unique(true)
- expect(provider.groupadd_options).to eq(" -o")
+ expect(provider.groupadd_options).to eq(["-o"])
end
end
end
describe "#create_group" do
before do
- allow(provider).to receive(:run_command).and_return(true)
- allow(provider).to receive(:set_options).and_return(" monkey")
- allow(provider).to receive(:groupadd_options).and_return("")
+ allow(provider).to receive(:shell_out!).and_return(true)
+ allow(provider).to receive(:set_options).and_return("monkey")
+ allow(provider).to receive(:groupadd_options).and_return([])
allow(provider).to receive(:modify_group_members).and_return(true)
end
it "should run groupadd with the return of set_options" do
- expect(provider).to receive(:run_command).with({ :command => "groupadd monkey" }).and_return(true)
+ expect(provider).to receive(:shell_out!).with("groupadd", "monkey").and_return(true)
provider.create_group
end
@@ -126,13 +127,13 @@ describe Chef::Provider::Group::Groupadd do
describe "#manage_group" do
before do
- allow(provider).to receive(:run_command).and_return(true)
- allow(provider).to receive(:set_options).and_return(" monkey")
+ allow(provider).to receive(:shell_out!).and_return(true)
+ allow(provider).to receive(:set_options).and_return("monkey")
end
it "should run groupmod with the return of set_options" do
allow(provider).to receive(:modify_group_members).and_return(true)
- expect(provider).to receive(:run_command).with({ :command => "groupmod monkey" }).and_return(true)
+ expect(provider).to receive(:shell_out!).with("groupmod", "monkey").and_return(true)
provider.manage_group
end
@@ -144,12 +145,12 @@ describe Chef::Provider::Group::Groupadd do
describe "#remove_group" do
before do
- allow(provider).to receive(:run_command).and_return(true)
- allow(provider).to receive(:set_options).and_return(" monkey")
+ allow(provider).to receive(:shell_out!).and_return(true)
+ allow(provider).to receive(:set_options).and_return("monkey")
end
it "should run groupdel with the new resources group name" do
- expect(provider).to receive(:run_command).with({ :command => "groupdel aj" }).and_return(true)
+ expect(provider).to receive(:shell_out!).with("groupdel", "aj").and_return(true)
provider.remove_group
end
end
@@ -162,8 +163,8 @@ describe Chef::Provider::Group::Groupadd do
describe "#load_current_resource" do
before do
- allow(provider).to receive(:run_command).and_return(true)
- allow(provider).to receive(:set_options).and_return(" monkey")
+ allow(provider).to receive(:shell_out!).and_return(true)
+ allow(provider).to receive(:set_options).and_return("monkey")
end
before do