summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@loftninjas.org>2019-04-10 10:49:34 -0400
committerBryan McLellan <btm@loftninjas.org>2019-04-10 16:31:48 -0400
commit9729891d13281ee1b36a836cd3011ed914f25774 (patch)
tree28590ab960131839e26493569d135e9609d3f5b2
parent6df07f8b55d2e56288f8b1c0ff60a048ce376c74 (diff)
downloadchef-btm/func-group-gid.tar.gz
Avoid accidentally reusing a gid in testsbtm/func-group-gid
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.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/spec/functional/resource/group_spec.rb b/spec/functional/resource/group_spec.rb
index 94f00185c4..bcea91c1d5 100644
--- a/spec/functional/resource/group_spec.rb
+++ b/spec/functional/resource/group_spec.rb
@@ -292,7 +292,16 @@ 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
+ 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
+
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) { [] }