summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2016-02-24 21:18:40 -0800
committerJay Mundrawala <jdmundrawala@gmail.com>2016-02-24 22:17:55 -0800
commit158178c3e039f3fcf0726fe3c7873bd80685f787 (patch)
tree58ef4f26f083b7bc053502b2be16d0b922f0c06c
parentcbb0f567ba9fa669a43761c6e2452734fa9a3fd5 (diff)
downloadchef-158178c3e039f3fcf0726fe3c7873bd80685f787.tar.gz
Add test for solo.d
This commit refactors the spec to use shared examples as the test for client.d and solo.d is the same. knife.d is a little special so it cannot use this.
-rw-r--r--spec/support/shared/unit/application_dot_d.rb70
-rw-r--r--spec/unit/application/client_spec.rb54
-rw-r--r--spec/unit/application/solo_spec.rb3
3 files changed, 75 insertions, 52 deletions
diff --git a/spec/support/shared/unit/application_dot_d.rb b/spec/support/shared/unit/application_dot_d.rb
new file mode 100644
index 0000000000..a8769d6d03
--- /dev/null
+++ b/spec/support/shared/unit/application_dot_d.rb
@@ -0,0 +1,70 @@
+#
+# Copyright:: Copyright 2016, Chef Software, Inc.
+# 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.
+#
+
+shared_examples_for "an application that loads a dot d" do
+ before do
+ Chef::Config[dot_d_config_name] = client_d_dir
+ end
+
+ context "when client_d_dir is set to nil" do
+ let(:client_d_dir) { nil }
+
+ it "does not raise an exception" do
+ expect { app.reconfigure }.not_to raise_error
+ end
+ end
+
+ context "when client_d_dir is set to a directory with configuration" do
+ # We're not going to mock out globbing the directory. We want to
+ # make sure that we are correctly globbing.
+ let(:client_d_dir) { Chef::Util::PathHelper.cleanpath(
+ File.join(File.dirname(__FILE__), "../../../data/client.d_00")) }
+
+ it "loads the configuration in order" do
+ expect(IO).to receive(:read).with(Pathname.new("#{client_d_dir}/00-foo.rb").cleanpath.to_s).and_return("foo 0")
+ expect(IO).to receive(:read).with(Pathname.new("#{client_d_dir}/01-bar.rb").cleanpath.to_s).and_return("bar 0")
+ allow(app).to receive(:apply_config).with(anything(), Chef::Config.platform_specific_path("/etc/chef/client.rb")).and_call_original.ordered
+ expect(app).to receive(:apply_config).with("foo 0", Pathname.new("#{client_d_dir}/00-foo.rb").cleanpath.to_s).and_call_original.ordered
+ expect(app).to receive(:apply_config).with("bar 0", Pathname.new("#{client_d_dir}/01-bar.rb").cleanpath.to_s).and_call_original.ordered
+ app.reconfigure
+ end
+ end
+
+ context "when client_d_dir is set to a directory without configuration" do
+ let(:client_d_dir) { Chef::Util::PathHelper.cleanpath(
+ File.join(File.dirname(__FILE__), "../../data/client.d_01")) }
+
+ # client.d_01 has a nested folder with a rb file that if
+ # executed, would raise an exception. If it is executed,
+ # it means we are loading configs that are deeply nested
+ # inside of client.d. For example, client.d/foo/bar.rb
+ # should not run, but client.d/foo.rb should.
+ it "does not raise an exception" do
+ expect { app.reconfigure }.not_to raise_error
+ end
+ end
+
+ context "when client_d_dir is set to a directory containing a directory named foo.rb" do
+ # foo.rb as a directory should be ignored
+ let(:client_d_dir) { Chef::Util::PathHelper.cleanpath(
+ File.join(File.dirname(__FILE__), "../../data/client.d_02")) }
+
+ it "does not raise an exception" do
+ expect { app.reconfigure }.not_to raise_error
+ end
+ end
+end
diff --git a/spec/unit/application/client_spec.rb b/spec/unit/application/client_spec.rb
index f742d24e24..97a297ccb5 100644
--- a/spec/unit/application/client_spec.rb
+++ b/spec/unit/application/client_spec.rb
@@ -258,58 +258,8 @@ Enable chef-client interval runs by setting `:client_fork = true` in your config
end
end
- describe "client.d" do
- before do
- Chef::Config[:client_d_dir] = client_d_dir
- end
-
- context "when client_d_dir is set to nil" do
- let(:client_d_dir) { nil }
-
- it "does not raise an exception" do
- expect { app.reconfigure }.not_to raise_error
- end
- end
-
- context "when client_d_dir is set to a directory with configuration" do
- # We're not going to mock out globbing the directory. We want to
- # make sure that we are correctly globbing.
- let(:client_d_dir) { Chef::Util::PathHelper.cleanpath(
- File.join(File.dirname(__FILE__), "../../data/client.d_00")) }
-
- it "loads the configuration in order" do
- expect(IO).to receive(:read).with(Pathname.new("#{client_d_dir}/00-foo.rb").cleanpath.to_s).and_return("foo 0")
- expect(IO).to receive(:read).with(Pathname.new("#{client_d_dir}/01-bar.rb").cleanpath.to_s).and_return("bar 0")
- allow(app).to receive(:apply_config).with(anything(), Chef::Config.platform_specific_path("/etc/chef/client.rb")).and_call_original.ordered
- expect(app).to receive(:apply_config).with("foo 0", Pathname.new("#{client_d_dir}/00-foo.rb").cleanpath.to_s).and_call_original.ordered
- expect(app).to receive(:apply_config).with("bar 0", Pathname.new("#{client_d_dir}/01-bar.rb").cleanpath.to_s).and_call_original.ordered
- app.reconfigure
- end
- end
-
- context "when client_d_dir is set to a directory without configuration" do
- let(:client_d_dir) { Chef::Util::PathHelper.cleanpath(
- File.join(File.dirname(__FILE__), "../../data/client.d_01")) }
-
- # client.d_01 has a nested folder with a rb file that if
- # executed, would raise an exception. If it is executed,
- # it means we are loading configs that are deeply nested
- # inside of client.d. For example, client.d/foo/bar.rb
- # should not run, but client.d/foo.rb should.
- it "does not raise an exception" do
- expect { app.reconfigure }.not_to raise_error
- end
- end
-
- context "when client_d_dir is set to a directory containing a directory named foo.rb" do
- # foo.rb as a directory should be ignored
- let(:client_d_dir) { Chef::Util::PathHelper.cleanpath(
- File.join(File.dirname(__FILE__), "../../data/client.d_02")) }
-
- it "does not raise an exception" do
- expect { app.reconfigure }.not_to raise_error
- end
- end
+ it_behaves_like "an application that loads a dot d" do
+ let(:dot_d_config_name) { :client_d_dir }
end
end
diff --git a/spec/unit/application/solo_spec.rb b/spec/unit/application/solo_spec.rb
index 4361a2cd33..85799d73db 100644
--- a/spec/unit/application/solo_spec.rb
+++ b/spec/unit/application/solo_spec.rb
@@ -164,4 +164,7 @@ Enable chef-client interval runs by setting `:client_fork = true` in your config
end
end
+ it_behaves_like "an application that loads a dot d" do
+ let(:dot_d_config_name) { :solo_d_dir }
+ end
end