diff options
author | danielsdeleo <dan@opscode.com> | 2013-01-07 12:12:44 -0800 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2013-01-07 12:12:44 -0800 |
commit | ba76735a9280a6af41504697ccbdb1382a6c9ecd (patch) | |
tree | 197297ebc90e039228533b846d60a066ed349d27 | |
parent | 3b255388943261f3d78bf202a66eaf0af8ef9c37 (diff) | |
parent | 5af97b3bbb4a38bd7d87fcc0077dc963efd1d25d (diff) | |
download | chef-ba76735a9280a6af41504697ccbdb1382a6c9ecd.tar.gz |
Merge branch 'functional-test-context-fix'
-rw-r--r-- | spec/functional/resource/link_spec.rb | 2 | ||||
-rw-r--r-- | spec/support/shared/functional/directory_resource.rb | 3 | ||||
-rw-r--r-- | spec/support/shared/functional/file_resource.rb | 14 | ||||
-rw-r--r-- | spec/support/shared/functional/securable_resource.rb | 65 |
4 files changed, 46 insertions, 38 deletions
diff --git a/spec/functional/resource/link_spec.rb b/spec/functional/resource/link_spec.rb index 39be3d58d9..5566a41587 100644 --- a/spec/functional/resource/link_spec.rb +++ b/spec/functional/resource/link_spec.rb @@ -25,6 +25,8 @@ end describe Chef::Resource::Link, :not_supported_on_win2k3 do let(:file_base) { "file_spec" } + let(:expect_updated?) {true} + let(:base_dir) do if windows? Chef::ReservedNames::Win32::File.get_long_path_name(Dir.tmpdir.gsub('/', '\\')) diff --git a/spec/support/shared/functional/directory_resource.rb b/spec/support/shared/functional/directory_resource.rb index 1eaa173c06..c4a93c076b 100644 --- a/spec/support/shared/functional/directory_resource.rb +++ b/spec/support/shared/functional/directory_resource.rb @@ -17,6 +17,9 @@ # shared_examples_for "a directory resource" do + + let(:expect_updated?) {true} + context "when the target directory does not exist" do before do # assert pre-condition diff --git a/spec/support/shared/functional/file_resource.rb b/spec/support/shared/functional/file_resource.rb index a0342cb6d7..04b6e1640d 100644 --- a/spec/support/shared/functional/file_resource.rb +++ b/spec/support/shared/functional/file_resource.rb @@ -149,6 +149,13 @@ shared_examples_for "a file resource" do # note the stripping of the drive letter from the tmpdir on windows let(:backup_glob) { File.join(CHEF_SPEC_BACKUP_PATH, Dir.tmpdir.sub(/^([A-Za-z]:)/, ""), "#{file_base}*") } + # Most tests update the resource, but a few do not. We need to test that the + # resource is marked updated or not correctly, but the test contexts are + # composed between correct/incorrect content and correct/incorrect + # permissions. We override this "let" definition in the context where content + # and permissions are correct. + let(:expect_updated?) { true } + def binread(file) content = File.open(file, "rb") do |f| f.read @@ -242,7 +249,7 @@ shared_examples_for "a file resource" do include_context "setup broken permissions" it_behaves_like "a file with the wrong content" - + it_behaves_like "a securable resource" end end @@ -258,6 +265,11 @@ shared_examples_for "a file resource" do end describe "and the target file has the correct permissions" do + + # When permissions and content are correct, chef should do nothing and + # the resource should not be marked updated. + let(:expect_updated?) { false } + include_context "setup correct permissions" it_behaves_like "a file with the correct content" diff --git a/spec/support/shared/functional/securable_resource.rb b/spec/support/shared/functional/securable_resource.rb index 240b65b225..187b512ab2 100644 --- a/spec/support/shared/functional/securable_resource.rb +++ b/spec/support/shared/functional/securable_resource.rb @@ -24,42 +24,32 @@ require 'etc' shared_context "setup correct permissions" do - context "on unix", :unix_only do - context "with root", :requires_root do - before :each do - File.chown(Etc.getpwnam('nobody').uid, 1337, path) - File.chmod(0776, path) - now = Time.now.to_i - File.utime(now - 9000, now - 9000, path) - end - end - context "without root", :requires_unprivileged_user do - before :each do - File.chmod(0776, path) - now = Time.now.to_i - File.utime(now - 9000, now - 9000, path) - end - end + # I could not get this to work with :requires_unprivileged_user for whatever + # reason. The setup when running as root is the same as non-root, except we + # also do a chown, so this sets up correct context for either case. + before :each, :unix_only do + File.chmod(0776, path) + now = Time.now.to_i + File.utime(now - 9000, now - 9000, path) + end + + # Root only context. + before :each, :unix_only, :requires_root do + File.chown(Etc.getpwnam('nobody').uid, 1337, path) end # FIXME: windows end shared_context "setup broken permissions" do - context "on unix", :unix_only do - context "with root", :requires_root do - before :each do - File.chown(0, 0, path) - File.chmod(0644, path) - end - end - - context "without root", :requires_unprivileged_user do - before :each do - File.chmod(0644, path) - end - end + + before :each, :unix_only do + File.chmod(0644, path) + end + + before :each, :unix_only, :requires_root do + File.chown(0, 0, path) end # FIXME: windows @@ -85,9 +75,10 @@ shared_examples_for "a securable resource" do File.lstat(path).uid.should == expected_uid end - it "is marked as updated" do - resource.should be_updated_by_last_action + it "is marked as updated only if changes are made" do + resource.updated_by_last_action?.should == expect_updated? end + end describe "when setting the group", :requires_root do @@ -100,8 +91,8 @@ shared_examples_for "a securable resource" do File.lstat(path).gid.should == expected_gid end - it "is marked as updated" do - resource.should be_updated_by_last_action + it "is marked as updated only if changes are made" do + resource.updated_by_last_action?.should == expect_updated? end end @@ -119,8 +110,8 @@ shared_examples_for "a securable resource" do end end - it "marks the resource as updated" do - resource.should be_updated_by_last_action + it "is marked as updated only if changes are made" do + resource.updated_by_last_action?.should == expect_updated? end end @@ -137,8 +128,8 @@ shared_examples_for "a securable resource" do end end - it "is marked as updated" do - resource.should be_updated_by_last_action + it "is marked as updated only if changes are made" do + resource.updated_by_last_action?.should == expect_updated? end end end |