summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorMatt Wrock <matt@mattwrock.com>2020-10-30 21:36:27 +0000
committerGitHub <noreply@github.com>2020-10-30 21:36:27 +0000
commit8248fa5b5542840bc6adbeaf32445e008397dc55 (patch)
tree1196f8804fb746d8c5dca2270c786da086770fad /spec
parent4b56eedf7c805d4ba649bd514cad8f16c0d892d2 (diff)
parent31e13be0222e96d3f9b194b2530d6a0a1892a117 (diff)
downloadchef-8248fa5b5542840bc6adbeaf32445e008397dc55.tar.gz
Merge pull request #10545 from chef/out_to_exec
Improve Windows resource performance by converting powershell_out usage to powershell_exec
Diffstat (limited to 'spec')
-rw-r--r--spec/functional/resource/chocolatey_package_spec.rb6
-rw-r--r--spec/functional/resource/dsc_script_spec.rb6
-rw-r--r--spec/functional/resource/powershell_package_source_spec.rb103
-rw-r--r--spec/functional/resource/windows_certificate_spec.rb16
-rw-r--r--spec/functional/resource/windows_firewall_rule_spec.rb93
-rw-r--r--spec/functional/resource/windows_share_spec.rb103
-rw-r--r--spec/support/platform_helpers.rb10
-rw-r--r--spec/unit/provider/package/chocolatey_spec.rb3
-rw-r--r--spec/unit/resource/powershell_package_source_spec.rb40
9 files changed, 342 insertions, 38 deletions
diff --git a/spec/functional/resource/chocolatey_package_spec.rb b/spec/functional/resource/chocolatey_package_spec.rb
index 24975d2e01..e55c1a453c 100644
--- a/spec/functional/resource/chocolatey_package_spec.rb
+++ b/spec/functional/resource/chocolatey_package_spec.rb
@@ -16,13 +16,13 @@
# limitations under the License.
#
require "spec_helper"
-require "chef/mixin/powershell_out"
+require "chef/mixin/shell_out"
describe Chef::Resource::ChocolateyPackage, :windows_only, :choco_installed do
- include Chef::Mixin::PowershellOut
+ include Chef::Mixin::ShellOut
let(:package_name) { "test-A" }
- let(:package_list) { proc { powershell_out!("choco list -lo -r #{Array(package_name).join(" ")}").stdout.chomp } }
+ let(:package_list) { proc { shell_out!("choco list -lo -r #{Array(package_name).join(" ")}").stdout.chomp } }
let(:package_source) { File.join(CHEF_SPEC_ASSETS, "chocolatey_feed") }
let(:run_context) do
diff --git a/spec/functional/resource/dsc_script_spec.rb b/spec/functional/resource/dsc_script_spec.rb
index 83544cee04..9d18e2f85d 100644
--- a/spec/functional/resource/dsc_script_spec.rb
+++ b/spec/functional/resource/dsc_script_spec.rb
@@ -17,13 +17,13 @@
#
require "spec_helper"
-require "chef/mixin/powershell_out"
+require "chef/mixin/powershell_exec"
require "chef/mixin/windows_architecture_helper"
require "support/shared/integration/integration_helper"
describe Chef::Resource::DscScript, :windows_powershell_dsc_only do
include Chef::Mixin::WindowsArchitectureHelper
- include Chef::Mixin::PowershellOut
+ include Chef::Mixin::PowershellExec
before(:all) do
@temp_dir = ::Dir.mktmpdir("dsc-functional-test")
# enable the HTTP listener if it is not already enabled needed by underlying DSC engine
@@ -33,7 +33,7 @@ describe Chef::Resource::DscScript, :windows_powershell_dsc_only do
winrm create winrm/config/Listener?Address=*+Transport=HTTP
}
CODE
- powershell_out!(winrm_code)
+ powershell_exec!(winrm_code)
end
after(:all) do
diff --git a/spec/functional/resource/powershell_package_source_spec.rb b/spec/functional/resource/powershell_package_source_spec.rb
new file mode 100644
index 0000000000..fa95415788
--- /dev/null
+++ b/spec/functional/resource/powershell_package_source_spec.rb
@@ -0,0 +1,103 @@
+#
+# Author:: Matt Wrock (<matt@mattwrock.com>)
+# Copyright:: Copyright (c) Chef Software Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+require "spec_helper"
+require "chef/mixin/powershell_exec"
+
+describe Chef::Resource::PowershellPackageSource, :windows_only do
+ include Chef::Mixin::PowershellExec
+
+ let(:source_name) { "fake" }
+ let(:url) { "https://www.nuget.org/api/v2" }
+ let(:trusted) { true }
+
+ let(:run_context) do
+ Chef::RunContext.new(Chef::Node.new, {}, Chef::EventDispatch::Dispatcher.new)
+ end
+
+ subject do
+ new_resource = Chef::Resource::PowershellPackageSource.new("test powershell package source", run_context)
+ new_resource.source_name source_name
+ new_resource.url url
+ new_resource.trusted trusted
+ new_resource.provider_name provider_name
+ new_resource
+ end
+
+ let(:provider) do
+ provider = subject.provider_for_action(subject.action)
+ provider
+ end
+
+ shared_examples "package_source" do
+ context "register a package source" do
+ after { remove_package_source }
+
+ it "registers the package source" do
+ subject.run_action(:register)
+ expect(get_installed_package_source_name).to eq(source_name)
+ end
+
+ it "does not register the package source if already installed" do
+ subject.run_action(:register)
+ subject.run_action(:register)
+ expect(subject).not_to be_updated_by_last_action
+ end
+
+ it "updates an existing package source if changed" do
+ subject.run_action(:register)
+ subject.trusted !trusted
+ subject.run_action(:register)
+ expect(subject).to be_updated_by_last_action
+ end
+ end
+
+ context "unregister a package source" do
+ it "unregisters the package source" do
+ subject.run_action(:register)
+ subject.run_action(:unregister)
+ expect(get_installed_package_source_name).to be_empty
+ end
+
+ it "does not unregister the package source if not already installed" do
+ subject.run_action(:unregister)
+ expect(subject).not_to be_updated_by_last_action
+ end
+ end
+ end
+
+ context "with NuGet provider" do
+ let(:provider_name) { "NuGet" }
+
+ it_behaves_like "package_source"
+ end
+
+ context "with PowerShellGet provider" do
+ let(:provider_name) { "PowerShellGet" }
+
+ it_behaves_like "package_source"
+ end
+
+ def get_installed_package_source_name
+ powershell_exec!("(Get-PackageSource -Name #{source_name} -ErrorAction SilentlyContinue).Name").result
+ end
+
+ def remove_package_source
+ pkg_to_remove = Chef::Resource::PowershellPackageSource.new(source_name, run_context)
+ pkg_to_remove.run_action(:unregister)
+ end
+end \ No newline at end of file
diff --git a/spec/functional/resource/windows_certificate_spec.rb b/spec/functional/resource/windows_certificate_spec.rb
index 9c996fe1f8..20d444dd59 100644
--- a/spec/functional/resource/windows_certificate_spec.rb
+++ b/spec/functional/resource/windows_certificate_spec.rb
@@ -16,18 +16,18 @@
#
require "spec_helper"
-require "chef/mixin/powershell_out"
+require "chef/mixin/powershell_exec"
require "chef/resource/windows_certificate"
module WindowsCertificateHelper
- include Chef::Mixin::PowershellOut
+ include Chef::Mixin::PowershellExec
def create_store(store)
path = "Cert:\\LocalMachine\\" + store
command = <<~EOC
New-Item -Path #{path}
EOC
- powershell_out(command)
+ powershell_exec(command)
end
def cleanup(store)
@@ -35,15 +35,19 @@ module WindowsCertificateHelper
command = <<~EOC
Remove-Item -Path #{path} -Recurse
EOC
- powershell_out(command)
+ powershell_exec(command)
end
def no_of_certificates
path = "Cert:\\LocalMachine\\" + store
+ # Seems weird that we have to call dir twice right?
+ # The powershell pki module cache the last dir in module session state
+ # Issuing dir with a different arg (-Force) seems to refresh that state.
command = <<~EOC
- Write-Host (dir #{path} | measure).Count;
+ dir #{path} -Force | Out-Null
+ (dir #{path} | measure).Count
EOC
- powershell_out(command).stdout.to_i
+ powershell_exec(command).result.to_i
end
end
diff --git a/spec/functional/resource/windows_firewall_rule_spec.rb b/spec/functional/resource/windows_firewall_rule_spec.rb
new file mode 100644
index 0000000000..86220c1b71
--- /dev/null
+++ b/spec/functional/resource/windows_firewall_rule_spec.rb
@@ -0,0 +1,93 @@
+#
+# Author:: Matt Wrock (<matt@mattwrock.com>)
+# Copyright:: Copyright (c) Chef Software Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+require "spec_helper"
+require "chef/mixin/powershell_exec"
+
+describe Chef::Resource::WindowsFirewallRule, :windows_only do
+ include Chef::Mixin::PowershellExec
+
+ let(:rule_name) { "fake_rule" }
+ let(:remote_port) { "5555" }
+ let(:enabled) { false }
+
+ let(:run_context) do
+ Chef::RunContext.new(Chef::Node.new, {}, Chef::EventDispatch::Dispatcher.new)
+ end
+
+ subject do
+ new_resource = Chef::Resource::WindowsFirewallRule.new("test firewall rule", run_context)
+ new_resource.rule_name rule_name
+ new_resource.remote_port remote_port
+ new_resource.enabled enabled
+ new_resource
+ end
+
+ let(:provider) do
+ provider = subject.provider_for_action(subject.action)
+ provider
+ end
+
+ context "create a new rule" do
+ after { delete_rule }
+
+ it "creates the rule" do
+ subject.run_action(:create)
+ expect(get_installed_rule_name).to eq(rule_name)
+ expect(get_installed_rule_remote_port).to eq(remote_port)
+ end
+
+ it "does not create rule if it already exists" do
+ subject.run_action(:create)
+ subject.run_action(:create)
+ expect(subject).not_to be_updated_by_last_action
+ end
+
+ it "updates the rule if it changed" do
+ subject.run_action(:create)
+ subject.remote_port = "7777"
+ subject.run_action(:create)
+ expect(get_installed_rule_remote_port).to eq("7777")
+ end
+ end
+
+ context "delete a rule" do
+ it "deletes an existing rule" do
+ subject.run_action(:create)
+ subject.run_action(:delete)
+ expect(get_installed_rule_name).to be_empty
+ end
+
+ it "does not delete rule if it does not exist" do
+ subject.run_action(:delete)
+ expect(subject).not_to be_updated_by_last_action
+ end
+ end
+
+ def get_installed_rule_name
+ powershell_exec!("(Get-NetFirewallRule -Name #{rule_name} -ErrorAction SilentlyContinue).Name").result
+ end
+
+ def get_installed_rule_remote_port
+ powershell_exec!("((Get-NetFirewallRule -Name #{rule_name} -ErrorAction SilentlyContinue) | Get-NetFirewallPortFilter).RemotePort").result
+ end
+
+ def delete_rule
+ rule_to_remove = Chef::Resource::WindowsFirewallRule.new(rule_name, run_context)
+ rule_to_remove.run_action(:delete)
+ end
+end
diff --git a/spec/functional/resource/windows_share_spec.rb b/spec/functional/resource/windows_share_spec.rb
new file mode 100644
index 0000000000..6fae7d45d3
--- /dev/null
+++ b/spec/functional/resource/windows_share_spec.rb
@@ -0,0 +1,103 @@
+#
+# Author:: Matt Wrock (<matt@mattwrock.com>)
+# Copyright:: Copyright (c) Chef Software Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+require "spec_helper"
+require "chef/mixin/powershell_exec"
+
+describe Chef::Resource::WindowsShare, :windows_only do
+ include Chef::Mixin::PowershellExec
+
+ let(:share_name) { "fake_share" }
+ let(:path) { ENV["temp"] }
+ let(:concurrent_user_limit) { 7 }
+ let(:full_users) { ["#{ENV["USERNAME"]}"] }
+
+ let(:run_context) do
+ node = Chef::Node.new
+ node.default["hostname"] = ENV["COMPUTERNAME"]
+ Chef::RunContext.new(node, {}, Chef::EventDispatch::Dispatcher.new)
+ end
+
+ subject do
+ new_resource = Chef::Resource::WindowsShare.new("test windows share", run_context)
+ new_resource.share_name share_name
+ new_resource.path path
+ new_resource.concurrent_user_limit concurrent_user_limit
+ new_resource.full_users full_users
+ new_resource
+ end
+
+ let(:provider) do
+ provider = subject.provider_for_action(subject.action)
+ provider
+ end
+
+ context "create a new share" do
+ after { delete_share }
+
+ it "creates the share" do
+ subject.run_action(:create)
+ share = get_installed_share
+ expect(share["Name"]).to eq(share_name)
+ expect(share["Path"]).to eq(path)
+ expect(get_installed_share_access["AccountName"]).to eq("#{ENV["COMPUTERNAME"]}\\#{full_users[0]}")
+ end
+
+ it "does not create share if it already exists" do
+ subject.run_action(:create)
+ subject.run_action(:create)
+ expect(subject).not_to be_updated_by_last_action
+ end
+
+ it "updates the share if it changed" do
+ subject.run_action(:create)
+ subject.concurrent_user_limit 8
+ subject.full_users ["BUILTIN\\Administrators"]
+ subject.run_action(:create)
+ share = get_installed_share
+ expect(share["ConcurrentUserLimit"]).to eq(8)
+ expect(get_installed_share_access["AccountName"]).to eq("BUILTIN\\Administrators")
+ end
+
+ end
+
+ context "delete a share" do
+ it "deletes an existing share" do
+ subject.run_action(:create)
+ subject.run_action(:delete)
+ expect(get_installed_share).to be_empty
+ end
+
+ it "does not delete share if it does not exist" do
+ subject.run_action(:delete)
+ expect(subject).not_to be_updated_by_last_action
+ end
+ end
+
+ def get_installed_share
+ powershell_exec!("Get-SmbShare -Name #{share_name} -ErrorAction SilentlyContinue").result
+ end
+
+ def get_installed_share_access
+ powershell_exec!("Get-SmbShareAccess -Name #{share_name} -ErrorAction SilentlyContinue").result
+ end
+
+ def delete_share
+ rule_to_remove = Chef::Resource::WindowsShare.new(share_name, run_context)
+ rule_to_remove.run_action(:delete)
+ end
+end
diff --git a/spec/support/platform_helpers.rb b/spec/support/platform_helpers.rb
index 60990f73a5..b29c860f30 100644
--- a/spec/support/platform_helpers.rb
+++ b/spec/support/platform_helpers.rb
@@ -2,11 +2,9 @@ require "fcntl"
require "chef/mixin/shell_out"
require "ohai/mixin/http_helper"
require "ohai/mixin/gce_metadata"
-require "chef/mixin/powershell_out"
class ShellHelpers
extend Chef::Mixin::ShellOut
- extend Chef::Mixin::PowershellOut
end
# magic stolen from bundler/spec/support/less_than_proc.rb
@@ -242,11 +240,15 @@ def ifconfig?
end
def choco_installed?
- result = ShellHelpers.powershell_out("choco --version")
+ result = ShellHelpers.shell_out("choco --version")
result.stderr.empty?
+rescue
+ false
end
def pwsh_installed?
- result = ShellHelpers.powershell_out("pwsh.exe --version")
+ result = ShellHelpers.shell_out("pwsh.exe --version")
result.stderr.empty?
+rescue
+ false
end
diff --git a/spec/unit/provider/package/chocolatey_spec.rb b/spec/unit/provider/package/chocolatey_spec.rb
index 96b17d90f2..ba5739fe55 100644
--- a/spec/unit/provider/package/chocolatey_spec.rb
+++ b/spec/unit/provider/package/chocolatey_spec.rb
@@ -501,8 +501,7 @@ describe "behavior when Chocolatey is not installed" do
before do
# the shellout sometimes returns "", but test nil to be safe.
- allow(provider).to receive(:choco_install_path).and_return(nil)
- provider.instance_variable_set("@choco_install_path", nil)
+ allow(provider).to receive(:choco_install_path).and_return("")
# we don't care what this returns, but we have to let it be called.
allow(provider).to receive(:shell_out_compacted!).and_return(double(stdout: ""))
diff --git a/spec/unit/resource/powershell_package_source_spec.rb b/spec/unit/resource/powershell_package_source_spec.rb
index 2640d9f3c5..1032902a0f 100644
--- a/spec/unit/resource/powershell_package_source_spec.rb
+++ b/spec/unit/resource/powershell_package_source_spec.rb
@@ -87,58 +87,58 @@ describe Chef::Resource::PowershellPackageSource do
context "#register" do
it "builds a minimal command" do
- expect(provider.build_ps_repository_command("Register", resource)).to eql("Register-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted'")
+ expect(provider.build_ps_repository_command("Register", resource)).to eql("Register-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' | Out-Null")
end
it "builds a command with trusted set to true" do
resource.trusted(true)
- expect(provider.build_ps_repository_command("Register", resource)).to eql("Register-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Trusted'")
+ expect(provider.build_ps_repository_command("Register", resource)).to eql("Register-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Trusted' | Out-Null")
end
it "builds a command with a publish location" do
resource.publish_location("https://mygallery.company.co/api/v2/package")
- expect(provider.build_ps_repository_command("Register", resource)).to eql("Register-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' -PublishLocation 'https://mygallery.company.co/api/v2/package'")
+ expect(provider.build_ps_repository_command("Register", resource)).to eql("Register-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' -PublishLocation 'https://mygallery.company.co/api/v2/package' | Out-Null")
end
it "builds a command with a script source location" do
resource.script_source_location("https://mygallery.company.co/api/v2/scripts")
- expect(provider.build_ps_repository_command("Register", resource)).to eql("Register-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' -ScriptSourceLocation 'https://mygallery.company.co/api/v2/scripts'")
+ expect(provider.build_ps_repository_command("Register", resource)).to eql("Register-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' -ScriptSourceLocation 'https://mygallery.company.co/api/v2/scripts' | Out-Null")
end
it "builds a command with a script publish location" do
resource.script_publish_location("https://mygallery.company.co/api/v2/scripts/package")
- expect(provider.build_ps_repository_command("Register", resource)).to eql("Register-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' -ScriptPublishLocation 'https://mygallery.company.co/api/v2/scripts/package'")
+ expect(provider.build_ps_repository_command("Register", resource)).to eql("Register-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' -ScriptPublishLocation 'https://mygallery.company.co/api/v2/scripts/package' | Out-Null")
end
end
context "#set" do
it "builds a minimal command" do
- expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted'")
+ expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' | Out-Null")
end
it "builds a command to change the url" do
resource.url("https://othergallery.company.co/api/v2/")
- expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://othergallery.company.co/api/v2/' -InstallationPolicy 'Untrusted'")
+ expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://othergallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' | Out-Null")
end
it "builds a command with trusted set to true" do
resource.trusted(true)
- expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Trusted'")
+ expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Trusted' | Out-Null")
end
it "builds a command with a publish location" do
resource.publish_location("https://mygallery.company.co/api/v2/package")
- expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' -PublishLocation 'https://mygallery.company.co/api/v2/package'")
+ expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' -PublishLocation 'https://mygallery.company.co/api/v2/package' | Out-Null")
end
it "builds a command with a script source location" do
resource.script_source_location("https://mygallery.company.co/api/v2/scripts")
- expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' -ScriptSourceLocation 'https://mygallery.company.co/api/v2/scripts'")
+ expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' -ScriptSourceLocation 'https://mygallery.company.co/api/v2/scripts' | Out-Null")
end
it "builds a command with a script publish location" do
resource.script_publish_location("https://mygallery.company.co/api/v2/scripts/package")
- expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' -ScriptPublishLocation 'https://mygallery.company.co/api/v2/scripts/package'")
+ expect(provider.build_ps_repository_command("Set", resource)).to eql("Set-PSRepository -Name 'MyGallery' -SourceLocation 'https://mygallery.company.co/api/v2/' -InstallationPolicy 'Untrusted' -ScriptPublishLocation 'https://mygallery.company.co/api/v2/scripts/package' | Out-Null")
end
end
end
@@ -151,42 +151,42 @@ describe Chef::Resource::PowershellPackageSource do
context "#register" do
it "builds a minimal command" do
- expect(provider.build_package_source_command("Register", resource)).to eql("Register-PackageSource -Name 'NuGet' -Location 'http://nuget.org/api/v2/' -Trusted:$false -ProviderName 'NuGet'")
+ expect(provider.build_package_source_command("Register", resource)).to eql("Register-PackageSource -Name 'NuGet' -Location 'http://nuget.org/api/v2/' -Trusted:$false -ProviderName 'NuGet' | Out-Null")
end
it "builds a command with trusted set to true" do
resource.trusted(true)
- expect(provider.build_package_source_command("Register", resource)).to eql("Register-PackageSource -Name 'NuGet' -Location 'http://nuget.org/api/v2/' -Trusted:$true -ProviderName 'NuGet'")
+ expect(provider.build_package_source_command("Register", resource)).to eql("Register-PackageSource -Name 'NuGet' -Location 'http://nuget.org/api/v2/' -Trusted:$true -ProviderName 'NuGet' | Out-Null")
end
it "builds a command with a different provider" do
resource.source_name("choco")
resource.url("https://chocolatey.org/api/v2/")
resource.provider_name("chocolatey")
- expect(provider.build_package_source_command("Register", resource)).to eql("Register-PackageSource -Name 'choco' -Location 'https://chocolatey.org/api/v2/' -Trusted:$false -ProviderName 'chocolatey'")
+ expect(provider.build_package_source_command("Register", resource)).to eql("Register-PackageSource -Name 'choco' -Location 'https://chocolatey.org/api/v2/' -Trusted:$false -ProviderName 'chocolatey' | Out-Null")
end
end
context "#set" do
it "builds a minimal command" do
- expect(provider.build_package_source_command("Set", resource)).to eql("Set-PackageSource -Name 'NuGet' -Location 'http://nuget.org/api/v2/' -Trusted:$false -ProviderName 'NuGet'")
+ expect(provider.build_package_source_command("Set", resource)).to eql("Set-PackageSource -Name 'NuGet' -Location 'http://nuget.org/api/v2/' -Trusted:$false -ProviderName 'NuGet' | Out-Null")
end
it "builds a command to change the url" do
resource.url("https://nuget.company.co/api/v2/")
- expect(provider.build_package_source_command("Set", resource)).to eql("Set-PackageSource -Name 'NuGet' -Location 'https://nuget.company.co/api/v2/' -Trusted:$false -ProviderName 'NuGet'")
+ expect(provider.build_package_source_command("Set", resource)).to eql("Set-PackageSource -Name 'NuGet' -Location 'https://nuget.company.co/api/v2/' -Trusted:$false -ProviderName 'NuGet' | Out-Null")
end
it "builds a command with trusted set to true" do
resource.trusted(true)
- expect(provider.build_package_source_command("Set", resource)).to eql("Set-PackageSource -Name 'NuGet' -Location 'http://nuget.org/api/v2/' -Trusted:$true -ProviderName 'NuGet'")
+ expect(provider.build_package_source_command("Set", resource)).to eql("Set-PackageSource -Name 'NuGet' -Location 'http://nuget.org/api/v2/' -Trusted:$true -ProviderName 'NuGet' | Out-Null")
end
it "builds a command with a different provider" do
resource.source_name("choco")
resource.url("https://chocolatey.org/api/v2/")
resource.provider_name("chocolatey")
- expect(provider.build_package_source_command("Set", resource)).to eql("Set-PackageSource -Name 'choco' -Location 'https://chocolatey.org/api/v2/' -Trusted:$false -ProviderName 'chocolatey'")
+ expect(provider.build_package_source_command("Set", resource)).to eql("Set-PackageSource -Name 'choco' -Location 'https://chocolatey.org/api/v2/' -Trusted:$false -ProviderName 'chocolatey' | Out-Null")
end
end
end
@@ -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' -WarningAction SilentlyContinue).Name").and_return(double("powershell_out!", stdout: "MyGallery\r\n"))
+ allow(provider).to receive(:powershell_exec!).with("(Get-PackageSource -Name 'MyGallery' -ErrorAction SilentlyContinue).Name").and_return(double("powershell_exec!", result: "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' -WarningAction SilentlyContinue).Name").and_return(double("powershell_out!", stdout: ""))
+ allow(provider).to receive(:powershell_exec!).with("(Get-PackageSource -Name 'MyGallery' -ErrorAction SilentlyContinue).Name").and_return(double("powershell_exec!", result: ""))
resource.source_name("MyGallery")
expect(provider.package_source_exists?).to eql(false)
end