summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-03-30 21:34:48 -0700
committerTim Smith <tsmith84@gmail.com>2020-03-30 21:34:48 -0700
commit8505124e840409734d2b8ce1ead8ca3eacc41972 (patch)
treea1b4dafa6445660ed52298bdf4df743fad16da43
parentfaff7df8ea4861df6c0d0149a9d371cd31a04082 (diff)
downloadchef-build_essential_macos.tar.gz
Handle scenario where no value found in the updatebuild_essential_macos
Also add a pile of specs Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/build_essential.rb2
-rw-r--r--spec/unit/resource/build_essential_spec.rb32
2 files changed, 32 insertions, 2 deletions
diff --git a/lib/chef/resource/build_essential.rb b/lib/chef/resource/build_essential.rb
index 210129c9a8..35bab48e3a 100644
--- a/lib/chef/resource/build_essential.rb
+++ b/lib/chef/resource/build_essential.rb
@@ -174,7 +174,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
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