diff options
author | Tim Smith <tsmith@chef.io> | 2018-12-07 09:31:08 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-07 09:31:08 -0800 |
commit | 23d806d196fc99be900557d75c4e1f30951ea28c (patch) | |
tree | f7eac559e5fbae3318fbbb30ba8cdd7c546f7757 | |
parent | e02e7df9934b04e4382a7277e59111ab9b0f6f7d (diff) | |
parent | fd3d50270a14f47d11581380bd210f0658a4edf1 (diff) | |
download | chef-23d806d196fc99be900557d75c4e1f30951ea28c.tar.gz |
Merge pull request #8025 from Intility/bugfixes
Bugfixes to powershell_package_source
-rw-r--r-- | lib/chef/resource/powershell_package_source.rb | 18 | ||||
-rw-r--r-- | spec/unit/resource/powershell_package_source_spec.rb | 4 |
2 files changed, 13 insertions, 9 deletions
diff --git a/lib/chef/resource/powershell_package_source.rb b/lib/chef/resource/powershell_package_source.rb index 321a788822..061b9e632d 100644 --- a/lib/chef/resource/powershell_package_source.rb +++ b/lib/chef/resource/powershell_package_source.rb @@ -54,10 +54,14 @@ class Chef description: "The location where scripts will be published to for this source. Only valid if the provider is 'PowerShellGet'." load_current_value do - cmd = load_resource_state_script(name) + cmd = load_resource_state_script(source_name) repo = powershell_out!(cmd) - status = Chef::JSONCompat.from_json(repo.stdout) - url status["url"].nil? ? "not_set" : status["url"] + if repo.stdout.empty? + current_value_does_not_exist! + else + status = Chef::JSONCompat.from_json(repo.stdout) + end + url status["url"] trusted status["trusted"] provider_name status["provider_name"] publish_location status["publish_location"] @@ -112,7 +116,7 @@ class Chef action_class do def package_source_exists? - cmd = powershell_out!("(Get-PackageSource -Name '#{new_resource.source_name}').Name") + cmd = powershell_out!("(Get-PackageSource -Name '#{new_resource.source_name}' -WarningAction SilentlyContinue).Name") cmd.stdout.downcase.strip == new_resource.source_name.downcase end @@ -144,6 +148,9 @@ class Chef def load_resource_state_script(name) <<-EOH + $PSDefaultParameterValues = @{ + "*:WarningAction" = "SilentlyContinue" + } if(Get-PackageSource -Name '#{name}' -ErrorAction SilentlyContinue) { if ((Get-PackageSource -Name '#{name}').ProviderName -eq 'PowerShellGet') { (Get-PSRepository -Name '#{name}') | Select @{n='source_name';e={$_.Name}}, @{n='url';e={$_.SourceLocation}}, @@ -155,9 +162,6 @@ class Chef @{n='provider_name';e={$_.ProviderName}}, @{n='trusted';e={$_.IsTrusted}} | ConvertTo-Json } } - else { - "" | Select source_name, url, provider_name, trusted | ConvertTo-Json - } EOH end end diff --git a/spec/unit/resource/powershell_package_source_spec.rb b/spec/unit/resource/powershell_package_source_spec.rb index 4033f4515f..2640d9f3c5 100644 --- a/spec/unit/resource/powershell_package_source_spec.rb +++ b/spec/unit/resource/powershell_package_source_spec.rb @@ -205,13 +205,13 @@ describe Chef::Resource::PowershellPackageSource do describe "#package_source_exists?" do it "returns true if it exists" do - allow(provider).to receive(:powershell_out!).with("(Get-PackageSource -Name 'MyGallery').Name").and_return(double("powershell_out!", stdout: "MyGallery\r\n")) + allow(provider).to receive(:powershell_out!).with("(Get-PackageSource -Name 'MyGallery' -WarningAction SilentlyContinue).Name").and_return(double("powershell_out!", stdout: "MyGallery\r\n")) resource.source_name("MyGallery") expect(provider.package_source_exists?).to eql(true) end it "returns false if it doesn't exist" do - allow(provider).to receive(:powershell_out!).with("(Get-PackageSource -Name 'MyGallery').Name").and_return(double("powershell_out!", stdout: "")) + allow(provider).to receive(:powershell_out!).with("(Get-PackageSource -Name 'MyGallery' -WarningAction SilentlyContinue).Name").and_return(double("powershell_out!", stdout: "")) resource.source_name("MyGallery") expect(provider.package_source_exists?).to eql(false) end |