summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@loftninjas.org>2020-03-18 20:18:00 -0400
committerBryan McLellan <btm@loftninjas.org>2020-03-18 20:18:00 -0400
commitd67cede51f4d3636de55c44fb7e9d36f5fb640e0 (patch)
tree6af01f1502fffa3cf7627dd624666a0495cc6ed8
parent3aef6663aa03aec531fdecbd3b73f7c88d9a63e8 (diff)
downloadchef-btm/yaml.tar.gz
Simplify YAML mode checking for chef-applybtm/yaml
Signed-off-by: Bryan McLellan <btm@loftninjas.org>
-rw-r--r--lib/chef/application/apply.rb7
-rw-r--r--spec/unit/application/apply_spec.rb14
2 files changed, 2 insertions, 19 deletions
diff --git a/lib/chef/application/apply.rb b/lib/chef/application/apply.rb
index e242f91d29..7267f4ecfa 100644
--- a/lib/chef/application/apply.rb
+++ b/lib/chef/application/apply.rb
@@ -154,10 +154,6 @@ class Chef::Application::Apply < Chef::Application
if file_name.nil?
Chef::Application.fatal!("No recipe file was provided", Chef::Exceptions::RecipeNotFound.new)
else
- if file_name =~ /\.yml$/
- logger.info "Recipe file name ends with .yml, parsing as YAML"
- config[:yaml] = true
- end
recipe_path = File.expand_path(file_name)
unless File.exist?(recipe_path)
Chef::Application.fatal!("No file exists at #{recipe_path}", Chef::Exceptions::RecipeNotFound.new)
@@ -208,7 +204,8 @@ class Chef::Application::Apply < Chef::Application
@recipe_text, @recipe_fh = read_recipe_file @recipe_filename
end
recipe, run_context = get_recipe_and_run_context
- if config[:yaml]
+ if config[:yaml] || File.extname(@recipe_filename) == ".yml"
+ logger.info "Parsing recipe as YAML"
recipe.from_yaml(@recipe_text)
else
recipe.instance_eval(@recipe_text, @recipe_filename, 1)
diff --git a/spec/unit/application/apply_spec.rb b/spec/unit/application/apply_spec.rb
index d7927c84e1..f071dbd981 100644
--- a/spec/unit/application/apply_spec.rb
+++ b/spec/unit/application/apply_spec.rb
@@ -69,20 +69,6 @@ describe Chef::Application::Apply do
@app.read_recipe_file(@recipe_file_name)
end
end
-
- describe "when the recipe filename ends in .yml" do
- it "configures for parsing the recipe as YAML" do
- @recipe_file_name = "foo.yml"
- @recipe_path = File.expand_path(@recipe_file_name)
- @recipe_file = double("Tempfile (mock)", read: @recipe_text)
- allow(@app).to receive(:open).with(@recipe_path).and_return(@recipe_file)
- allow(File).to receive(:exist?).with(@recipe_path).and_return(true)
- allow(Chef::Application).to receive(:fatal!).and_return(true)
-
- @app.read_recipe_file(@recipe_file_name)
- expect(@app.config[:yaml]).to eq(true)
- end
- end
end
describe "temp_recipe_file" do