Skip to content

Commit

Permalink
use correct name for defaults array consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
waveclaw committed Aug 12, 2017
1 parent 8e00a49 commit f7a7f54
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 34 deletions.
10 changes: 5 additions & 5 deletions lib/puppet/provider/rhsm_config/subscription_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def self.defaults_to=(value)
# @param [String] the raw data
# @api private
def self.ini_parse(input)
@defaulted_to = []
@defaults_to = []
output = {}
title = nil
section = nil
Expand All @@ -182,14 +182,14 @@ def self.ini_parse(input)
# if nil is used here then puppet considers parameters set to
# '' to be in need of sync at all time
value = ''
@defaulted_to.push "#{section}_#{title}".to_sym
@defaults_to.push "#{section}_#{title}".to_sym
when /\[(\d+)\]/
@defaulted_to.push "#{section}_#{title}".to_sym
@defaults_to.push "#{section}_#{title}".to_sym
value = parse_digit(section, title, $1)
when /^(\d+)$/
value = parse_digit(section, title, $1)
when /\[(.+)\]/
@defaulted_to.push "#{section}_#{title}".to_sym
@defaults_to.push "#{section}_#{title}".to_sym
value = $1
when /(\S+)/
value = $1
Expand Down Expand Up @@ -219,7 +219,7 @@ def build_config_parameters(config)
@property_hash.keys.each { |key|
# skip meta parameters and default values
unless [ :ensure, :title, :tags, :name, :provider].include? key or
(!@defaulted_to.nil? and @defaulted_to.include? key)
(!@defaults_to.nil? and @defaults_to.include? key)
section = key.to_s.sub('_','.')
if config == :remove or
(@property_hash[key] == '' and @property_hash[key] != @resource[key]) or
Expand Down
64 changes: 35 additions & 29 deletions spec/unit/provider/rhsm_config/subscription_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@
config = configs[0]
expect(config.public_send(:rhsm_repo_ca_cert)).to eq(resource[:rhsm_repo_ca_cert])
end
it "detects default options" do
@resource = Puppet::Type.type(:rhsm_config).new(
{:provider => provider, :name => title })
expect(@resource.provider.class).to receive(:subscription_manager).with(['config','--list']) { raw_hostname01_data }
config = @resource.provider.class.get_configuration
expect(config.size).to_not eq(0)
expect(@resource.provider.class.defaults_to?).to include(:server_port)
end
end

describe 'build_config_parameters' do
Expand Down Expand Up @@ -330,34 +338,32 @@
expect((combo[:apply]).sort!).to eq(apply_expected)
expect((combo[:remove]).sort!).to eq(remove_expected)
end

it "correctly combines several options into a command" do
@resource = Puppet::Type.type(:rhsm_config).new(
{:provider => provider, :name => title })
@resource.provider.set(:server_insecure => false)
@resource.provider.set(:server_port => 443)
@resource.provider.set(:rhsm_ca_cert_dir => '/etc/rhsm/ca/')
apply = @resource.provider.build_config_parameters(:apply)
expect(apply[:apply].sort!).to eq([
'config',
"--server.port", "443", "--rhsm.ca_cert_dir", "/etc/rhsm/ca/", "--server.insecure", "0"
].sort!)
expect(apply[:remove]).to eq(nil)
remove = @resource.provider.build_config_parameters(:remove)
expect(remove[:apply]).to eq(nil)
expect(remove[:remove].sort!).to eq([
"--remove=server.port", "--remove=rhsm.ca_cert_dir", "--remove=server.insecure" ].sort!)
end

it "skips default options" do
@resource = Puppet::Type.type(:rhsm_config).new(
{:provider => provider, :name => title })
@resource.provider.set(:server_insecure => false)
@resource.provider.set(:server_port => 443)
@resource.provider.set(:rhsm_ca_cert_dir => '/etc/rhsm/ca/')
@resource.provider.class.defaults_to = [ :server_port ]
apply = @resource.provider.build_config_parameters(:apply)
expect(apply).to_not include(:server_port)
end
it "correctly combines several options into a command" do
@resource = Puppet::Type.type(:rhsm_config).new(
{:provider => provider, :name => title })
@resource.provider.set(:server_insecure => false)
@resource.provider.set(:server_port => 443)
@resource.provider.set(:rhsm_ca_cert_dir => '/etc/rhsm/ca/')
apply = @resource.provider.build_config_parameters(:apply)
expect(apply[:apply].sort!).to eq([
'config',
"--server.port", "443", "--rhsm.ca_cert_dir", "/etc/rhsm/ca/", "--server.insecure", "0"
].sort!)
expect(apply[:remove]).to eq(nil)
remove = @resource.provider.build_config_parameters(:remove)
expect(remove[:apply]).to eq(nil)
expect(remove[:remove].sort!).to eq([
"--remove=server.port", "--remove=rhsm.ca_cert_dir", "--remove=server.insecure" ].sort!)
end
it "skips default options" do
@resource = Puppet::Type.type(:rhsm_config).new(
{:provider => provider, :name => title })
@resource.provider.set(:server_insecure => false)
@resource.provider.set(:server_port => 443)
@resource.provider.set(:rhsm_ca_cert_dir => '/etc/rhsm/ca/')
@resource.provider.class.defaults_to = [ :server_port ]
apply = @resource.provider.build_config_parameters(:apply)
expect(apply).to_not include(:server_port)
end
end
end

0 comments on commit f7a7f54

Please sign in to comment.