diff options
author | Bryan McLellan <btm@loftninjas.org> | 2019-04-10 10:49:34 -0400 |
---|---|---|
committer | Bryan McLellan <btm@loftninjas.org> | 2019-04-11 14:44:16 -0400 |
commit | f8d1127a41d91dea3b05ff3080c5400933dd5344 (patch) | |
tree | cb1cd63c2ef72faee1fa5de6d1aebf6824a2429d | |
parent | 6df07f8b55d2e56288f8b1c0ff60a048ce376c74 (diff) | |
download | chef-f8d1127a41d91dea3b05ff3080c5400933dd5344.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>
-rw-r--r-- | spec/functional/resource/group_spec.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/spec/functional/resource/group_spec.rb b/spec/functional/resource/group_spec.rb index 94f00185c4..efa089ca2e 100644 --- a/spec/functional/resource/group_spec.rb +++ b/spec/functional/resource/group_spec.rb @@ -292,7 +292,18 @@ describe Chef::Resource::Group, :requires_root_or_running_windows do end end - let(:number) { rand(2000..9999) } # avoid low group numbers + 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) { [] } |