spec/unit/provider/template_spec.rb in chef-10.34.6 vs spec/unit/provider/template_spec.rb in chef-11.0.0.beta.0
- old
+ new
@@ -24,11 +24,13 @@
before(:each) do
@cookbook_repo = File.expand_path(File.join(CHEF_SPEC_DATA, "cookbooks"))
Chef::Cookbook::FileVendor.on_create { |manifest| Chef::Cookbook::FileSystemFileVendor.new(manifest, @cookbook_repo) }
@node = Chef::Node.new
- @cookbook_collection = Chef::CookbookCollection.new(Chef::CookbookLoader.new(@cookbook_repo))
+ cl = Chef::CookbookLoader.new(@cookbook_repo)
+ cl.load_cookbooks
+ @cookbook_collection = Chef::CookbookCollection.new(cl)
@events = Chef::EventDispatch::Dispatcher.new
@run_context = Chef::RunContext.new(@node, @cookbook_collection, @events)
@rendered_file_location = Dir.tmpdir + '/openldap_stuff.conf'
@@ -43,20 +45,20 @@
passwd_struct = if windows?
Struct::Passwd.new("root", "x", 0, 0, "/root", "/bin/bash")
else
Struct::Passwd.new("root", "x", 0, 0, "root", "/root", "/bin/bash")
end
- group_struct = OpenStruct.new(:name => "root", :passwd => "x", :gid => 0)
+ group_struct = mock("Group Ent", :name => "root", :passwd => "x", :gid => 0)
Etc.stub!(:getpwuid).and_return(passwd_struct)
Etc.stub!(:getgrgid).and_return(group_struct)
end
describe "when creating the template" do
- before do
-
+ before do
end
+
after do
FileUtils.rm(@rendered_file_location) if ::File.exist?(@rendered_file_location)
end
it "finds the template file in the coobook cache if it isn't local" do
@@ -85,11 +87,11 @@
describe "when the target file does not exist" do
it "creates the template with the rendered content" do
@access_controls.stub!(:requires_changes?).and_return(true)
@access_controls.should_receive(:set_all!)
- @node[:slappiness] = "a warm gun"
+ @node.normal[:slappiness] = "a warm gun"
@provider.should_receive(:backup)
@provider.run_action(:create)
IO.read(@rendered_file_location).should == "slappiness is a warm gun"
@resource.should be_updated_by_last_action
end
@@ -105,25 +107,48 @@
end
it "creates the template with the rendered content for the create if missing action" do
@access_controls.stub!(:requires_changes?).and_return(true)
@access_controls.should_receive(:set_all!)
- @node[:slappiness] = "happiness"
+ @node.normal[:slappiness] = "happiness"
@provider.should_receive(:backup)
@provider.run_action(:create_if_missing)
IO.read(@rendered_file_location).should == "slappiness is happiness"
@resource.should be_updated_by_last_action
end
+
+ context "and no access control settings are set on the resource" do
+ context "on a Unix system" do
+ before do
+ Chef::Platform.stub!(:windows?).and_return(false)
+ end
+
+ it "sets access control metadata on the new resource" do
+ @access_controls.stub!(:requires_changes?).and_return(false)
+ @access_controls.should_receive(:set_all!)
+ @node.normal[:slappiness] = "happiness"
+ @provider.should_receive(:backup)
+ @provider.run_action(:create)
+ IO.read(@rendered_file_location).should == "slappiness is happiness"
+ @resource.should be_updated_by_last_action
+
+ # Veracity of actual data checked in functional tests
+ @resource.owner.should be_a_kind_of(String)
+ @resource.group.should be_a_kind_of(String)
+ @resource.mode.should be_a_kind_of(String)
+ end
+ end
+ end
end
describe "when the target file has the wrong content" do
before do
File.open(@rendered_file_location, "w+") { |f| f.print "blargh" }
end
it "overwrites the file with the updated content when the create action is run" do
- @node[:slappiness] = "a warm gun"
+ @node.normal[:slappiness] = "a warm gun"
@access_controls.stub!(:requires_changes?).and_return(false)
@access_controls.should_receive(:set_all!)
@provider.should_receive(:backup)
@provider.run_action(:create)
IO.read(@rendered_file_location).should == "slappiness is a warm gun"
@@ -142,37 +167,36 @@
end
it "doesn't overwrite the file when the create if missing action is run" do
@access_controls.stub!(:requires_changes?).and_return(false)
@access_controls.should_not_receive(:set_all!)
- @node[:slappiness] = "a warm gun"
+ @node.normal[:slappiness] = "a warm gun"
@provider.should_not_receive(:backup)
@provider.run_action(:create_if_missing)
IO.read(@rendered_file_location).should == "blargh"
@resource.should_not be_updated_by_last_action
end
end
describe "when the target has the correct content" do
before do
- Chef::ChecksumCache.instance.reset!
File.open(@rendered_file_location, "w") { |f| f.print "slappiness is a warm gun" }
@current_resource.checksum('4ff94a87794ed9aefe88e734df5a66fc8727a179e9496cbd88e3b5ec762a5ee9')
@access_controls = mock("access controls")
@provider.stub!(:access_controls).and_return(@access_controls)
end
it "does not backup the original or overwrite it" do
- @node[:slappiness] = "a warm gun"
+ @node.normal[:slappiness] = "a warm gun"
@access_controls.stub!(:requires_changes?).and_return(false)
@provider.should_not_receive(:backup)
FileUtils.should_not_receive(:mv)
@provider.run_action(:create)
@resource.should_not be_updated_by_last_action
end
it "does not backup the original or overwrite it on create if missing" do
- @node[:slappiness] = "a warm gun"
+ @node.normal[:slappiness] = "a warm gun"
@access_controls.stub!(:requires_changes?).and_return(false)
@provider.should_not_receive(:backup)
FileUtils.should_not_receive(:mv)
@provider.run_action(:create)
@resource.should_not be_updated_by_last_action