summaryrefslogtreecommitdiff
path: root/spec/unit/application
diff options
context:
space:
mode:
authorAdam Bewsher <adam.bewsher@neos.co.uk>2019-03-14 12:52:23 +0000
committerAdam Bewsher <adam.bewsher@neos.co.uk>2019-03-15 10:51:42 +0000
commit8d9d18672d9f124d5f702474680ee2c25f43ee35 (patch)
treee5d74cb8010802b9a5d7ac8472121170b49e8a58 /spec/unit/application
parente26d943ab7958a88161f3c5959fad29aa8ed8b36 (diff)
downloadchef-8d9d18672d9f124d5f702474680ee2c25f43ee35.tar.gz
fix undefined local variable 'recipes_path'
Developer's Certificate of Origin 1.1 By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as Indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. Signed-off-by: Adam Bewsher <adam.bewsher@neos.co.uk>
Diffstat (limited to 'spec/unit/application')
-rw-r--r--spec/unit/application/client_spec.rb107
1 files changed, 106 insertions, 1 deletions
diff --git a/spec/unit/application/client_spec.rb b/spec/unit/application/client_spec.rb
index f58d1ed079..f971848c5b 100644
--- a/spec/unit/application/client_spec.rb
+++ b/spec/unit/application/client_spec.rb
@@ -91,7 +91,7 @@ describe Chef::Application::Client, "reconfigure" do
# protect the unit tests against accidental --delete-entire-chef-repo from firing
# for real during tests. DO NOT delete this line.
- expect(FileUtils).not_to receive(:rm_rf)
+ allow(FileUtils).to receive(:rm_rf)
end
after do
@@ -207,6 +207,111 @@ describe Chef::Application::Client, "reconfigure" do
end
end
end
+
+ describe "--recipe-url and --local-mode" do
+ let(:archive) { double }
+ let(:config_exists) { false }
+
+ before do
+ allow(Chef::Config).to receive(:chef_repo_path).and_return("the_path_to_the_repo")
+ allow(FileUtils).to receive(:rm_rf)
+ allow(FileUtils).to receive(:mkdir_p)
+ allow(app).to receive(:fetch_recipe_tarball)
+ allow(Mixlib::Archive).to receive(:new).and_return(archive)
+ allow(archive).to receive(:extract)
+ allow(Chef::Config).to receive(:from_string)
+ allow(IO).to receive(:read).with(File.join("the_path_to_the_repo", ".chef/config.rb")).and_return("new_config")
+ allow(File).to receive(:file?).with(File.join("the_path_to_the_repo", ".chef/config.rb")).and_return(config_exists)
+ end
+
+ context "local mode not set" do
+ it "fails with a message stating local mode required" do
+ expect(Chef::Application).to receive(:fatal!).with("chef-client recipe-url can be used only in local-mode").and_raise("error occured")
+ ARGV.replace(["--recipe-url=test_url"])
+ expect { app.reconfigure }.to raise_error "error occured"
+ end
+ end
+
+ context "local mode set" do
+ before do
+ ARGV.replace(["--local-mode", "--recipe-url=test_url"])
+ end
+
+ context "--delete-entire-chef-repo" do
+ before do
+ ARGV.replace(["--local-mode", "--recipe-url=test_url", "--delete-entire-chef-repo"])
+ end
+
+ it "deletes the repo" do
+ expect(FileUtils).to receive(:rm_rf)
+ .with("the_path_to_the_repo", secure: true)
+
+ app.reconfigure
+ end
+ end
+
+ it "does not delete the repo" do
+ expect(FileUtils).not_to receive(:rm_rf)
+
+ app.reconfigure
+ end
+
+ it "sets { recipe_url: 'test_url' }" do
+ app.reconfigure
+
+ expect(Chef::Config.configuration).to include recipe_url: "test_url"
+ end
+
+ it "makes the repo path" do
+ expect(FileUtils).to receive(:mkdir_p)
+ .with("the_path_to_the_repo")
+
+ app.reconfigure
+ end
+
+ it "fetches the tarball" do
+ expect(app).to receive(:fetch_recipe_tarball)
+ .with("test_url", File.join("the_path_to_the_repo", "recipes.tgz"))
+
+ app.reconfigure
+ end
+
+ it "extracts the archive" do
+ expect(Mixlib::Archive).to receive(:new)
+ .with(File.join("the_path_to_the_repo", "recipes.tgz"))
+ .and_return(archive)
+
+ expect(archive).to receive(:extract)
+ .with("the_path_to_the_repo", perms: false, ignore: /^\.$/)
+
+ app.reconfigure
+ end
+
+ context "when there is new config" do
+ let(:config_exists) { true }
+
+ it "updates the config from the extracted config" do
+ expect(Chef::Config).to receive(:from_string)
+ .with(
+ "new_config",
+ File.join("the_path_to_the_repo", ".chef/config.rb")
+ )
+
+ app.reconfigure
+ end
+ end
+
+ context "when there is no new config" do
+ let(:config_exists) { false }
+
+ it "does not updates the config" do
+ expect(Chef::Config).not_to receive(:from_string)
+
+ app.reconfigure
+ end
+ end
+ end
+ end
end
describe "when configured to not fork the client process" do