Skip to content
This repository was archived by the owner on Jul 14, 2021. It is now read-only.

Improve chef --version command #2143

Merged
merged 3 commits into from
Jun 20, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update the specs for the new CLI output
Signed-off-by: Tim Smith <tsmith@chef.io>
  • Loading branch information
tas50 committed Jun 20, 2019
commit c181a35976535bbbeff9664ae3f14c28ec83752d
2 changes: 1 addition & 1 deletion lib/chef-dk/cli.rb
Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ def handle_options
end

def show_version
msg("Chef Development Kit Version: #{ChefDK::VERSION}\n")
msg("Chef Development Kit Version: #{ChefDK::VERSION}")
{ "Chef Infra Client": "chef-client",
"Test Kitchen": "kitchen",
"Foodcritic": "foodcritic",
60 changes: 28 additions & 32 deletions spec/unit/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -69,9 +69,9 @@ def run_cli_with_sanity_check(expected_exit_code)

def run_cli_and_validate_tool_versions
full_version_message = version_message
tools.each do |name, version|
expect(cli).to receive(:shell_out).with("#{name} --version").and_return(mock_shell_out(0, "#{version["version_output"]}", ""))
full_version_message += "#{name} version: #{version["expected_version"]}\n"
tools.each do |name, details|
expect(cli).to receive(:shell_out).with("#{details["command"]} --version").and_return(mock_shell_out(0, "#{details["version_output"]}", ""))
full_version_message += "#{name} version: #{details["expected_version"]}\n"
end
run_cli(0)
expect(stdout).to eq(full_version_message)
@@ -123,42 +123,46 @@ def mock_shell_out(exitstatus, stdout, stderr)

context "given -v" do
let(:argv) { %w{-v} }
let(:delivery_version) { "master (454c3f37819ed508a49c971f38e42267ce8a47de)" }

let(:tools) do
{
"chef-client" => {
"version_output" => "Chef: 12.0.3",
"expected_version" => "12.0.3",
"Chef Infra Client" => {
"command" => "chef-client",
"version_output" => "Chef Infra Client: 15.0.300",
"expected_version" => "15.0.300",
},
"delivery" => {
"version_output" => "delivery #{delivery_version}",
"expected_version" => delivery_version,
"Test Kitchen" => {
"command" => "kitchen",
"version_output" => "Test Kitchen version 2.2.5",
"expected_version" => "2.2.5",
},
"berks" => {
"version_output" => "3.2.3",
"expected_version" => "3.2.3",
"Foodcritic" => {
"command" => "foodcritic",
"version_output" => "foodcritic 16.0.0",
"expected_version" => "16.0.0",
},
"kitchen" => {
"version_output" => "Test Kitchen version 1.3.1",
"expected_version" => "1.3.1",
"Cookstyle" => {
"command" => "cookstyle",
"version_output" => "Cookstyle 4.0.0\n * RuboCop 0.62.0",
"expected_version" => "4.0.0",
},
"inspec" => {
"version_output" => "1.19.1\n\nYour version of InSpec is out of date! The latest version is 1.21.0.",
"expected_version" => "1.19.1",
"InSpec" => {
"command" => "inspec",
"version_output" => "4.6.2\n\nYour version of InSpec is out of date! The latest version is 4.6.4.",
"expected_version" => "4.6.2",
},
}
end

it "does not print versions of tools with missing or errored tools" do
full_version_message = version_message
tools.each do |name, version|
if name == "berks"
expect(cli).to receive(:shell_out).with("#{name} --version").and_return(mock_shell_out(1, "#{version["version_output"]}", ""))
tools.each do |name, details|
if name == "inspec"
expect(cli).to receive(:shell_out).with("#{details["command"]} --version").and_return(mock_shell_out(1, "#{details["version_output"]}", ""))
full_version_message += "#{name} version: ERROR\n"
else
expect(cli).to receive(:shell_out).with("#{name} --version").and_return(mock_shell_out(0, "#{version["version_output"]}", ""))
full_version_message += "#{name} version: #{version["expected_version"]}\n"
expect(cli).to receive(:shell_out).with("#{details["command"]} --version").and_return(mock_shell_out(0, "#{details["version_output"]}", ""))
full_version_message += "#{name} version: #{details["expected_version"]}\n"
end
end
run_cli(0)
@@ -168,14 +172,6 @@ def mock_shell_out(exitstatus, stdout, stderr)
it "prints the version and versions of chef-dk tools" do
run_cli_and_validate_tool_versions
end

context "alternate Delivery CLI version format" do
let(:delivery_version) { "0.0.15 (454c3f37819ed508a49c971f38e42267ce8a47de)" }

it "prints the expected version of Delivery CLI" do
run_cli_and_validate_tool_versions
end
end
end

context "given an invalid option" do