Skip to content

Commit

Permalink
PR Checks / Acceptance: use home helper function
Browse files Browse the repository at this point in the history
`home` returns `"/Users"` on macOS and `"/home"` on everything else.
  • Loading branch information
danielparks committed Feb 20, 2024
1 parent a68d06e commit 83664bb
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 54 deletions.
107 changes: 54 additions & 53 deletions spec/acceptance/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

describe 'Per-user rustup management' do
it 'creates test user' do
apply_manifest(<<~'PUPPET', catch_failures: true)
apply_manifest(<<~"PUPPET", catch_failures: true)
# Don’t use managehome in case /etc/skel has rustup installed, as is the
# case on GitHub CI runners.
user { 'user':
Expand All @@ -20,13 +20,13 @@
group => 'user',
mode => '0644',
;
'/home/user':
'#{home}/user':
ensure => directory,
;
'/home/user/.bashrc':
'#{home}/user/.bashrc':
content => "# .bashrc\n",
;
'/home/user/.profile':
'#{home}/user/.profile':
content => "# .profile\n",
;
}
Expand All @@ -40,30 +40,30 @@
PUPPET
end

describe file('/home/user/.rustup') do
describe file("#{home}/user/.rustup") do
it { is_expected.to be_directory }
it { is_expected.to be_owned_by 'user' }
end

describe file('/home/user/.cargo/bin/rustup') do
describe file("#{home}/user/.cargo/bin/rustup") do
it { is_expected.to be_file }
it { is_expected.to be_executable }
it { is_expected.to be_owned_by 'user' }
end

describe file('/home/user/.bashrc') do
describe file("#{home}/user/.bashrc") do
it { is_expected.to be_file }
its(:content) { is_expected.to match %r{^\. "\$HOME/\.cargo/env"$} }
end

describe file('/home/user/.profile') do
describe file("#{home}/user/.profile") do
it { is_expected.to be_file }
its(:content) { is_expected.to match %r{^\. "\$HOME/\.cargo/env"$} }
end

describe command_as_user("echo '$PATH'") do
its(:stdout) do
is_expected.to match %r{(\A|:)/home/user/\.cargo/bin:}
is_expected.to match %r{(\A|:)#{home}/user/\.cargo/bin:}
is_expected.not_to match %r{/opt/rust/cargo/bin}
end
its(:stderr) { is_expected.to eq '' }
Expand Down Expand Up @@ -102,27 +102,27 @@
PUPPET
end

describe file('/home/user/.rustup') do
describe file("#{home}/user/.rustup") do
it { is_expected.not_to exist }
end

describe file('/home/user/.cargo') do
describe file("#{home}/user/.cargo") do
it { is_expected.not_to exist }
end

describe file('/home/user/.bashrc') do
describe file("#{home}/user/.bashrc") do
it { is_expected.to be_file }
its(:content) { is_expected.not_to match %r{^\. "\$HOME/\.cargo/env"$} }
end

describe file('/home/user/.profile') do
describe file("#{home}/user/.profile") do
it { is_expected.to be_file }
its(:content) { is_expected.not_to match %r{^\. "\$HOME/\.cargo/env"$} }
end

describe command_as_user("echo '$PATH'") do
its(:stdout) do
is_expected.not_to match %r{(\A|:)/home/user/\.cargo/bin(:|\Z)}
is_expected.not_to match %r{(\A|:)#{home}/user/\.cargo/bin(:|\Z)}
end
its(:stderr) { is_expected.to eq '' }
its(:exit_status) { is_expected.to eq 0 }
Expand All @@ -141,29 +141,29 @@
PUPPET
end

describe file('/home/user/.rustup') do
describe file("#{home}/user/.rustup") do
it { is_expected.to be_directory }
it { is_expected.to be_owned_by 'user' }
end

describe file('/home/user/.cargo/bin/rustup') do
describe file("#{home}/user/.cargo/bin/rustup") do
it { is_expected.to be_file }
it { is_expected.to be_executable }
it { is_expected.to be_owned_by 'user' }
end

describe file('/home/user/.bashrc') do
describe file("#{home}/user/.bashrc") do
it { is_expected.to be_file }
its(:content) { is_expected.to match %r{^\. "\$HOME/\.cargo/env"$} }
end

describe file('/home/user/.profile') do
describe file("#{home}/user/.profile") do
it { is_expected.to be_file }
its(:content) { is_expected.to match %r{^\. "\$HOME/\.cargo/env"$} }
end

describe command_as_user("echo '$PATH'") do
its(:stdout) { is_expected.to match %r{(\A|:)/home/user/\.cargo/bin:} }
its(:stdout) { is_expected.to match %r{(\A|:)#{home}/user/\.cargo/bin:} }
its(:stderr) { is_expected.to eq '' }
its(:exit_status) { is_expected.to eq 0 }
end
Expand All @@ -184,7 +184,7 @@
its(:exit_status) { is_expected.to eq 0 }
end

describe file('/home/user/.cargo/bin/hello-world') do
describe file("#{home}/user/.cargo/bin/hello-world") do
it { is_expected.to be_executable }
end

Expand All @@ -210,7 +210,7 @@
end

toolchain_name = "beta-#{os[:arch]}-unknown-linux-gnu"
toolchain_path = "/home/user/.rustup/toolchains/#{toolchain_name}"
toolchain_path = "#{home}/user/.rustup/toolchains/#{toolchain_name}"

describe file("#{toolchain_path}/bin/rustc") do
it { is_expected.to be_file }
Expand Down Expand Up @@ -243,7 +243,7 @@
end

toolchain_name = "stable-#{os[:arch]}-unknown-linux-gnu"
toolchain_path = "/home/user/.rustup/toolchains/#{toolchain_name}"
toolchain_path = "#{home}/user/.rustup/toolchains/#{toolchain_name}"

describe file("#{toolchain_path}/bin/rustc") do
it { is_expected.to be_file }
Expand Down Expand Up @@ -272,15 +272,15 @@
end

toolchain_name = "stable-#{os[:arch]}-unknown-linux-gnu"
toolchain_path = "/home/user/.rustup/toolchains/#{toolchain_name}"
toolchain_path = "#{home}/user/.rustup/toolchains/#{toolchain_name}"
describe file("#{toolchain_path}/bin/rustc") do
it { is_expected.to be_file }
it { is_expected.to be_executable }
it { is_expected.to be_owned_by 'user' }
end

toolchain_name = "nightly-#{os[:arch]}-unknown-linux-gnu"
toolchain_path = "/home/user/.rustup/toolchains/#{toolchain_name}"
toolchain_path = "#{home}/user/.rustup/toolchains/#{toolchain_name}"
describe file("#{toolchain_path}/bin/rustc") do
it { is_expected.to be_file }
it { is_expected.to be_executable }
Expand Down Expand Up @@ -346,27 +346,27 @@
PUPPET
end

describe file('/home/user/.rustup') do
describe file("#{home}/user/.rustup") do
it { is_expected.not_to exist }
end

describe file('/home/user/.cargo') do
describe file("#{home}/user/.cargo") do
it { is_expected.not_to exist }
end

describe file('/home/user/.bashrc') do
describe file("#{home}/user/.bashrc") do
it { is_expected.to be_file }
its(:content) { is_expected.not_to match %r{^\. "\$HOME/\.cargo/env"$} }
end

describe file('/home/user/.profile') do
describe file("#{home}/user/.profile") do
it { is_expected.to be_file }
its(:content) { is_expected.not_to match %r{^\. "\$HOME/\.cargo/env"$} }
end

describe command_as_user("echo '$PATH'") do
its(:stdout) do
is_expected.not_to match %r{(\A|:)/home/user/\.cargo/bin(:|\Z)}
is_expected.not_to match %r{(\A|:)#{home}/user/\.cargo/bin(:|\Z)}
end
its(:stderr) { is_expected.to eq '' }
its(:exit_status) { is_expected.to eq 0 }
Expand Down Expand Up @@ -409,10 +409,10 @@
mode => '0644',
before => Rustup['rustup_test'],
;
'/home/rustup_test':
'#{home}/rustup_test':
ensure => directory,
;
'/home/rustup_test/.bashrc':
'#{home}/rustup_test/.bashrc':
ensure => file,
content => "# .bashrc\n",
;
Expand All @@ -423,8 +423,8 @@
PUPPET

expect(user('rustup_test')).to exist
expect(file('/home/rustup_test/.cargo/bin/rustup')).to exist
expect(file('/home/rustup_test/.bashrc').content)
expect(file("#{home}/rustup_test/.cargo/bin/rustup")).to exist
expect(file("#{home}/rustup_test/.bashrc").content)
.to eq %(# .bashrc\n. "$HOME/.cargo/env"\n)

apply_manifest(<<~'PUPPET', catch_failures: true)
Expand All @@ -434,8 +434,8 @@
PUPPET

expect(user('rustup_test')).not_to exist
expect(file('/home/rustup_test/.cargo/bin/rustup')).to exist
expect(file('/home/rustup_test/.bashrc').content)
expect(file("#{home}/rustup_test/.cargo/bin/rustup")).to exist
expect(file("#{home}/rustup_test/.bashrc").content)
.to eq %(# .bashrc\n. "$HOME/.cargo/env"\n)

idempotent_apply(<<~'PUPPET')
Expand All @@ -449,9 +449,9 @@
PUPPET

expect(user('rustup_test')).not_to exist
expect(file('/home/rustup_test')).to exist
expect(file('/home/rustup_test/.cargo')).not_to exist
expect(file('/home/rustup_test/.bashrc').content).to eq %(# .bashrc\n)
expect(file("#{home}/rustup_test")).to exist
expect(file("#{home}/rustup_test/.cargo")).not_to exist
expect(file("#{home}/rustup_test/.bashrc").content).to eq %(# .bashrc\n)
end

it 'can remove itself after the user was deleted (with custom cargo_home)' do
Expand All @@ -467,31 +467,32 @@
file {
default:
ensure => directory,
owner => 'rustup_test',
group => 'rustup_test',
mode => '0644',
before => Rustup['rustup_test'],
;
'/home/rustup_test/.bashrc':
'#{home}/rustup_test/.bashrc':
ensure => file,
content => "# .bashrc\n",
;
['/home/rustup_test', '/home/rustup_test/a', '/home/rustup_test/a/b']:
ensure => directory,
;
'#{home}/rustup_test':;
'#{home}/rustup_test/a':;
'#{home}/rustup_test/a/b':;
}
rustup { 'rustup_test':
cargo_home => '/home/rustup_test/a/b/.cargo',
cargo_home => "#{home}/rustup_test/a/b/.cargo",
}
rustup::toolchain { 'rustup_test: stable': }
PUPPET

expect(user('rustup_test')).to exist
expect(file('/home/rustup_test/a/b/.cargo/bin/rustup')).to exist
expect(file('/home/rustup_test/.bashrc').content)
.to eq %(# .bashrc\n. "/home/rustup_test/a/b/.cargo/env"\n)
expect(file("#{home}/rustup_test/a/b/.cargo/bin/rustup")).to exist
expect(file("#{home}/rustup_test/.bashrc").content)
.to eq %(# .bashrc\n. "#{home}/rustup_test/a/b/.cargo/env"\n)

apply_manifest(<<~'PUPPET', catch_failures: true)
user { 'rustup_test':
Expand All @@ -500,14 +501,14 @@
PUPPET

expect(user('rustup_test')).not_to exist
expect(file('/home/rustup_test/a/b/.cargo/bin/rustup')).to exist
expect(file('/home/rustup_test/.bashrc').content)
.to eq %(# .bashrc\n. "/home/rustup_test/a/b/.cargo/env"\n)
expect(file("#{home}/rustup_test/a/b/.cargo/bin/rustup")).to exist
expect(file("#{home}/rustup_test/.bashrc").content)
.to eq %(# .bashrc\n. "#{home}/rustup_test/a/b/.cargo/env"\n)

idempotent_apply(<<~"PUPPET")
rustup { 'rustup_test':
ensure => absent,
cargo_home => '/home/rustup_test/a/b/.cargo',
cargo_home => "#{home}/rustup_test/a/b/.cargo",
}
rustup::toolchain { 'rustup_test: stable':
Expand All @@ -516,8 +517,8 @@
PUPPET

expect(user('rustup_test')).not_to exist
expect(file('/home/rustup_test')).to exist
expect(file('/home/rustup_test/a/b/.cargo')).not_to exist
expect(file('/home/rustup_test/.bashrc').content).to eq %(# .bashrc\n)
expect(file("#{home}/rustup_test")).to exist
expect(file("#{home}/rustup_test/a/b/.cargo")).not_to exist
expect(file("#{home}/rustup_test/.bashrc").content).to eq %(# .bashrc\n)
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper_acceptance_local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def rm_user(name)
ensure => absent,
}
file { '/home/#{name}':
file { '#{home}/#{name}':
ensure => absent,
force => true,
}
Expand Down

0 comments on commit 83664bb

Please sign in to comment.