summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Magnus Rakvåg <tm@intility.no>2018-06-13 09:51:51 +0200
committerTor Magnus Rakvåg <tm@intility.no>2018-06-13 09:51:51 +0200
commitb49ca16636b77426e615adb30cc106d961575572 (patch)
tree52f3e5424cdc5d8c7c58a68a09b85d44f087019e
parentfae8378ca0a7646a69a5683d086a841dce591ba6 (diff)
downloadchef-b49ca16636b77426e615adb30cc106d961575572.tar.gz
rename name property to source_name
Signed-off-by: Tor Magnus Rakvåg <tm@intility.no>
-rw-r--r--lib/chef/resource/powershell_package_source.rb28
-rw-r--r--spec/unit/resource/powershell_package_source_spec.rb14
2 files changed, 21 insertions, 21 deletions
diff --git a/lib/chef/resource/powershell_package_source.rb b/lib/chef/resource/powershell_package_source.rb
index cf84d0a828..58a831a698 100644
--- a/lib/chef/resource/powershell_package_source.rb
+++ b/lib/chef/resource/powershell_package_source.rb
@@ -24,7 +24,7 @@ class Chef
description "Use the powershell_package_source resource to register a powershell package repository"
introduced "14.3"
- property :name, String,
+ property :source_name, String,
description: "The name of the package source",
name_property: true
@@ -75,13 +75,13 @@ class Chef
converge_if_changed :url, :trusted, :publish_location, :script_source_location, :script_publish_location do
update_cmd = build_ps_repository_command("Set", new_resource)
res = powershell_out(update_cmd)
- raise "Failed to update #{new_resource.name}: #{res.stderr}" unless res.stderr.empty?
+ raise "Failed to update #{new_resource.source_name}: #{res.stderr}" unless res.stderr.empty?
end
else
- converge_by("register source: #{new_resource.name}") do
+ converge_by("register source: #{new_resource.source_name}") do
register_cmd = build_ps_repository_command("Register", new_resource)
res = powershell_out(register_cmd)
- raise "Failed to register #{new_resource.name}: #{res.stderr}" unless res.stderr.empty?
+ raise "Failed to register #{new_resource.source_name}: #{res.stderr}" unless res.stderr.empty?
end
end
else
@@ -89,13 +89,13 @@ class Chef
converge_if_changed :url, :trusted, :provider_name do
update_cmd = build_package_source_command("Set", new_resource)
res = powershell_out(update_cmd)
- raise "Failed to update #{new_resource.name}: #{res.stderr}" unless res.stderr.empty?
+ raise "Failed to update #{new_resource.source_name}: #{res.stderr}" unless res.stderr.empty?
end
else
- converge_by("register source: #{new_resource.name}") do
+ converge_by("register source: #{new_resource.source_name}") do
register_cmd = build_package_source_command("Register", new_resource)
res = powershell_out(register_cmd)
- raise "Failed to register #{new_resource.name}: #{res.stderr}" unless res.stderr.empty?
+ raise "Failed to register #{new_resource.source_name}: #{res.stderr}" unless res.stderr.empty?
end
end
end
@@ -103,18 +103,18 @@ class Chef
action :unregister do
if package_source_exists?
- unregister_cmd = "Get-PackageSource -Name '#{new_resource.name}' | Unregister-PackageSource"
- converge_by("unregister source: #{new_resource.name}") do
+ unregister_cmd = "Get-PackageSource -Name '#{new_resource.source_name}' | Unregister-PackageSource"
+ converge_by("unregister source: #{new_resource.source_name}") do
res = powershell_out(unregister_cmd)
- raise "Failed to unregister #{new_resource.name}: #{res.stderr}" unless res.stderr.empty?
+ raise "Failed to unregister #{new_resource.source_name}: #{res.stderr}" unless res.stderr.empty?
end
end
end
action_class do
def package_source_exists?
- cmd = powershell_out!("(Get-PackageSource -Name '#{new_resource.name}').Name")
- cmd.stdout.downcase.strip == new_resource.name.downcase
+ cmd = powershell_out!("(Get-PackageSource -Name '#{new_resource.source_name}').Name")
+ cmd.stdout.downcase.strip == new_resource.source_name.downcase
end
def psrepository_cmdlet_appropriate?
@@ -122,7 +122,7 @@ class Chef
end
def build_ps_repository_command(cmdlet_type, new_resource)
- cmd = "#{cmdlet_type}-PSRepository -Name '#{new_resource.name}'"
+ cmd = "#{cmdlet_type}-PSRepository -Name '#{new_resource.source_name}'"
cmd << " -SourceLocation '#{new_resource.url}'" if new_resource.url
cmd << " -InstallationPolicy '#{new_resource.trusted ? "Trusted" : "Untrusted"}'"
cmd << " -PublishLocation '#{new_resource.publish_location}'" if new_resource.publish_location
@@ -132,7 +132,7 @@ class Chef
end
def build_package_source_command(cmdlet_type, new_resource)
- cmd = "#{cmdlet_type}-PackageSource -Name '#{new_resource.name}'"
+ cmd = "#{cmdlet_type}-PackageSource -Name '#{new_resource.source_name}'"
cmd << " -Location '#{new_resource.url}'" if new_resource.url
cmd << " -Trusted:#{new_resource.trusted ? "$true" : "$false"}"
cmd << " -ProviderName '#{new_resource.provider_name}'" if new_resource.provider_name
diff --git a/spec/unit/resource/powershell_package_source_spec.rb b/spec/unit/resource/powershell_package_source_spec.rb
index 0265547b21..d8cb8a09a0 100644
--- a/spec/unit/resource/powershell_package_source_spec.rb
+++ b/spec/unit/resource/powershell_package_source_spec.rb
@@ -26,7 +26,7 @@ describe Chef::Resource::PowershellPackageSource do
end
it "the name_property is 'name'" do
- expect(resource.name).to eql("MyGallery")
+ expect(resource.source_name).to eql("MyGallery")
end
it "the default action is :register" do
@@ -81,7 +81,7 @@ describe Chef::Resource::PowershellPackageSource do
describe "#build_ps_repository_command" do
before do
- resource.name("MyGallery")
+ resource.source_name("MyGallery")
resource.url("https://mygallery.company.co/api/v2/")
end
@@ -145,7 +145,7 @@ describe Chef::Resource::PowershellPackageSource do
describe "#build_package_source_command" do
before do
- resource.name("NuGet")
+ resource.source_name("NuGet")
resource.url("http://nuget.org/api/v2/")
end
@@ -160,7 +160,7 @@ describe Chef::Resource::PowershellPackageSource do
end
it "builds a command with a different provider" do
- resource.name("choco")
+ 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'")
@@ -183,7 +183,7 @@ describe Chef::Resource::PowershellPackageSource do
end
it "builds a command with a different provider" do
- resource.name("choco")
+ 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'")
@@ -206,13 +206,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"))
- resource.name("MyGallery")
+ 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 => ""))
- resource.name("MyGallery")
+ resource.source_name("MyGallery")
expect(provider.package_source_exists?).to eql(false)
end
end