diff options
author | Tim Smith <tsmith84@gmail.com> | 2020-03-30 21:34:48 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-04-02 12:27:35 -0700 |
commit | 9e61ebc8ef68215b0c43e256d2c83650301789ad (patch) | |
tree | f57df7244cd176061f01e1201b8ab5d84c0ae812 | |
parent | d12aa43d7b2aee6a5fb5876997ca10454afafeee (diff) | |
download | chef-9e61ebc8ef68215b0c43e256d2c83650301789ad.tar.gz |
Handle scenario where no value found in the update
Also add a pile of specs
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/chef/resource/build_essential.rb | 2 | ||||
-rw-r--r-- | spec/unit/resource/build_essential_spec.rb | 32 |
2 files changed, 32 insertions, 2 deletions
diff --git a/lib/chef/resource/build_essential.rb b/lib/chef/resource/build_essential.rb index 7b423b1412..cb54e45dd6 100644 --- a/lib/chef/resource/build_essential.rb +++ b/lib/chef/resource/build_essential.rb @@ -186,7 +186,7 @@ class Chef label_match = available_updates.stdout.match(/^\s*\* (?:Label: )?(Command Line Tools.*)/) # this will return the match or nil - label_match&.first + label_match[1] unless label_match.nil? end end diff --git a/spec/unit/resource/build_essential_spec.rb b/spec/unit/resource/build_essential_spec.rb index 8b412c94c2..62d7963ea2 100644 --- a/spec/unit/resource/build_essential_spec.rb +++ b/spec/unit/resource/build_essential_spec.rb @@ -1,5 +1,5 @@ # -# Copyright:: Copyright 2018, Chef Software, Inc. +# Copyright:: Copyright 2018-2020, Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,6 +25,18 @@ describe Chef::Resource::BuildEssential do let(:resource) { Chef::Resource::BuildEssential.new("foo", run_context) } let(:provider) { resource.provider_for_action(:install) } + let(:softwareupdate_catalina_and_later) do + double("shell_out", exitstatus: 0, error!: nil, stdout: "Software Update Tool\n\nFinding available software\nSoftware Update found the following new or updated software:\n* Label: Command Line Tools for Xcode-11.0\n\tTitle: Command Line Tools for Xcode, Version: 11.0, Size: 224868K, Recommended: YES, \n") + end + + let(:softwareupdate_catalina_and_later_no_cli) do + double("shell_out", exitstatus: 0, error!: nil, stdout: "Software Update Tool\n\nFinding available software\nSoftware Update found the following new or updated software:\n* Label: Chef Infra Client\n\tTitle: Chef Infra Client, Version: 17.0.208, Size: 224868K, Recommended: YES, \n") + end + + let(:softwareupdate_pre_catalina) do + double("shell_out", exitstatus: 0, error!: nil, stdout: "Software Update Tool\n\nFinding available software\nSoftware Update found the following new or updated software:\n * Command Line Tools (macOS High Sierra version 10.13) for Xcode-10.0\n") + end + it "has a resource name of :build_essential" do expect(resource.resource_name).to eql(:build_essential) end @@ -56,4 +68,22 @@ describe Chef::Resource::BuildEssential do expect(provider.xcode_cli_installed?).to eql(false) end end + + describe "#xcode_cli_package_label" do + it "returns a package name on macOS < 10.15" do + allow(provider).to receive(:shell_out).with("softwareupdate", "--list").and_return(softwareupdate_pre_catalina) + expect(provider.xcode_cli_package_label).to eql("Command Line Tools (macOS High Sierra version 10.13) for Xcode-10.0") + end + + it "returns a package name on macOS 10.15+" do + allow(provider).to receive(:shell_out).with("softwareupdate", "--list").and_return(softwareupdate_catalina_and_later) + expect(provider.xcode_cli_package_label).to eql("Command Line Tools for Xcode-11.0") + end + + it "returns nil if no update is listed" do + allow(provider).to receive(:shell_out).with("softwareupdate", "--list").and_return(softwareupdate_catalina_and_later_no_cli) + expect(provider.xcode_cli_package_label).to be_nil + end + + end end |