diff options
author | Tim Smith <tsmith@chef.io> | 2018-07-17 13:05:46 -0700 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2018-07-17 13:05:46 -0700 |
commit | 49ff30d16b8551a9814bd9e1cb96b9f50b891698 (patch) | |
tree | cb683f5134882d02e69e24794ecb8632b182da0a | |
parent | c04fcdff7faedcc3e291d24aa6db8078cb9b8af6 (diff) | |
download | chef-group_properties.tar.gz |
Improve comma separated list splitting in group resourcegroup_properties
This is the same thing I did in sudo. It just makes the string parsing a bit more user spacing proof.
accepted before:
- 1,2,3
accepted now:
- 1,2,3
- 1, 2, 3
- 1 ,2 ,3
- any combo of the above 3
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/chef/resource/group.rb | 6 | ||||
-rw-r--r-- | spec/unit/resource/group_spec.rb | 32 |
2 files changed, 19 insertions, 19 deletions
diff --git a/lib/chef/resource/group.rb b/lib/chef/resource/group.rb index 63e376d34f..fc2c33322b 100644 --- a/lib/chef/resource/group.rb +++ b/lib/chef/resource/group.rb @@ -1,7 +1,7 @@ # # Author:: Adam Jacob (<adam@chef.io>) # Author:: Tyler Cloke (<tyler@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"); @@ -35,11 +35,11 @@ class Chef description: "The identifier for the group." property :members, [String, Array], default: lazy { [] }, - coerce: proc { |x| x.kind_of?(String) ? x.split(",") : x }, + coerce: proc { |arg| arg.is_a?(String) ? arg.split(/\s*,\s*/) : arg }, description: "Which users should be set or appended to a group. This can be either an array or a comma separated list." property :excluded_members, [String, Array], default: lazy { [] }, - coerce: proc { |x| x.kind_of?(String) ? x.split(",") : x }, + coerce: proc { |arg| arg.is_a?(String) ? arg.split(/\s*,\s*/) : arg }, description: "Remove users from a group. May only be used when append is set to true." property :append, [ TrueClass, FalseClass ], default: false, diff --git a/spec/unit/resource/group_spec.rb b/spec/unit/resource/group_spec.rb index 10bef38410..60f72b6785 100644 --- a/spec/unit/resource/group_spec.rb +++ b/spec/unit/resource/group_spec.rb @@ -1,7 +1,7 @@ # -# Author:: AJ Christensen (<aj@chef.io>) +# Author:: AJ Christensen (<aj@junglistheavy.industries>) # Author:: Tyler Cloke (<tyler@chef.io>); -# Copyright:: Copyright 2008-2017, 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"); @@ -72,7 +72,7 @@ describe Chef::Resource::Group, "group_name" do end it "does not allow a hash" do - expect { resource.send(:group_name, { aj: "is freakin awesome" }) }.to raise_error(ArgumentError) + expect { resource.send(:group_name, { some_other_user: "is freakin awesome" }) }.to raise_error(ArgumentError) end end @@ -85,7 +85,7 @@ describe Chef::Resource::Group, "gid" do end it "does not allow a hash" do - expect { resource.send(:gid, { aj: "is freakin awesome" }) }.to raise_error(ArgumentError) + expect { resource.send(:gid, { some_other_user: "is freakin awesome" }) }.to raise_error(ArgumentError) end end @@ -93,23 +93,23 @@ describe Chef::Resource::Group, "members" do let(:resource) { Chef::Resource::Group.new("fakey_fakerton") } [ :users, :members].each do |method| - it "(#{method}) allows and convert a string" do - resource.send(method, "aj") - expect(resource.send(method)).to eql(["aj"]) + it "(#{method}) allows a String and coerces it to an Array" do + resource.send(method, "some_user") + expect(resource.send(method)).to eql(["some_user"]) end - it "(#{method}) should split a string on commas" do - resource.send(method, "aj,adam") - expect(resource.send(method)).to eql( %w{aj adam} ) + it "(#{method}) coerces a comma separated list of users to an Array" do + resource.send(method, "some_user, other_user ,another_user,just_one_more_user") + expect(resource.send(method)).to eql( %w{some_user other_user another_user just_one_more_user} ) end - it "(#{method}) allows an array" do - resource.send(method, %w{aj adam}) - expect(resource.send(method)).to eql( %w{aj adam} ) + it "(#{method}) allows an Array" do + resource.send(method, %w{some_user other_user}) + expect(resource.send(method)).to eql( %w{some_user other_user} ) end - it "(#{method}) does not allow a hash" do - expect { resource.send(method, { aj: "is freakin awesome" }) }.to raise_error(ArgumentError) + it "(#{method}) does not allow a Hash" do + expect { resource.send(method, { some_user: "is freakin awesome" }) }.to raise_error(ArgumentError) end end end @@ -127,7 +127,7 @@ describe Chef::Resource::Group, "append" do end it "does not allow a hash" do - expect { resource.send(:gid, { aj: "is freakin awesome" }) }.to raise_error(ArgumentError) + expect { resource.send(:gid, { some_other_user: "is freakin awesome" }) }.to raise_error(ArgumentError) end describe "when it has members" do |