Hi all,

I am writing a custom hiera backend for consul and I want to test the 
functionality.
But I am unable to create the proper puppet data structures that are 
required by the function definition. 


Part of the function I want to test:

Puppet::Functions.create_function(:hiera_consul) do
dispatch :lookup_key do
param 'Variant[String, Numeric]', :key
param 'Hash', :options
param 'Puppet::LookupContext', :context
end
def lookup_key(key, options, context)
if confine_keys = options['confine_to_keys']
raise ArgumentError, 'confine_to_keys must be an array' unless confine_keys.
is_a?(Array)
confine_keys.map! { |r| Regexp.new(r) }
regex_key_match = Regexp.union(confine_keys)
unless key[regex_key_match] == key
context.explain { "Skipping consul backend because key does not match 
confine_to_keys" }
context.not_found
end
end
....
end
end


The test:
describe 'hiera_consul' do
it "is confined to certain keys" do
context = Puppet::Pops::Lookup::Context.new({},{})

is_expected.to run.with_params('test_key', {'k' => 'v'}, context)
end
end

The results:
1) hiera_consul is confined to certain keys
Failure/Error: is_expected.to run.with_params('test_key', {'k' => 'v'}, 
context)

expected hiera_consul("test_key", {"k"=>"v"}, 
#<Puppet::Pops::Lookup::Context:0x007fdb7acc7060 
@lookup_invocation={}, @function_context={}>) to have run successfully 
instead of NoMethodError(undefined method `gsub!' for nil:NilClass)


What would the right way to construct the arguments for this signature?

Specifically 
- how do i create Puppet::LookupContext. Is this really the way?
- how do i create a puppet hash construct with data in it?

With regards,

Jos Houtman



-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/2e9a54b7-c7bd-4ce4-8a69-723422845e21%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to