summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2019-04-11 12:40:27 -0700
committerGitHub <noreply@github.com>2019-04-11 12:40:27 -0700
commit341d720cef809d73bbd54d36801feee95460986b (patch)
tree7b1e1f127ac1eb6b4d5acd5250a11da52838023e
parent0c2be39a02445ae1c0acbe1a22cd6a2c101ba385 (diff)
parentf8d1127a41d91dea3b05ff3080c5400933dd5344 (diff)
downloadchef-341d720cef809d73bbd54d36801feee95460986b.tar.gz
Merge pull request #8352 from chef/btm/func-group-gid
Avoid occasionally randomly reusing a gid in tests
-rw-r--r--spec/functional/resource/group_spec.rb13
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) { [] }