Skip to content

Commit

Permalink
Merge pull request #115 from chef/windows_chef_manifest
Browse files Browse the repository at this point in the history
Ensure chef manifest exists before trying to read it
  • Loading branch information
tyler-ball authored May 11, 2018
2 parents ad6653d + e568632 commit a38c46c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
9 changes: 3 additions & 6 deletions components/chef-cli/lib/chef-cli/target_host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,9 @@ def installed_chef_version

def get_chef_version_manifest
path = MANIFEST_PATHS[base_os()]
content = backend.file(path).content
if content
JSON.parse(content)
else
:not_found
end
manifest = backend.file(path)
return :not_found unless manifest.file?
JSON.parse(manifest.content)
end

class RemoteExecutionFailed < ChefCLI::ErrorNoLogs
Expand Down
8 changes: 4 additions & 4 deletions components/chef-cli/spec/unit/target_host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
end

context "#get_chef_version_manifest" do
let(:manifest_content) { nil }
let(:manifest_content) { '{"build_version" : "1.2.3"}' }
let(:expected_manifest_path) do
{
windows: "c:\\opscode\\chef\\version-manifest.json",
Expand All @@ -94,7 +94,7 @@
end
let(:base_os) { :unknown }
before do
remote_file_mock = double("remote_file", content: manifest_content)
remote_file_mock = double("remote_file", file?: manifest_exists, content: manifest_content)
backend_mock = double("backend")
expect(backend_mock).to receive(:file).
with(expected_manifest_path[base_os]).
Expand All @@ -104,6 +104,7 @@
end

context "when manifest is missing" do
let(:manifest_exists) { false }
context "on windows" do
let(:base_os) { :windows }
it "returns :not_found" do
Expand All @@ -120,17 +121,16 @@
end

context "when manifest is present" do
let(:manifest_exists) { true }
context "on windows" do
let(:base_os) { :windows }
let(:manifest_content) { '{"build_version" : "1.2.3"}' }
it "should return the parsed manifest" do
expect(subject.get_chef_version_manifest).to eq({ "build_version" => "1.2.3" })
end
end

context "on linux" do
let(:base_os) { :linux }
let(:manifest_content) { '{"build_version" : "1.2.3"}' }
it "should return the parsed manifest" do
expect(subject.get_chef_version_manifest).to eq({ "build_version" => "1.2.3" })
end
Expand Down

0 comments on commit a38c46c

Please sign in to comment.