Skip to content

Commit

Permalink
more debug
Browse files Browse the repository at this point in the history
  • Loading branch information
danielparks committed Feb 16, 2024
1 parent fdaa7f7 commit edb6a93
Showing 1 changed file with 4 additions and 160 deletions.
164 changes: 4 additions & 160 deletions spec/acceptance/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,171 +3,12 @@
require 'spec_helper_acceptance'

describe 'Per-user rustup management' do
context 'supports installing without toolchain' do
it do
idempotent_apply(<<~'END')
user { 'user':
ensure => present,
managehome => true,
shell => '/bin/bash',
}
rustup { 'user': }
END
end

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
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
it { is_expected.to be_file }
its(:content) { is_expected.to match %r{^\. "\$HOME/\.cargo/env"$} }
end

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.not_to match %r{/opt/rust/cargo/bin}
end
its(:stderr) { is_expected.to eq '' }
its(:exit_status) { is_expected.to eq 0 }
end

describe command_as_user('rustup toolchain list') do
its(:stdout) { is_expected.to match %r{^no installed toolchains$} }
its(:stderr) { is_expected.to eq '' }
its(:exit_status) { is_expected.to eq 0 }
end

describe command_as_user('rm -rf hello-world') do
its(:exit_status) { is_expected.to eq 0 }
end

# FIXME: this test will fail if there is any present rustup installation. As
# long as the tests are run in order (sigh), they should clean themselves
# up. Unfortunately, there doesn’t seem to be a way to just reset the VM.
describe command_as_user('cargo init hello-world --bin --quiet') do
its(:stderr) do
is_expected.to match(
%r{error: rustup could not choose a version of cargo to run},
)
end
its(:exit_status) { is_expected.to be > 0 }
end
end

context 'fails with uninstalled default_toolchain' do
it do
apply_manifest(<<~'PUPPET', expect_failures: true)
rustup { 'user':
purge_toolchains => true,
toolchains => ['nightly', 'stable'],
targets => ['default nightly', 'default stable'],
default_toolchain => 'beta',
}
PUPPET
end
end

context 'supports installing non-host toolchain' do
target = 'x86_64-pc-windows-gnu'
toolchain = "stable-#{target}"

it do
# Note that the quotes here are within the END block.
idempotent_apply(<<~END)
rustup { 'user': }
rustup::toolchain { 'user: #{toolchain}': }
END
end

command = "rustup target list --toolchain #{toolchain}"
describe command_as_user(command) do
its(:stdout) do
is_expected.to match(%r{^#{target} \(installed\)$})
end
its(:stderr) { is_expected.to eq '' }
its(:exit_status) { is_expected.to eq 0 }
end
end

context 'supports multi-resource uninstall for a real user' do
it do
idempotent_apply(<<~'END')
rustup { 'user':
ensure => absent,
}
rustup::toolchain { 'user: stable':
ensure => absent,
}
rustup::target { 'user: wasm32-unknown-unknown stable':
ensure => absent,
}
END
end

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

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

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
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)}
end
its(:stderr) { is_expected.to eq '' }
its(:exit_status) { is_expected.to eq 0 }
end
end

it 'supports ensure=>absent with non-existant user' do
expect(user('non_existant_user')).not_to exist

idempotent_apply(<<~'END')
rustup { 'non_existant_user':
ensure => absent,
}
rustup::toolchain { 'non_existant_user: stable':
ensure => absent,
}
rustup::target { 'non_existant_user: wasm32-unknown-unknown stable':
ensure => absent,
}
END

expect(user('non_existant_user')).not_to exist
end

it 'can remove itself after the user was deleted' do
rm_user('rustup_test')

puts "/etc/skel"
puts Dir.entries("/etc/skel").sort rescue puts "no /etc/skel"
puts "--------"

puts "default cargo home"
puts "run 1"
Expand All @@ -187,7 +28,10 @@
#before => Rustup['rustup_test'],
}
END

puts "/home/rustup_test"
puts Dir.entries("/home/rustup_test").sort rescue puts "no /home/rustup_test"
puts "--------"
puts "run 1a"

puts apply_manifest(<<~'END', catch_failures: true, prefix_command: 'RUSTUP_TRACE=1 ').stderr
Expand Down

0 comments on commit edb6a93

Please sign in to comment.