summaryrefslogtreecommitdiff
path: root/chef-config/spec
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2016-02-08 12:07:33 -0800
committerJay Mundrawala <jdmundrawala@gmail.com>2016-02-24 21:24:14 -0800
commit352c98ee1f50cf3d18f341e48b5fe3214e5afda5 (patch)
tree6542ad560f1f2f1006c5c4838d6bd897ab21efbc /chef-config/spec
parent9cfe82b9af36c92457598f857cba5671a1e24ef2 (diff)
downloadchef-352c98ee1f50cf3d18f341e48b5fe3214e5afda5.tar.gz
Allow the workstation config to load a conf.d directory
This will behave similarly to the client.d directory. The top-level ruby files will be loaded in sorted order.
Diffstat (limited to 'chef-config/spec')
-rw-r--r--chef-config/spec/unit/workstation_config_loader_spec.rb81
1 files changed, 79 insertions, 2 deletions
diff --git a/chef-config/spec/unit/workstation_config_loader_spec.rb b/chef-config/spec/unit/workstation_config_loader_spec.rb
index df53f87de9..cae9ce4304 100644
--- a/chef-config/spec/unit/workstation_config_loader_spec.rb
+++ b/chef-config/spec/unit/workstation_config_loader_spec.rb
@@ -35,6 +35,12 @@ RSpec.describe ChefConfig::WorkstationConfigLoader do
end
end
+ before do
+ # We set this to nil so that a dev workstation will
+ # not interfere with the tests.
+ ChefConfig::Config[:conf_d_dir] = nil
+ end
+
# Test methods that do I/O or reference external state which are stubbed out
# elsewhere.
describe "external dependencies" do
@@ -215,7 +221,8 @@ RSpec.describe ChefConfig::WorkstationConfigLoader do
it "skips loading" do
expect(config_loader.config_location).to be(nil)
- expect(config_loader.load).to be(false)
+ expect(config_loader).not_to receive(:read_config)
+ config_loader.load
end
end
@@ -254,7 +261,8 @@ RSpec.describe ChefConfig::WorkstationConfigLoader do
let(:config_content) { "config_file_evaluated(true)" }
it "loads the config" do
- expect(config_loader.load).to be(true)
+ expect(config_loader).to receive(:read_config).and_call_original
+ config_loader.load
expect(ChefConfig::Config.config_file_evaluated).to be(true)
end
@@ -286,4 +294,73 @@ RSpec.describe ChefConfig::WorkstationConfigLoader do
end
+ describe "when loading config.d" do
+ context "when the conf.d directory exists" do
+ let(:config_content) { "" }
+
+ let(:tempdir) { Dir.mktmpdir("chef-workstation-test") }
+
+ let!(:confd_file) do
+ Tempfile.new(["Chef-WorkstationConfigLoader-rspec-test", ".rb"], tempdir).tap do |t|
+ t.print(config_content)
+ t.close
+ end
+ end
+
+ before do
+ ChefConfig::Config[:conf_d_dir] = tempdir
+ allow(config_loader).to receive(:path_exists?).with(
+ an_instance_of(String)).and_return(false)
+ end
+
+ after do
+ FileUtils.remove_entry_secure tempdir
+ end
+
+ context "and is valid" do
+ let(:config_content) { "config_d_file_evaluated(true)" }
+
+ it "loads the config" do
+ expect(config_loader).to receive(:read_config).and_call_original
+ config_loader.load
+ expect(ChefConfig::Config.config_d_file_evaluated).to be(true)
+ end
+ end
+
+ context "and has a syntax error" do
+ let(:config_content) { "{{{{{:{{" }
+
+ it "raises a ConfigurationError" do
+ expect { config_loader.load }.to raise_error(ChefConfig::ConfigurationError)
+ end
+ end
+
+ context "has a non rb file" do
+ let(:sytax_error_content) { "{{{{{:{{" }
+ let(:config_content) { "config_d_file_evaluated(true)" }
+
+ let!(:not_confd_file) do
+ Tempfile.new(["Chef-WorkstationConfigLoader-rspec-test", ".foorb"], tempdir).tap do |t|
+ t.print(sytax_error_content)
+ t.close
+ end
+ end
+
+ it "does not load the non rb file" do
+ expect { config_loader.load }.not_to raise_error
+ expect(ChefConfig::Config.config_d_file_evaluated).to be(true)
+ end
+ end
+ end
+
+ context "when the conf.d directory does not exist" do
+ before do
+ ChefConfig::Config[:conf_d_dir] = "/nope/nope/nope/nope/notdoingit"
+ end
+
+ it "does not load anything" do
+ expect(config_loader).not_to receive(:read_config)
+ end
+ end
+ end
end