summaryrefslogtreecommitdiff
path: root/spec/unit/client_spec.rb
diff options
context:
space:
mode:
authorsdelano <stephen@opscode.com>2017-04-06 09:21:46 -0700
committersdelano <stephen@opscode.com>2017-04-06 10:00:35 -0700
commitadb0a55cb63f394ed23450e41f8a93cd017d225a (patch)
tree0aff07ce4b93eac5d5a31641596ea20653867bcd /spec/unit/client_spec.rb
parentc36bf3013e7c1f54efc6635145a5fb28daf17c7a (diff)
downloadchef-adb0a55cb63f394ed23450e41f8a93cd017d225a.tar.gz
server enforced required recipe
when the chef-server is configured to serve a requried recipe, chef-client shall load the recipe into the run context and execute it as part of the converge phase. if the chef-server is NOT configured, it will return a 404 and chef-client will continue normally. Signed-off-by: Stephen Delano <stephen@chef.io>
Diffstat (limited to 'spec/unit/client_spec.rb')
-rw-r--r--spec/unit/client_spec.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb
index a2bb573e15..528dbd4b4e 100644
--- a/spec/unit/client_spec.rb
+++ b/spec/unit/client_spec.rb
@@ -394,6 +394,55 @@ describe Chef::Client do
end
end
+ describe "load_required_recipe" do
+ let(:rest) { double("Chef::ServerAPI (required recipe)") }
+ let(:run_context) { double("Chef::RunContext") }
+ let(:recipe) { double("Chef::Recipe (required recipe)") }
+ let(:required_recipe) {
+ <<EOM
+fake_recipe_variable = "for reals"
+EOM
+ }
+
+ context "when required_recipe is configured" do
+
+ before(:each) do
+ expect(rest).to receive(:get).with("required_recipe").and_return(required_recipe)
+ expect(Chef::Recipe).to receive(:new).with(nil, nil, run_context).and_return(recipe)
+ expect(recipe).to receive(:from_file)
+ end
+
+ it "fetches the recipe and adds it to the run context" do
+ client.load_required_recipe(rest, run_context)
+ end
+
+ context "when the required_recipe has bad contents" do
+ let(:required_recipe) {
+ <<EOM
+this is not a recipe
+EOM
+ }
+ it "should not raise an error" do
+ expect { client.load_required_recipe(rest, run_context) }.not_to raise_error()
+ end
+ end
+ end
+
+ context "when required_recipe returns 404" do
+ let(:http_response) { Net::HTTPNotFound.new("1.1", "404", "Not Found") }
+ let(:http_exception) { Net::HTTPServerException.new('404 "Not Found"', http_response) }
+
+ before(:each) do
+ expect(rest).to receive(:get).with("required_recipe").and_raise(http_exception)
+ end
+
+ it "should log and continue on" do
+ expect(Chef::Log).to receive(:info)
+ client.load_required_recipe(rest, run_context)
+ end
+ end
+ end
+
describe "windows_admin_check" do
context "platform is not windows" do
before do