diff options
author | dheerajd-msys <dheeraj.dubey@msystechnologies.com> | 2016-11-21 15:13:52 +0530 |
---|---|---|
committer | dheerajd-msys <dheeraj.dubey@msystechnologies.com> | 2016-11-22 12:31:46 +0530 |
commit | 63a6d5e5f24e26662d520b366b8604b81b757c3a (patch) | |
tree | 331d89398a3e98e59f74e5570c4ffe7669a68737 | |
parent | 0c0ccba6a97b1a5147e1f3c9891bcf9d15ef7d4b (diff) | |
download | chef-63a6d5e5f24e26662d520b366b8604b81b757c3a.tar.gz |
Added specs for config_log_location
Signed-off-by: dheerajd-msys <dheeraj.dubey@msystechnologies.com>
-rw-r--r-- | lib/chef/knife/core/bootstrap_context.rb | 12 | ||||
-rw-r--r-- | spec/unit/knife/core/bootstrap_context_spec.rb | 55 |
2 files changed, 58 insertions, 9 deletions
diff --git a/lib/chef/knife/core/bootstrap_context.rb b/lib/chef/knife/core/bootstrap_context.rb index cc9c6c4903..ceb067d48d 100644 --- a/lib/chef/knife/core/bootstrap_context.rb +++ b/lib/chef/knife/core/bootstrap_context.rb @@ -68,25 +68,23 @@ class Chef end def get_log_location - if (@chef_config[:config_log_location].nil? || @chef_config[:config_log_location].empty?) + if !(@chef_config[:config_log_location].class == IO ) && (@chef_config[:config_log_location].nil? || @chef_config[:config_log_location].to_s.empty?) "STDOUT" elsif @chef_config[:config_log_location].equal?(:win_evt) - raise "The value \:win_evt is not supported for config_log_location on Linux Platforms \n" + raise "The value :win_evt is not supported for config_log_location on Linux Platforms \n" elsif @chef_config[:config_log_location].equal?(:syslog) ":syslog" - elsif (@chef_config[:config_log_location].equal?(STDOUT)) + elsif @chef_config[:config_log_location].equal?(STDOUT) "STDOUT" - elsif (@chef_config[:config_log_location].equal?(STDERR)) + elsif @chef_config[:config_log_location].equal?(STDERR) "STDERR" elsif @chef_config[:config_log_location] - %Q{"#{@chef_config[:config_log_location]}"} + %Q{"#{@chef_config[:config_log_location]}"} else "STDOUT" end end - - def config_content client_rb = <<-CONFIG chef_server_url "#{@chef_config[:chef_server_url]}" diff --git a/spec/unit/knife/core/bootstrap_context_spec.rb b/spec/unit/knife/core/bootstrap_context_spec.rb index dc3a33a9ca..515381cf6e 100644 --- a/spec/unit/knife/core/bootstrap_context_spec.rb +++ b/spec/unit/knife/core/bootstrap_context_spec.rb @@ -70,10 +70,10 @@ describe Chef::Knife::Core::BootstrapContext do it "generates the config file data" do expected = <<-EXPECTED -log_level :info -log_location "/tmp/log" chef_server_url "http://chef.example.com:4444" validation_client_name "chef-validator-testing" +log_level :info +log_location "/tmp/log" # Using default node name (fqdn) EXPECTED expect(bootstrap_context.config_content).to eq expected @@ -253,4 +253,55 @@ EXPECTED end end + describe "#config_log_location" do + context "when config_log_location is nil" do + let(:chef_config) { { :config_log_location => nil } } + it "sets the default config_log_location in the client.rb" do + expect(bootstrap_context.get_log_location).to eq "STDOUT" + end + end + + context "when config_log_location is empty" do + let(:chef_config) { { :config_log_location => "" } } + it "sets the default config_log_location in the client.rb" do + expect(bootstrap_context.get_log_location).to eq "STDOUT" + end + end + + context "when config_log_location is :win_evt" do + let(:chef_config) { { :config_log_location => :win_evt } } + it "raise error when config_log_location is :win_evt " do + expect { bootstrap_context.get_log_location }.to raise_error("The value :win_evt is not supported for config_log_location on Linux Platforms \n") + end + end + + context "when config_log_location is :syslog" do + let(:chef_config) { { :config_log_location => :syslog } } + it "sets the config_log_location value as :syslog in the client.rb" do + expect(bootstrap_context.get_log_location).to eq ":syslog" + end + end + + context "When config_log_location is STDOUT" do + let(:chef_config) { { :config_log_location => STDOUT } } + it "Sets the config_log_location value as STDOUT in the client.rb" do + expect(bootstrap_context.get_log_location).to eq "STDOUT" + end + end + + context "when config_log_location is STDERR" do + let(:chef_config) { { :config_log_location => STDERR } } + it "sets the config_log_location value as STDERR in the client.rb" do + expect(bootstrap_context.get_log_location).to eq "STDERR" + end + end + + context "when config_log_location is a path" do + let(:chef_config) { { :config_log_location => "/tmp/ChefLogFile" } } + it "sets the config_log_location path in the client.rb" do + expect(bootstrap_context.get_log_location).to eq "\"/tmp/ChefLogFile\"" + end + end + + end end |