summaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-03-30 21:34:48 -0700
committerTim Smith <tsmith84@gmail.com>2020-03-31 10:51:50 -0700
commitfb0a385cbdf2d76e75aceca270bc0b3f2c1043ec (patch)
tree603c2b26eb13efb1037778b8b2f311b3a355a9b8 /spec/unit
parent3452647ad1edd85735ee7a23a6b4d38ce2d67d69 (diff)
downloadchef-fb0a385cbdf2d76e75aceca270bc0b3f2c1043ec.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>
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/resource/build_essential_spec.rb32
1 files changed, 31 insertions, 1 deletions
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