summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorNoah Kantrowitz <noah@coderanger.net>2017-04-04 22:02:51 -0700
committerNoah Kantrowitz <noah@coderanger.net>2017-04-04 22:02:51 -0700
commitf51d16101dd244046bece8721861c1aad332bca0 (patch)
tree62884b53d97c31f2aa0323ab7ad05e4e36297001 /spec
parent1148f3319ca93e99e209443fc2823d09a6fb695c (diff)
downloadchef-f51d16101dd244046bece8721861c1aad332bca0.tar.gz
First pass on implementing root aliases.
Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
Diffstat (limited to 'spec')
-rw-r--r--spec/data/cookbooks/aliased/attributes.rb1
-rw-r--r--spec/data/cookbooks/aliased/metadata.rb2
-rw-r--r--spec/data/cookbooks/aliased/recipe.rb3
-rw-r--r--spec/functional/root_alias_spec.rb53
4 files changed, 59 insertions, 0 deletions
diff --git a/spec/data/cookbooks/aliased/attributes.rb b/spec/data/cookbooks/aliased/attributes.rb
new file mode 100644
index 0000000000..3a3bab96e1
--- /dev/null
+++ b/spec/data/cookbooks/aliased/attributes.rb
@@ -0,0 +1 @@
+default["aliased"]["attr"] = "value"
diff --git a/spec/data/cookbooks/aliased/metadata.rb b/spec/data/cookbooks/aliased/metadata.rb
new file mode 100644
index 0000000000..e3b2b96177
--- /dev/null
+++ b/spec/data/cookbooks/aliased/metadata.rb
@@ -0,0 +1,2 @@
+name "aliased"
+version "1.0.0"
diff --git a/spec/data/cookbooks/aliased/recipe.rb b/spec/data/cookbooks/aliased/recipe.rb
new file mode 100644
index 0000000000..d82e58fbcd
--- /dev/null
+++ b/spec/data/cookbooks/aliased/recipe.rb
@@ -0,0 +1,3 @@
+ruby_block "root alias" do
+ block { }
+end
diff --git a/spec/functional/root_alias_spec.rb b/spec/functional/root_alias_spec.rb
new file mode 100644
index 0000000000..6c08877be4
--- /dev/null
+++ b/spec/functional/root_alias_spec.rb
@@ -0,0 +1,53 @@
+#
+# Copyright:: Copyright 2017, Noah Kantrowitz
+# 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"
+
+describe "root aliases" do
+ let(:chef_repo_path) { File.expand_path(File.join(CHEF_SPEC_DATA, "cookbooks")) }
+ let(:cookbook_collection) do
+ cl = Chef::CookbookLoader.new(chef_repo_path)
+ cl.load_cookbooks
+ Chef::CookbookCollection.new(cl)
+ end
+ let(:node) do
+ node = Chef::Node.new
+ node.run_list << "aliased"
+ node.automatic[:recipes] = []
+ node
+ end
+ let(:events) { Chef::EventDispatch::Dispatcher.new }
+ let(:run_context) { Chef::RunContext.new(node, cookbook_collection, events) }
+ before do
+ node.run_context = run_context
+ end
+
+ describe "attributes root aliases" do
+ it "should load attributes.rb" do
+ node.include_attribute("aliased")
+ expect(node["aliased"]["attr"]).to eq "value"
+ end
+ end
+
+ describe "recipe root aliased" do
+ it "should load recipe.rb" do
+ run_context.load(node.run_list.expand("_default"))
+ run_context.include_recipe("aliased")
+ expect(run_context.resource_collection.map(&:to_s)).to eq ["ruby_block[root alias]"]
+ end
+ end
+end