Skip to content

Commit

Permalink
rm_user consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
danielparks committed Feb 15, 2024
1 parent c6ccbd9 commit fc320e2
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 119 deletions.
208 changes: 99 additions & 109 deletions spec/acceptance/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -366,134 +366,124 @@
expect(user('non_existant_user')).not_to exist
end

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

apply_manifest(<<~'END', catch_failures: true)
user { 'rustup_test':
ensure => present,
managehome => true,
}
file { '/home/rustup_test/.bashrc':
ensure => file,
owner => 'rustup_test',
group => 'rustup_test',
mode => '0644',
content => "# .bashrc\n",
require => User['rustup_test'],
before => Rustup['rustup_test'],
}
rustup { 'rustup_test': }
rustup::toolchain { 'rustup_test: stable': }
END
apply_manifest(<<~'END', catch_failures: true)
user { 'rustup_test':
ensure => present,
managehome => true,
}
expect(user('rustup_test')).to exist
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)
file { '/home/rustup_test/.bashrc':
ensure => file,
owner => 'rustup_test',
group => 'rustup_test',
mode => '0644',
content => "# .bashrc\n",
require => User['rustup_test'],
before => Rustup['rustup_test'],
}
apply_manifest(<<~'END', catch_failures: true)
user { 'rustup_test':
ensure => absent,
}
END
rustup { 'rustup_test': }
rustup::toolchain { 'rustup_test: stable': }
END

expect(user('rustup_test')).not_to exist
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)
expect(user('rustup_test')).to exist
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(<<~'END')
rustup { 'rustup_test':
ensure => absent,
}
apply_manifest(<<~'END', catch_failures: true)
user { 'rustup_test':
ensure => absent,
}
END

rustup::toolchain { 'rustup_test: stable':
ensure => absent,
}
END
expect(user('rustup_test')).not_to exist
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)

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)
idempotent_apply(<<~'END')
rustup { 'rustup_test':
ensure => absent,
}
# Clean up
rm_user('rustup_test')
end
rustup::toolchain { 'rustup_test: stable':
ensure => absent,
}
END

it 'can remove itself after the user was deleted (with custom cargo_home)' do
rm_user('rustup_test')
expect(user('rustup_test')).not_to exist
expect(file('/home/rustup_test')).not_to exist
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)
end

apply_manifest(<<~'END', catch_failures: true)
user { 'rustup_test':
ensure => present,
managehome => true,
}
it 'can remove itself after the user was deleted (with custom cargo_home)' do
rm_user('rustup_test')

file {
default:
owner => 'rustup_test',
group => 'rustup_test',
mode => '0644',
require => User['rustup_test'],
before => Rustup['rustup_test'],
;
'/home/rustup_test/.bashrc':
ensure => file,
content => "# .bashrc\n",
;
['/home/rustup_test/a', '/home/rustup_test/a/b']:
ensure => directory,
;
}
apply_manifest(<<~'END', catch_failures: true)
user { 'rustup_test':
ensure => present,
managehome => true,
}
rustup { 'rustup_test':
cargo_home => '/home/rustup_test/a/b/.cargo',
}
file {
default:
owner => 'rustup_test',
group => 'rustup_test',
mode => '0644',
require => User['rustup_test'],
before => Rustup['rustup_test'],
;
'/home/rustup_test/.bashrc':
ensure => file,
content => "# .bashrc\n",
;
['/home/rustup_test/a', '/home/rustup_test/a/b']:
ensure => directory,
;
}
rustup::toolchain { 'rustup_test: stable': }
END
rustup { 'rustup_test':
cargo_home => '/home/rustup_test/a/b/.cargo',
}
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)
rustup::toolchain { 'rustup_test: stable': }
END

apply_manifest(<<~'END', catch_failures: true)
user { 'rustup_test':
ensure => absent,
}
END
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(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)
apply_manifest(<<~'END', catch_failures: true)
user { 'rustup_test':
ensure => absent,
}
END

idempotent_apply(<<~'END')
rustup { 'rustup_test':
ensure => absent,
cargo_home => '/home/rustup_test/a/b/.cargo',
}
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)

rustup::toolchain { 'rustup_test: stable':
ensure => absent,
}
END
idempotent_apply(<<~'END')
rustup { 'rustup_test':
ensure => absent,
cargo_home => '/home/rustup_test/a/b/.cargo',
}
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)
rustup::toolchain { 'rustup_test: stable':
ensure => absent,
}
END

# Clean up
rm_user('rustup_test')
end
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)
end
end
13 changes: 3 additions & 10 deletions spec/spec_helper_acceptance_local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,13 @@ def command_as_user(cmd)
command("sudo -iu user #{cmd}")
end

def expect_no_user(name)
it "user #{name}" do
expect(user(name)).not_to exist
expect(file("/home/#{name}")).not_to exist
end
end

def rm_user(name)
apply_manifest(<<~'END', catch_failures: true)
user { 'rustup_test':
apply_manifest(<<~"END", catch_failures: true)
user { #{name}:
ensure => absent,
}
file { '/home/rustup_test':
file { '/home/#{name}':
ensure => absent,
force => true,
}
Expand Down

0 comments on commit fc320e2

Please sign in to comment.