Skip to content

Commit

Permalink
(PUP-11634) Rename Struct::{Group,Passwd} to Etc::{Group,Password}
Browse files Browse the repository at this point in the history
Ruby 3.2 removed the deprecated Struct constant.
  • Loading branch information
joshcooper committed Dec 8, 2022
1 parent a94db64 commit dd3df54
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions spec/unit/provider/file/posix_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

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

expect(provider.uid2name(501)).to eq('jilluser')
end
Expand All @@ -61,7 +61,7 @@

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

allow(Etc).to receive(:getpwnam).with('bobbo').and_return(passwd)
allow(Etc).to receive(:getpwuid).with(502).and_return(passwd)
Expand Down Expand Up @@ -131,7 +131,7 @@

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

expect(provider.gid2name(501)).to eq('unicorns')
end
Expand All @@ -153,7 +153,7 @@

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

allow(Etc).to receive(:getgrnam).with('penguins').and_return(passwd)
allow(Etc).to receive(:getgrgid).with(502).and_return(passwd)
Expand Down
28 changes: 14 additions & 14 deletions spec/unit/provider/nameservice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ def modifycmd(param, value)
# These are values getpwent might give you
let :users do
[
Struct::Passwd.new('root', 'x', 0, 0),
Struct::Passwd.new('foo', 'x', 1000, 2000),
Etc::Passwd.new('root', 'x', 0, 0),
Etc::Passwd.new('foo', 'x', 1000, 2000),
nil
]
end

# These are values getgrent might give you
let :groups do
[
Struct::Group.new('root', 'x', 0, %w{root}),
Struct::Group.new('bin', 'x', 1, %w{root bin daemon}),
Etc::Group.new('root', 'x', 0, %w{root}),
Etc::Group.new('bin', 'x', 1, %w{root bin daemon}),
nil
]
end

# A fake struct besides Struct::Group and Struct::Passwd
# A fake struct besides Etc::Group and Etc::Passwd
let :fakestruct do
Struct.new(:foo, :bar)
end
Expand Down Expand Up @@ -82,22 +82,22 @@ def modifycmd(param, value)

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

let(:latin_1_mixed_users) {
[
# In a LATIN-1 environment, ruby will return *all* strings labeled as LATIN-1
Struct::Passwd.new('root'.force_encoding(Encoding::ISO_8859_1), 'x', 0, 0),
Struct::Passwd.new('foo'.force_encoding(Encoding::ISO_8859_1), 'x', 1000, 2000),
Struct::Passwd.new(utf_8_labeled_as_latin_1_jose, utf_8_labeled_as_latin_1_jose, 1002, 2000),
Struct::Passwd.new(valid_latin1_jose, valid_latin1_jose, 1001, 2000), # UTF-8 character
Etc::Passwd.new('root'.force_encoding(Encoding::ISO_8859_1), 'x', 0, 0),
Etc::Passwd.new('foo'.force_encoding(Encoding::ISO_8859_1), 'x', 1000, 2000),
Etc::Passwd.new(utf_8_labeled_as_latin_1_jose, utf_8_labeled_as_latin_1_jose, 1002, 2000),
Etc::Passwd.new(valid_latin1_jose, valid_latin1_jose, 1001, 2000), # UTF-8 character
nil
]
}
Expand Down Expand Up @@ -197,7 +197,7 @@ def modifycmd(param, value)
end

it "should pass the Puppet::Etc :canonical_name Struct member to the constructor" do
users = [ Struct::Passwd.new(invalid_utf_8_jose, invalid_utf_8_jose, 1002, 2000), nil ]
users = [ Etc::Passwd.new(invalid_utf_8_jose, invalid_utf_8_jose, 1002, 2000), nil ]
allow(Etc).to receive(:getpwent).and_return(*users)
expect(provider.class).to receive(:new).with({:name => escaped_utf_8_jose, :canonical_name => invalid_utf_8_jose, :ensure => :present})
provider.class.instances
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/provider/user/hpux_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

context "managing passwords" do
let :pwent do
Struct::Passwd.new("testuser", "foopassword")
Etc::Passwd.new("testuser", "foopassword")
end

before :each do
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/provider/user/openbsd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

let(:shadow_entry) {
return unless Puppet.features.libshadow?
entry = Struct::PasswdEntry.new
entry = Etc::PasswdEntry.new
entry[:sp_namp] = 'myuser' # login name
entry[:sp_loginclass] = 'staff' # login class
entry
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/provider/user/useradd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

let(:shadow_entry) {
return unless Puppet.features.libshadow?
entry = Struct::PasswdEntry.new
entry = Etc::PasswdEntry.new
entry[:sp_namp] = 'myuser' # login name
entry[:sp_pwdp] = '$6$FvW8Ib8h$qQMI/CR9m.QzIicZKutLpBgCBBdrch1IX0rTnxuI32K1pD9.RXZrmeKQlaC.RzODNuoUtPPIyQDufunvLOQWF0' # encrypted password
entry[:sp_lstchg] = 15573 # date of last password change
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/type/exec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def exec_stub(options = {})

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

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

Expand Down

0 comments on commit dd3df54

Please sign in to comment.