summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/data/client.d_00/00-foo.rb2
-rw-r--r--spec/data/client.d_00/01-bar.rb1
-rw-r--r--spec/data/client.d_00/bar1
-rw-r--r--spec/data/client.d_01/foo/bar.rb1
-rw-r--r--spec/data/client.d_02/foo.rb/foo.txt1
-rw-r--r--spec/support/shared/unit/application_dot_d.rb70
-rw-r--r--spec/unit/application/client_spec.rb4
-rw-r--r--spec/unit/application/solo_spec.rb3
-rw-r--r--spec/unit/knife/bootstrap_spec.rb49
-rw-r--r--spec/unit/mixin/path_sanity_spec.rb6
10 files changed, 138 insertions, 0 deletions
diff --git a/spec/data/client.d_00/00-foo.rb b/spec/data/client.d_00/00-foo.rb
new file mode 100644
index 0000000000..44a763aca1
--- /dev/null
+++ b/spec/data/client.d_00/00-foo.rb
@@ -0,0 +1,2 @@
+# 00-foo.rb
+# d6f9b976-289c-4149-baf7-81e6ffecf228
diff --git a/spec/data/client.d_00/01-bar.rb b/spec/data/client.d_00/01-bar.rb
new file mode 100644
index 0000000000..73f91386bc
--- /dev/null
+++ b/spec/data/client.d_00/01-bar.rb
@@ -0,0 +1 @@
+# 01-bar.rb
diff --git a/spec/data/client.d_00/bar b/spec/data/client.d_00/bar
new file mode 100644
index 0000000000..72dca4d5e4
--- /dev/null
+++ b/spec/data/client.d_00/bar
@@ -0,0 +1 @@
+1 / 0
diff --git a/spec/data/client.d_01/foo/bar.rb b/spec/data/client.d_01/foo/bar.rb
new file mode 100644
index 0000000000..72dca4d5e4
--- /dev/null
+++ b/spec/data/client.d_01/foo/bar.rb
@@ -0,0 +1 @@
+1 / 0
diff --git a/spec/data/client.d_02/foo.rb/foo.txt b/spec/data/client.d_02/foo.rb/foo.txt
new file mode 100644
index 0000000000..d724c93bef
--- /dev/null
+++ b/spec/data/client.d_02/foo.rb/foo.txt
@@ -0,0 +1 @@
+# foo.txt
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 ff6f460c13..97a297ccb5 100644
--- a/spec/unit/application/client_spec.rb
+++ b/spec/unit/application/client_spec.rb
@@ -257,6 +257,10 @@ Enable chef-client interval runs by setting `:client_fork = true` in your config
expect { app.reconfigure }.to raise_error(Chef::Exceptions::PIDFileLockfileMatch)
end
end
+
+ it_behaves_like "an application that loads a dot d" do
+ let(:dot_d_config_name) { :client_d_dir }
+ end
end
describe Chef::Application::Client, "setup_application" do
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
diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb
index 3425b94c76..8ad5c338c3 100644
--- a/spec/unit/knife/bootstrap_spec.rb
+++ b/spec/unit/knife/bootstrap_spec.rb
@@ -458,6 +458,55 @@ describe Chef::Knife::Bootstrap do
end
end
+ describe "when transferring client.d" do
+
+ let(:rendered_template) do
+ knife.merge_configs
+ knife.render_template
+ end
+
+ before do
+ Chef::Config[:client_d_dir] = client_d_dir
+ end
+
+ context "when client_d_dir is nil" do
+ let(:client_d_dir) { nil }
+
+ it "does not create /etc/chef/client.d" do
+ expect(rendered_template).not_to match(%r{mkdir -p /etc/chef/client\.d})
+ end
+ end
+
+ context "when client_d_dir is set" do
+ let(:client_d_dir) { Chef::Util::PathHelper.cleanpath(
+ File.join(File.dirname(__FILE__), "../../data/client.d_00")) }
+
+ it "creates /etc/chef/client.d" do
+ expect(rendered_template).to match("mkdir -p /etc/chef/client\.d")
+ end
+
+ context "a flat directory structure" do
+ it "creates a file 00-foo.rb" do
+ expect(rendered_template).to match("cat > /etc/chef/client.d/00-foo.rb <<'EOP'")
+ expect(rendered_template).to match("d6f9b976-289c-4149-baf7-81e6ffecf228")
+ end
+ it "creates a file bar" do
+ expect(rendered_template).to match("cat > /etc/chef/client.d/bar <<'EOP'")
+ expect(rendered_template).to match("1 / 0")
+ end
+ end
+
+ context "a nested directory structure" do
+ let(:client_d_dir) { Chef::Util::PathHelper.cleanpath(
+ File.join(File.dirname(__FILE__), "../../data/client.d_01")) }
+ it "creates a file foo/bar.rb" do
+ expect(rendered_template).to match("cat > /etc/chef/client.d/foo/bar.rb <<'EOP'")
+ expect(rendered_template).to match("1 / 0")
+ end
+ end
+ end
+ end
+
describe "handling policyfile options" do
context "when only policy_name is given" do
diff --git a/spec/unit/mixin/path_sanity_spec.rb b/spec/unit/mixin/path_sanity_spec.rb
index e410f034d5..2c26e2fb79 100644
--- a/spec/unit/mixin/path_sanity_spec.rb
+++ b/spec/unit/mixin/path_sanity_spec.rb
@@ -56,6 +56,12 @@ describe Chef::Mixin::PathSanity do
expect(env["PATH"]).to eq("/usr/bin:/sbin:/bin:#{@ruby_bindir}:#{@gem_bindir}:/usr/local/sbin:/usr/local/bin:/usr/sbin")
end
+ it "creates path with utf-8 encoding" do
+ env = { "PATH" => "/usr/bin:/sbin:/bin:/b\x81t".force_encoding("ISO-8859-1") }
+ @sanity.enforce_path_sanity(env)
+ expect(env["PATH"].encoding.to_s).to eq("UTF-8")
+ end
+
it "adds the current executing Ruby's bindir and Gem bindir to the PATH" do
env = { "PATH" => "" }
@sanity.enforce_path_sanity(env)