diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-03-13 11:48:03 -0700 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-03-13 11:48:03 -0700 |
commit | b7c6878f15327879cdd937b956082eaf61069c13 (patch) | |
tree | 9511cf326adbc9a1e52f1f5dcc3016e7717490fe /spec/functional | |
parent | f400002d1a68b8ee672dea92ddfc6ff15624d9d2 (diff) | |
parent | a1ad408b06d400c053d6bdb17e43d53bacb9ea86 (diff) | |
download | chef-b7c6878f15327879cdd937b956082eaf61069c13.tar.gz |
Merge pull request #3060 from chef/jdm/useradd-specs
Cleanup user directories if state was leftover from previous run
Diffstat (limited to 'spec/functional')
-rw-r--r-- | spec/functional/resource/user/useradd_spec.rb | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/spec/functional/resource/user/useradd_spec.rb b/spec/functional/resource/user/useradd_spec.rb index 852f2eb083..3e4e4e7604 100644 --- a/spec/functional/resource/user/useradd_spec.rb +++ b/spec/functional/resource/user/useradd_spec.rb @@ -77,9 +77,22 @@ describe Chef::Provider::User::Useradd, metadata do end end + def try_cleanup + ['/home/cheftestfoo', '/home/cheftestbar'].each do |f| + FileUtils.rm_rf(f) if File.exists? f + end + + ['cf-test'].each do |u| + r = Chef::Resource::User.new("DELETE USER", run_context) + r.username('cf-test') + r.run_action(:remove) + end + end + before do # Silence shell_out live stream Chef::Log.level = :warn + try_cleanup end after do @@ -387,18 +400,18 @@ describe Chef::Provider::User::Useradd, metadata do end context "and home directory is updated" do - let(:existing_home) { "/home/foo" } - let(:home) { "/home/bar" } + let(:existing_home) { "/home/cheftestfoo" } + let(:home) { "/home/cheftestbar" } it "ensures the home directory is set to the desired value" do - expect(pw_entry.home).to eq("/home/bar") + expect(pw_entry.home).to eq("/home/cheftestbar") end context "and manage_home is enabled" do let(:existing_manage_home) { true } let(:manage_home) { true } it "moves the home directory to the new location" do - expect(File).not_to exist("/home/foo") - expect(File).to exist("/home/bar") + expect(File).not_to exist("/home/cheftestfoo") + expect(File).to exist("/home/cheftestbar") end end @@ -410,19 +423,19 @@ describe Chef::Provider::User::Useradd, metadata do # Inconsistent behavior. See: CHEF-2205 it "created the home dir b/c of CHEF-2205 so it still exists" do # This behavior seems contrary to expectation and non-convergent. - expect(File).not_to exist("/home/foo") - expect(File).to exist("/home/bar") + expect(File).not_to exist("/home/cheftestfoo") + expect(File).to exist("/home/cheftestbar") end elsif ohai[:platform] == "aix" it "creates the home dir in the desired location" do - expect(File).not_to exist("/home/foo") - expect(File).to exist("/home/bar") + expect(File).not_to exist("/home/cheftestfoo") + expect(File).to exist("/home/cheftestbar") end else it "does not create the home dir in the desired location (XXX)" do # This behavior seems contrary to expectation and non-convergent. - expect(File).not_to exist("/home/foo") - expect(File).not_to exist("/home/bar") + expect(File).not_to exist("/home/cheftestfoo") + expect(File).not_to exist("/home/cheftestbar") end end end @@ -433,8 +446,8 @@ describe Chef::Provider::User::Useradd, metadata do it "leaves the old home directory around (XXX)" do # Would it be better to remove the old home? - expect(File).to exist("/home/foo") - expect(File).not_to exist("/home/bar") + expect(File).to exist("/home/cheftestfoo") + expect(File).not_to exist("/home/cheftestbar") end end end |