From d67cede51f4d3636de55c44fb7e9d36f5fb640e0 Mon Sep 17 00:00:00 2001 From: Bryan McLellan Date: Wed, 18 Mar 2020 20:18:00 -0400 Subject: Simplify YAML mode checking for chef-apply Signed-off-by: Bryan McLellan --- lib/chef/application/apply.rb | 7 ++----- spec/unit/application/apply_spec.rb | 14 -------------- 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 -- cgit v1.2.1