diff options
Diffstat (limited to 'spec/functional/resource/link_spec.rb')
-rw-r--r-- | spec/functional/resource/link_spec.rb | 262 |
1 files changed, 131 insertions, 131 deletions
diff --git a/spec/functional/resource/link_spec.rb b/spec/functional/resource/link_spec.rb index 6b214f0b16..4840713667 100644 --- a/spec/functional/resource/link_spec.rb +++ b/spec/functional/resource/link_spec.rb @@ -16,10 +16,10 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" if windows? - require 'chef/win32/file' #probably need this in spec_helper + require "chef/win32/file" #probably need this in spec_helper end describe Chef::Resource::Link do @@ -31,7 +31,7 @@ describe Chef::Resource::Link do # different file deployment strategies more completely. let(:test_file_dir) do if windows? - File.join(ENV['systemdrive'], "test-dir") + File.join(ENV["systemdrive"], "test-dir") else File.join(CHEF_SPEC_DATA, "test-dir") end @@ -73,7 +73,7 @@ describe Chef::Resource::Link do end def canonicalize(path) - windows? ? path.gsub('/', '\\') : path + windows? ? path.gsub("/", '\\') : path end def symlink(a, b) @@ -121,142 +121,142 @@ describe Chef::Resource::Link do end describe "when supported on platform", :not_supported_on_win2k3 do - shared_examples_for 'delete errors out' do - it 'delete errors out' do + shared_examples_for "delete errors out" do + it "delete errors out" do expect { resource.run_action(:delete) }.to raise_error(Chef::Exceptions::Link) expect(File.exist?(target_file) || symlink?(target_file)).to be_truthy end end - shared_context 'delete is noop' do - describe 'the :delete action' do + shared_context "delete is noop" do + describe "the :delete action" do before(:each) do @info = [] allow(Chef::Log).to receive(:info) { |msg| @info << msg } resource.run_action(:delete) end - it 'leaves the file deleted' do + it "leaves the file deleted" do expect(File.exist?(target_file)).to be_falsey expect(symlink?(target_file)).to be_falsey end - it 'does not mark the resource updated' do + it "does not mark the resource updated" do expect(resource).not_to be_updated end - it 'does not log that it deleted' do + it "does not log that it deleted" do expect(@info.include?("link[#{target_file}] deleted")).to be_falsey end end end - shared_context 'delete succeeds' do - describe 'the :delete action' do + shared_context "delete succeeds" do + describe "the :delete action" do before(:each) do @info = [] allow(Chef::Log).to receive(:info) { |msg| @info << msg } resource.run_action(:delete) end - it 'deletes the file' do + it "deletes the file" do expect(File.exist?(target_file)).to be_falsey expect(symlink?(target_file)).to be_falsey end - it 'marks the resource updated' do + it "marks the resource updated" do expect(resource).to be_updated end - it 'logs that it deleted' do + it "logs that it deleted" do expect(@info.include?("link[#{target_file}] deleted")).to be_truthy end end end - shared_context 'create symbolic link succeeds' do - describe 'the :create action' do + shared_context "create symbolic link succeeds" do + describe "the :create action" do before(:each) do @info = [] allow(Chef::Log).to receive(:info) { |msg| @info << msg } resource.run_action(:create) end - it 'links to the target file' do + it "links to the target file" do expect(symlink?(target_file)).to be_truthy expect(readlink(target_file)).to eq(canonicalize(to)) end - it 'marks the resource updated' do + it "marks the resource updated" do expect(resource).to be_updated end - it 'logs that it created' do + it "logs that it created" do expect(@info.include?("link[#{target_file}] created")).to be_truthy end end end - shared_context 'create symbolic link is noop' do - describe 'the :create action' do + shared_context "create symbolic link is noop" do + describe "the :create action" do before(:each) do @info = [] allow(Chef::Log).to receive(:info) { |msg| @info << msg } resource.run_action(:create) end - it 'leaves the file linked' do + it "leaves the file linked" do expect(symlink?(target_file)).to be_truthy expect(readlink(target_file)).to eq(canonicalize(to)) end - it 'does not mark the resource updated' do + it "does not mark the resource updated" do expect(resource).not_to be_updated end - it 'does not log that it created' do + it "does not log that it created" do expect(@info.include?("link[#{target_file}] created")).to be_falsey end end end - shared_context 'create hard link succeeds' do - describe 'the :create action' do + shared_context "create hard link succeeds" do + describe "the :create action" do before(:each) do @info = [] allow(Chef::Log).to receive(:info) { |msg| @info << msg } resource.run_action(:create) end - it 'preserves the hard link' do + it "preserves the hard link" do expect(File.exists?(target_file)).to be_truthy expect(symlink?(target_file)).to be_falsey # Writing to one hardlinked file should cause both # to have the new value. expect(IO.read(to)).to eq(IO.read(target_file)) - File.open(to, "w") { |file| file.write('wowzers') } - expect(IO.read(target_file)).to eq('wowzers') + File.open(to, "w") { |file| file.write("wowzers") } + expect(IO.read(target_file)).to eq("wowzers") end - it 'marks the resource updated' do + it "marks the resource updated" do expect(resource).to be_updated end - it 'logs that it created' do + it "logs that it created" do expect(@info.include?("link[#{target_file}] created")).to be_truthy end end end - shared_context 'create hard link is noop' do - describe 'the :create action' do + shared_context "create hard link is noop" do + describe "the :create action" do before(:each) do @info = [] allow(Chef::Log).to receive(:info) { |msg| @info << msg } resource.run_action(:create) end - it 'links to the target file' do + it "links to the target file" do expect(File.exists?(target_file)).to be_truthy expect(symlink?(target_file)).to be_falsey # Writing to one hardlinked file should cause both # to have the new value. expect(IO.read(to)).to eq(IO.read(target_file)) - File.open(to, "w") { |file| file.write('wowzers') } - expect(IO.read(target_file)).to eq('wowzers') + File.open(to, "w") { |file| file.write("wowzers") } + expect(IO.read(target_file)).to eq("wowzers") end - it 'does not mark the resource updated' do + it "does not mark the resource updated" do expect(resource).not_to be_updated end - it 'does not log that it created' do + it "does not log that it created" do expect(@info.include?("link[#{target_file}] created")).to be_falsey end end @@ -264,34 +264,34 @@ describe Chef::Resource::Link do context "is symbolic" do - context 'when the link destination is a file' do + context "when the link destination is a file" do before(:each) do File.open(to, "w") do |file| - file.write('woohoo') + file.write("woohoo") end end - context 'and the link does not yet exist' do - include_context 'create symbolic link succeeds' - include_context 'delete is noop' + context "and the link does not yet exist" do + include_context "create symbolic link succeeds" + include_context "delete is noop" end - context 'and the link already exists and is a symbolic link' do - context 'pointing at the target' do + context "and the link already exists and is a symbolic link" do + context "pointing at the target" do before(:each) do symlink(to, target_file) expect(symlink?(target_file)).to be_truthy expect(readlink(target_file)).to eq(canonicalize(to)) end - include_context 'create symbolic link is noop' - include_context 'delete succeeds' - it 'the :delete action does not delete the target file' do + include_context "create symbolic link is noop" + include_context "delete succeeds" + it "the :delete action does not delete the target file" do resource.run_action(:delete) expect(File.exists?(to)).to be_truthy end end - context 'pointing somewhere else' do + context "pointing somewhere else" do before(:each) do - @other_target = File.join(test_file_dir, make_tmpname('other_spec')) - File.open(@other_target, 'w') { |file| file.write('eek') } + @other_target = File.join(test_file_dir, make_tmpname("other_spec")) + File.open(@other_target, "w") { |file| file.write("eek") } symlink(@other_target, target_file) expect(symlink?(target_file)).to be_truthy expect(readlink(target_file)).to eq(canonicalize(@other_target)) @@ -299,45 +299,45 @@ describe Chef::Resource::Link do after(:each) do File.delete(@other_target) end - include_context 'create symbolic link succeeds' - include_context 'delete succeeds' - it 'the :delete action does not delete the target file' do + include_context "create symbolic link succeeds" + include_context "delete succeeds" + it "the :delete action does not delete the target file" do resource.run_action(:delete) expect(File.exists?(to)).to be_truthy end end - context 'pointing nowhere' do + context "pointing nowhere" do before(:each) do - nonexistent = File.join(test_file_dir, make_tmpname('nonexistent_spec')) + nonexistent = File.join(test_file_dir, make_tmpname("nonexistent_spec")) symlink(nonexistent, target_file) expect(symlink?(target_file)).to be_truthy expect(readlink(target_file)).to eq(canonicalize(nonexistent)) end - include_context 'create symbolic link succeeds' - include_context 'delete succeeds' + include_context "create symbolic link succeeds" + include_context "delete succeeds" end end - context 'and the link already exists and is a hard link to the file' do + context "and the link already exists and is a hard link to the file" do before(:each) do link(to, target_file) expect(File.exists?(target_file)).to be_truthy expect(symlink?(target_file)).to be_falsey end - include_context 'create symbolic link succeeds' - it_behaves_like 'delete errors out' + include_context "create symbolic link succeeds" + it_behaves_like "delete errors out" end - context 'and the link already exists and is a file' do + context "and the link already exists and is a file" do before(:each) do - File.open(target_file, 'w') { |file| file.write('eek') } + File.open(target_file, "w") { |file| file.write("eek") } end - include_context 'create symbolic link succeeds' - it_behaves_like 'delete errors out' + include_context "create symbolic link succeeds" + it_behaves_like "delete errors out" end - context 'and the link already exists and is a directory' do + context "and the link already exists and is a directory" do before(:each) do Dir.mkdir(target_file) end - it 'create errors out' do + it "create errors out" do if windows? expect { resource.run_action(:create) }.to raise_error(Errno::EACCES) elsif os_x? or solaris? or freebsd? or aix? @@ -346,10 +346,10 @@ describe Chef::Resource::Link do expect { resource.run_action(:create) }.to raise_error(Errno::EISDIR) end end - it_behaves_like 'delete errors out' + it_behaves_like "delete errors out" end - it_behaves_like 'a securable resource without existing target' do + it_behaves_like "a securable resource without existing target" do let(:path) { target_file } def allowed_acl(sid, expected_perms) [ ACE.access_allowed(sid, expected_perms[:specific]) ] @@ -366,27 +366,27 @@ describe Chef::Resource::Link do end end end - context 'when the link destination is a directory' do + context "when the link destination is a directory" do before(:each) do Dir.mkdir(to) end # On Windows, readlink fails to open the link. FILE_FLAG_OPEN_REPARSE_POINT # might help, from http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx - context 'and the link does not yet exist' do - include_context 'create symbolic link succeeds' - include_context 'delete is noop' + context "and the link does not yet exist" do + include_context "create symbolic link succeeds" + include_context "delete is noop" end - context 'and the link already exists and points to a different directory' do + context "and the link already exists and points to a different directory" do before(:each) do other_dir = File.join(test_file_dir, make_tmpname("other_dir")) Dir.mkdir(other_dir) symlink(other_dir, target_file) end - include_context 'create symbolic link succeeds' + include_context "create symbolic link succeeds" end end context "when the link destination is a symbolic link" do - context 'to a file that exists' do + context "to a file that exists" do before(:each) do @other_target = File.join(test_file_dir, make_tmpname("other_spec")) File.open(@other_target, "w") { |file| file.write("eek") } @@ -397,32 +397,32 @@ describe Chef::Resource::Link do after(:each) do File.delete(@other_target) end - context 'and the link does not yet exist' do - include_context 'create symbolic link succeeds' - include_context 'delete is noop' + context "and the link does not yet exist" do + include_context "create symbolic link succeeds" + include_context "delete is noop" end end - context 'to a file that does not exist' do + context "to a file that does not exist" do before(:each) do @other_target = File.join(test_file_dir, make_tmpname("other_spec")) symlink(@other_target, to) expect(symlink?(to)).to be_truthy expect(readlink(to)).to eq(canonicalize(@other_target)) end - context 'and the link does not yet exist' do - include_context 'create symbolic link succeeds' - include_context 'delete is noop' + context "and the link does not yet exist" do + include_context "create symbolic link succeeds" + include_context "delete is noop" end end end context "when the link destination does not exist" do - include_context 'create symbolic link succeeds' - include_context 'delete is noop' + include_context "create symbolic link succeeds" + include_context "delete is noop" end { - '../' => 'with a relative link destination', - '' => 'with a bare filename for the link destination', + "../" => "with a relative link destination", + "" => "with a bare filename for the link destination", }.each do |prefix, desc| context desc do let(:to) { "#{prefix}#{File.basename(absolute_to)}" } @@ -430,27 +430,27 @@ describe Chef::Resource::Link do before(:each) do resource.to(to) end - context 'when the link does not yet exist' do - include_context 'create symbolic link succeeds' - include_context 'delete is noop' + context "when the link does not yet exist" do + include_context "create symbolic link succeeds" + include_context "delete is noop" end - context 'when the link already exists and points at the target' do + context "when the link already exists and points at the target" do before(:each) do symlink(to, target_file) expect(symlink?(target_file)).to be_truthy expect(readlink(target_file)).to eq(canonicalize(to)) end - include_context 'create symbolic link is noop' - include_context 'delete succeeds' + include_context "create symbolic link is noop" + include_context "delete succeeds" end - context 'when the link already exists and points at the target with an absolute path' do + context "when the link already exists and points at the target with an absolute path" do before(:each) do symlink(absolute_to, target_file) expect(symlink?(target_file)).to be_truthy expect(readlink(target_file)).to eq(canonicalize(absolute_to)) end - include_context 'create symbolic link succeeds' - include_context 'delete succeeds' + include_context "create symbolic link succeeds" + include_context "delete succeeds" end end end @@ -464,12 +464,12 @@ describe Chef::Resource::Link do context "when the link destination is a file" do before(:each) do File.open(to, "w") do |file| - file.write('woohoo') + file.write("woohoo") end end context "and the link does not yet exist" do - include_context 'create hard link succeeds' - include_context 'delete is noop' + include_context "create hard link succeeds" + include_context "delete is noop" end context "and the link already exists and is a symbolic link pointing at the same file" do before(:each) do @@ -477,34 +477,34 @@ describe Chef::Resource::Link do expect(symlink?(target_file)).to be_truthy expect(readlink(target_file)).to eq(canonicalize(to)) end - include_context 'create hard link succeeds' - it_behaves_like 'delete errors out' + include_context "create hard link succeeds" + it_behaves_like "delete errors out" end - context 'and the link already exists and is a hard link to the file' do + context "and the link already exists and is a hard link to the file" do before(:each) do link(to, target_file) expect(File.exists?(target_file)).to be_truthy expect(symlink?(target_file)).to be_falsey end - include_context 'create hard link is noop' - include_context 'delete succeeds' - it 'the :delete action does not delete the target file' do + include_context "create hard link is noop" + include_context "delete succeeds" + it "the :delete action does not delete the target file" do resource.run_action(:delete) expect(File.exists?(to)).to be_truthy end end context "and the link already exists and is a file" do before(:each) do - File.open(target_file, 'w') { |file| file.write('tomfoolery') } + File.open(target_file, "w") { |file| file.write("tomfoolery") } end - include_context 'create hard link succeeds' - it_behaves_like 'delete errors out' + include_context "create hard link succeeds" + it_behaves_like "delete errors out" end context "and the link already exists and is a directory" do before(:each) do Dir.mkdir(target_file) end - it 'errors out' do + it "errors out" do if windows? expect { resource.run_action(:create) }.to raise_error(Errno::EACCES) elsif os_x? or solaris? or freebsd? or aix? @@ -513,18 +513,18 @@ describe Chef::Resource::Link do expect { resource.run_action(:create) }.to raise_error(Errno::EISDIR) end end - it_behaves_like 'delete errors out' + it_behaves_like "delete errors out" end context "and specifies security attributes" do before(:each) do - resource.owner(windows? ? 'Guest' : 'nobody') + resource.owner(windows? ? "Guest" : "nobody") end - it 'ignores them' do + it "ignores them" do resource.run_action(:create) if windows? expect(Chef::ReservedNames::Win32::Security.get_named_security_info(target_file).owner).not_to eq(SID.Guest) else - expect(File.lstat(target_file).uid).not_to eq(Etc.getpwnam('nobody').uid) + expect(File.lstat(target_file).uid).not_to eq(Etc.getpwnam("nobody").uid) end end end @@ -533,15 +533,15 @@ describe Chef::Resource::Link do before(:each) do Dir.mkdir(to) end - context 'and the link does not yet exist' do - it 'create errors out' do + context "and the link does not yet exist" do + it "create errors out" do expect { resource.run_action(:create) }.to raise_error(windows? ? Chef::Exceptions::Win32APIError : Errno::EPERM) end - include_context 'delete is noop' + include_context "delete is noop" end end context "when the link destination is a symbolic link" do - context 'to a real file' do + context "to a real file" do before(:each) do @other_target = File.join(test_file_dir, make_tmpname("other_spec")) File.open(@other_target, "w") { |file| file.write("eek") } @@ -552,28 +552,28 @@ describe Chef::Resource::Link do after(:each) do File.delete(@other_target) end - context 'and the link does not yet exist' do - it 'links to the target file' do - skip('OS X/FreeBSD/AIX symlink? and readlink working on hard links to symlinks') if (os_x? or freebsd? or aix?) + context "and the link does not yet exist" do + it "links to the target file" do + skip("OS X/FreeBSD/AIX symlink? and readlink working on hard links to symlinks") if (os_x? or freebsd? or aix?) resource.run_action(:create) expect(File.exists?(target_file)).to be_truthy # OS X gets angry about this sort of link. Bug in OS X, IMO. expect(symlink?(target_file)).to be_truthy expect(readlink(target_file)).to eq(canonicalize(@other_target)) end - include_context 'delete is noop' + include_context "delete is noop" end end - context 'to a nonexistent file' do + context "to a nonexistent file" do before(:each) do @other_target = File.join(test_file_dir, make_tmpname("other_spec")) symlink(@other_target, to) expect(symlink?(to)).to be_truthy expect(readlink(to)).to eq(canonicalize(@other_target)) end - context 'and the link does not yet exist' do - it 'links to the target file' do - skip('OS X/FreeBSD/AIX fails to create hardlinks to broken symlinks') if (os_x? or freebsd? or aix?) + context "and the link does not yet exist" do + it "links to the target file" do + skip("OS X/FreeBSD/AIX fails to create hardlinks to broken symlinks") if (os_x? or freebsd? or aix?) resource.run_action(:create) # Windows and Unix have different definitions of exists? here, and that's OK. if windows? @@ -584,17 +584,17 @@ describe Chef::Resource::Link do expect(symlink?(target_file)).to be_truthy expect(readlink(target_file)).to eq(canonicalize(@other_target)) end - include_context 'delete is noop' + include_context "delete is noop" end end end context "when the link destination does not exist" do - context 'and the link does not yet exist' do - it 'create errors out' do + context "and the link does not yet exist" do + it "create errors out" do expect { resource.run_action(:create) }.to raise_error(Errno::ENOENT) end - include_context 'delete is noop' + include_context "delete is noop" end end end |