diff options
author | Bryan McLellan <btm@loftninjas.org> | 2019-04-10 10:49:34 -0400 |
---|---|---|
committer | Bryan McLellan <btm@loftninjas.org> | 2019-04-12 10:26:27 -0400 |
commit | ddcc875fcd77243ea580b91be50d51aea79499ca (patch) | |
tree | efcae2c5179af24b8e931dacb48a94c54ca764e8 /spec | |
parent | d79e710d6c9166b35c3960bc444f268b202c3066 (diff) | |
download | chef-ddcc875fcd77243ea580b91be50d51aea79499ca.tar.gz |
Avoid accidentally reusing a gid in tests
Some platforms have groups in odd ranges, make sure the gid we select is
not in use.
Signed-off-by: Bryan McLellan <btm@loftninjas.org>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/functional/resource/group_spec.rb | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/spec/functional/resource/group_spec.rb b/spec/functional/resource/group_spec.rb index 2d65d69843..32bfdb0328 100644 --- a/spec/functional/resource/group_spec.rb +++ b/spec/functional/resource/group_spec.rb @@ -292,14 +292,27 @@ describe Chef::Resource::Group, :requires_root_or_running_windows do end end - let(:group_name) { "group#{SecureRandom.random_number(9999)}" } + let(:number) do + # Loop until we pick a gid that is not in use. + loop do + begin + gid = rand(2000..9999) # avoid low group numbers + return nil if Etc.getgrgid(gid).nil? # returns nil on windows + rescue ArgumentError # group does not exist + return gid + end + end + end + + let(:group_name) { "grp#{number}" } # group name should be 8 characters or less for Solaris, and possibly others + # https://community.aegirproject.org/developing/architecture/unix-group-limitations/index.html#Group_name_length_limits let(:included_members) { [] } let(:excluded_members) { [] } let(:group_resource) do group = Chef::Resource::Group.new(group_name, run_context) group.members(included_members) group.excluded_members(excluded_members) - group.gid(30000) unless ohai[:platform_family] == "mac_os_x" + group.gid(number) unless ohai[:platform_family] == "mac_os_x" group end |