spec/unit/lwrp_spec.rb in chef-10.34.6 vs spec/unit/lwrp_spec.rb in chef-11.0.0.beta.0
- old
+ new
@@ -4,74 +4,49 @@
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'spec_helper'
-module LwrpConstScopingConflict
-end
-
describe "override logging" do
before :each do
$stderr.stub!(:write)
end
it "should log if attempting to load resource of same name" do
Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp", "resources", "*"))].each do |file|
- Chef::Resource.build_from_file("lwrp", file, nil)
+ Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil)
end
Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp_override", "resources", "*"))].each do |file|
Chef::Log.should_receive(:info).with(/overriding/)
- Chef::Resource.build_from_file("lwrp", file, nil)
+ Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil)
end
end
it "should log if attempting to load provider of same name" do
Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp", "providers", "*"))].each do |file|
- Chef::Provider.build_from_file("lwrp", file, nil)
+ Chef::Provider::LWRPBase.build_from_file("lwrp", file, nil)
end
Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp_override", "providers", "*"))].each do |file|
Chef::Log.should_receive(:info).with(/overriding/)
- Chef::Provider.build_from_file("lwrp", file, nil)
+ Chef::Provider::LWRPBase.build_from_file("lwrp", file, nil)
end
end
- it "removes the old LRWP resource class from the list of resource subclasses [CHEF-3432]" do
- # CHEF-3432 regression test:
- # Chef::Resource keeps a list of all subclasses to assist class inflation
- # for json parsing (see Chef::JSONCompat). When replacing LWRP resources,
- # we need to ensure the old resource class is remove from that list.
- Dir[File.expand_path( "lwrp/resources/*", CHEF_SPEC_DATA)].each do |file|
- Chef::Resource.build_from_file("lwrp", file, nil)
- end
- first_lwr_foo_class = Chef::Resource::LwrpFoo
- Chef::Resource.resource_classes.should include(first_lwr_foo_class)
- Dir[File.expand_path( "lwrp/resources/*", CHEF_SPEC_DATA)].each do |file|
- Chef::Resource.build_from_file("lwrp", file, nil)
- end
- Chef::Resource.resource_classes.should_not include(first_lwr_foo_class)
- end
-
- it "does not attempt to remove classes from higher up namespaces [CHEF-4117]" do
- conflicting_lwrp_file = File.expand_path( "lwrp_const_scoping/resources/conflict.rb", CHEF_SPEC_DATA)
- # The test is that this should not raise an error:
- Chef::Resource.build_from_file("lwrp_const_scoping", conflicting_lwrp_file, nil)
- end
-
end
describe "LWRP" do
before do
@original_VERBOSE = $VERBOSE
@@ -84,15 +59,15 @@
describe "Lightweight Chef::Resource" do
before do
Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp", "resources", "*"))].each do |file|
- Chef::Resource.build_from_file("lwrp", file, nil)
+ Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil)
end
Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp_override", "resources", "*"))].each do |file|
- Chef::Resource.build_from_file("lwrp", file, nil)
+ Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil)
end
end
it "should load the resource into a properly-named class" do
Chef::Resource.const_get("LwrpFoo").should be_kind_of(Class)
@@ -117,16 +92,16 @@
it "should build attribute methods that respect validation rules" do
lambda { Chef::Resource::LwrpFoo.new("blah").monkey(42) }.should raise_error(ArgumentError)
end
it "should have access to the run context and node during class definition" do
- node = Chef::Node.new(nil)
- node[:penguin_name] = "jackass"
+ node = Chef::Node.new
+ node.normal[:penguin_name] = "jackass"
run_context = Chef::RunContext.new(node, Chef::CookbookCollection.new, @events)
Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp", "resources_with_default_attributes", "*"))].each do |file|
- Chef::Resource.build_from_file("lwrp", file, run_context)
+ Chef::Resource::LWRPBase.build_from_file("lwrp", file, run_context)
end
cls = Chef::Resource.const_get("LwrpNodeattr")
cls.node.should be_kind_of(Chef::Node)
cls.run_context.should be_kind_of(Chef::RunContext)
@@ -136,32 +111,32 @@
end
describe "Lightweight Chef::Provider" do
before do
@node = Chef::Node.new
- @node.platform(:ubuntu)
- @node.platform_version('8.10')
+ @node.automatic[:platform] = :ubuntu
+ @node.automatic[:platform_version] = '8.10'
@events = Chef::EventDispatch::Dispatcher.new
@run_context = Chef::RunContext.new(@node, Chef::CookbookCollection.new({}), @events)
@runner = Chef::Runner.new(@run_context)
end
before(:each) do
Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp", "resources", "*"))].each do |file|
- Chef::Resource.build_from_file("lwrp", file, @run_context)
+ Chef::Resource::LWRPBase.build_from_file("lwrp", file, @run_context)
end
Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp_override", "resources", "*"))].each do |file|
- Chef::Resource.build_from_file("lwrp", file, @run_context)
+ Chef::Resource::LWRPBase.build_from_file("lwrp", file, @run_context)
end
Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp", "providers", "*"))].each do |file|
- Chef::Provider.build_from_file("lwrp", file, @run_context)
+ Chef::Provider::LWRPBase.build_from_file("lwrp", file, @run_context)
end
Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp_override", "providers", "*"))].each do |file|
- Chef::Provider.build_from_file("lwrp", file, @run_context)
+ Chef::Provider::LWRPBase.build_from_file("lwrp", file, @run_context)
end
end
it "should properly handle a new_resource reference" do
@@ -247,9 +222,51 @@
provider = Chef::Platform.provider_for_resource(resource, :twiddle_thumbs)
#provider = @runner.build_provider(resource)
provider.action_twiddle_thumbs
provider.enclosed_resource.monkey.should == 'bob, the monkey'
+ end
+
+ describe "when using inline compilation" do
+ before do
+ # Behavior in these examples depends on implementation of fixture provider.
+ # See spec/data/lwrp/providers/inline_compiler
+
+ # Side effect of lwrp_inline_compiler provider for testing notifications.
+ $interior_ruby_block_2 = nil
+ # resource type doesn't matter, so make an existing resource type work with provider.
+ @resource = Chef::Resource::LwrpFoo.new("morpheus", @run_context)
+ @resource.allowed_actions << :test
+ @resource.action(:test)
+ @resource.provider(:lwrp_inline_compiler)
+ end
+
+ it "does not add interior resources to the exterior resource collection" do
+ @resource.run_action(:test)
+ @run_context.resource_collection.should be_empty
+ end
+
+ context "when interior resources are updated" do
+ it "processes notifications within the LWRP provider's action" do
+ @resource.run_action(:test)
+ $interior_ruby_block_2.should == "executed"
+ end
+
+ it "marks the parent resource updated" do
+ @resource.run_action(:test)
+ @resource.should be_updated
+ @resource.should be_updated_by_last_action
+ end
+ end
+
+ context "when interior resources are not updated" do
+ it "does not mark the parent resource updated" do
+ @resource.run_action(:no_updates)
+ @resource.should_not be_updated
+ @resource.should_not be_updated_by_last_action
+ end
+ end
+
end
end
end