Skip to content

Commit dd3df54

Browse files
committed
(PUP-11634) Rename Struct::{Group,Passwd} to Etc::{Group,Password}
Ruby 3.2 removed the deprecated Struct constant.
1 parent a94db64 commit dd3df54

File tree

6 files changed

+22
-22
lines changed

6 files changed

+22
-22
lines changed

spec/unit/provider/file/posix_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
describe "#uid2name" do
4141
it "should return the name of the user identified by the id" do
42-
allow(Etc).to receive(:getpwuid).with(501).and_return(Struct::Passwd.new('jilluser', nil, 501))
42+
allow(Etc).to receive(:getpwuid).with(501).and_return(Etc::Passwd.new('jilluser', nil, 501))
4343

4444
expect(provider.uid2name(501)).to eq('jilluser')
4545
end
@@ -61,7 +61,7 @@
6161

6262
describe "#name2uid" do
6363
it "should return the id of the user if it exists" do
64-
passwd = Struct::Passwd.new('bobbo', nil, 502)
64+
passwd = Etc::Passwd.new('bobbo', nil, 502)
6565

6666
allow(Etc).to receive(:getpwnam).with('bobbo').and_return(passwd)
6767
allow(Etc).to receive(:getpwuid).with(502).and_return(passwd)
@@ -131,7 +131,7 @@
131131

132132
describe "#gid2name" do
133133
it "should return the name of the group identified by the id" do
134-
allow(Etc).to receive(:getgrgid).with(501).and_return(Struct::Passwd.new('unicorns', nil, nil, 501))
134+
allow(Etc).to receive(:getgrgid).with(501).and_return(Etc::Passwd.new('unicorns', nil, nil, 501))
135135

136136
expect(provider.gid2name(501)).to eq('unicorns')
137137
end
@@ -153,7 +153,7 @@
153153

154154
describe "#name2gid" do
155155
it "should return the id of the group if it exists" do
156-
passwd = Struct::Passwd.new('penguins', nil, nil, 502)
156+
passwd = Etc::Passwd.new('penguins', nil, nil, 502)
157157

158158
allow(Etc).to receive(:getgrnam).with('penguins').and_return(passwd)
159159
allow(Etc).to receive(:getgrgid).with(502).and_return(passwd)

spec/unit/provider/nameservice_spec.rb

+14-14
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@ def modifycmd(param, value)
3030
# These are values getpwent might give you
3131
let :users do
3232
[
33-
Struct::Passwd.new('root', 'x', 0, 0),
34-
Struct::Passwd.new('foo', 'x', 1000, 2000),
33+
Etc::Passwd.new('root', 'x', 0, 0),
34+
Etc::Passwd.new('foo', 'x', 1000, 2000),
3535
nil
3636
]
3737
end
3838

3939
# These are values getgrent might give you
4040
let :groups do
4141
[
42-
Struct::Group.new('root', 'x', 0, %w{root}),
43-
Struct::Group.new('bin', 'x', 1, %w{root bin daemon}),
42+
Etc::Group.new('root', 'x', 0, %w{root}),
43+
Etc::Group.new('bin', 'x', 1, %w{root bin daemon}),
4444
nil
4545
]
4646
end
4747

48-
# A fake struct besides Struct::Group and Struct::Passwd
48+
# A fake struct besides Etc::Group and Etc::Passwd
4949
let :fakestruct do
5050
Struct.new(:foo, :bar)
5151
end
@@ -82,22 +82,22 @@ def modifycmd(param, value)
8282

8383
let(:utf_8_mixed_users) {
8484
[
85-
Struct::Passwd.new('root', 'x', 0, 0),
86-
Struct::Passwd.new('foo', 'x', 1000, 2000),
87-
Struct::Passwd.new(utf_8_jose, utf_8_jose, 1001, 2000), # UTF-8 character
85+
Etc::Passwd.new('root', 'x', 0, 0),
86+
Etc::Passwd.new('foo', 'x', 1000, 2000),
87+
Etc::Passwd.new(utf_8_jose, utf_8_jose, 1001, 2000), # UTF-8 character
8888
# In a UTF-8 environment, ruby will return strings labeled as UTF-8 even if they're not valid in UTF-8
89-
Struct::Passwd.new(invalid_utf_8_jose, invalid_utf_8_jose, 1002, 2000),
89+
Etc::Passwd.new(invalid_utf_8_jose, invalid_utf_8_jose, 1002, 2000),
9090
nil
9191
]
9292
}
9393

9494
let(:latin_1_mixed_users) {
9595
[
9696
# In a LATIN-1 environment, ruby will return *all* strings labeled as LATIN-1
97-
Struct::Passwd.new('root'.force_encoding(Encoding::ISO_8859_1), 'x', 0, 0),
98-
Struct::Passwd.new('foo'.force_encoding(Encoding::ISO_8859_1), 'x', 1000, 2000),
99-
Struct::Passwd.new(utf_8_labeled_as_latin_1_jose, utf_8_labeled_as_latin_1_jose, 1002, 2000),
100-
Struct::Passwd.new(valid_latin1_jose, valid_latin1_jose, 1001, 2000), # UTF-8 character
97+
Etc::Passwd.new('root'.force_encoding(Encoding::ISO_8859_1), 'x', 0, 0),
98+
Etc::Passwd.new('foo'.force_encoding(Encoding::ISO_8859_1), 'x', 1000, 2000),
99+
Etc::Passwd.new(utf_8_labeled_as_latin_1_jose, utf_8_labeled_as_latin_1_jose, 1002, 2000),
100+
Etc::Passwd.new(valid_latin1_jose, valid_latin1_jose, 1001, 2000), # UTF-8 character
101101
nil
102102
]
103103
}
@@ -197,7 +197,7 @@ def modifycmd(param, value)
197197
end
198198

199199
it "should pass the Puppet::Etc :canonical_name Struct member to the constructor" do
200-
users = [ Struct::Passwd.new(invalid_utf_8_jose, invalid_utf_8_jose, 1002, 2000), nil ]
200+
users = [ Etc::Passwd.new(invalid_utf_8_jose, invalid_utf_8_jose, 1002, 2000), nil ]
201201
allow(Etc).to receive(:getpwent).and_return(*users)
202202
expect(provider.class).to receive(:new).with({:name => escaped_utf_8_jose, :canonical_name => invalid_utf_8_jose, :ensure => :present})
203203
provider.class.instances

spec/unit/provider/user/hpux_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
context "managing passwords" do
2929
let :pwent do
30-
Struct::Passwd.new("testuser", "foopassword")
30+
Etc::Passwd.new("testuser", "foopassword")
3131
end
3232

3333
before :each do

spec/unit/provider/user/openbsd_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
let(:shadow_entry) {
2424
return unless Puppet.features.libshadow?
25-
entry = Struct::PasswdEntry.new
25+
entry = Etc::PasswdEntry.new
2626
entry[:sp_namp] = 'myuser' # login name
2727
entry[:sp_loginclass] = 'staff' # login class
2828
entry

spec/unit/provider/user/useradd_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
let(:shadow_entry) {
3131
return unless Puppet.features.libshadow?
32-
entry = Struct::PasswdEntry.new
32+
entry = Etc::PasswdEntry.new
3333
entry[:sp_namp] = 'myuser' # login name
3434
entry[:sp_pwdp] = '$6$FvW8Ib8h$qQMI/CR9m.QzIicZKutLpBgCBBdrch1IX0rTnxuI32K1pD9.RXZrmeKQlaC.RzODNuoUtPPIyQDufunvLOQWF0' # encrypted password
3535
entry[:sp_lstchg] = 15573 # date of last password change

spec/unit/type/exec_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def exec_stub(options = {})
295295

296296
it "accepts the current user" do
297297
allow(Puppet.features).to receive(:root?).and_return(false)
298-
allow(Etc).to receive(:getpwuid).and_return(Struct::Passwd.new('input'))
298+
allow(Etc).to receive(:getpwuid).and_return(Etc::Passwd.new('input'))
299299

300300
type = Puppet::Type.type(:exec).new(:name => '/bin/true whatever', :user => 'input')
301301

0 commit comments

Comments
 (0)