On Thu, Mar 22, 2018 at 1:38 PM Bill Sirinek <[email protected]> wrote:

> My *type *file calls Puppet::Type.newtype() as you suggest, but the code
> snippet you were referring to was for my *provider*, so I think
> Puppet::Type.type(:myapp_config).provide
>
> is correct here. The type/provider itself actually works. I have verified
> that by actually using the module. I am in the process of writing tests for
> modules where we did not do so before.
>

Oh yeah, sorry. You're right.


>
> There are two providers for my type. One of them, the one showing this
> error when running tests, manages an ini-style configuration file, so I
> defined Puppet::Type.type(:ini_setting).provider(:ruby) as a parent
> provider. That is part of the puppetlabs/inifile module. My test fails
> because it doesnt seem to be able to find this? From what I can see,
> Puppet::Type.type(:ini_setting).provider(:ruby) is nil when the test runs.
> I included the inifile module in my .fixtures.yml  but apparently that
> doesnt fix it.
>

Hmm. can you provide the module's source, so we can have a look at it? If
you can't publish it, please send it to [email protected].



>
> As for the facts, the test code I for testing this type/provider started
> out as a copy and paste so I wont be able to deal with the facts until I
> get past this issue, but to answer your question, one big issue I ran into
> with PDK's default handling of facts is that it uses rspec-puppet-facts
> which does not seem to support Solaris 10 anymore, or at least I hadnt
> gotten it to work. So I have been having to keep Solaris 10 out of my
> metadata.json file, even though it probably should be there as Solaris 10
> is supported by Puppet in my version of PE (2017.3.5)
>

I see you already found your way around to adding the facts to facterdb.
Thanks a lot!

Cheers, David


>
> Bill
>
>
> On Wednesday, March 21, 2018 at 9:57:34 AM UTC-4, Bill Sirinek wrote:
>>
>> I am trying to write an rspec test for a custom type and provider I wrote
>> and having issues.
>>
>> The custom type has a provider that manages an ini file. Because I
>> already have puppetlabs/inifile, I made this provider a child provider of
>> ini_setting.  (I don't use the ini_setting type directly in my manifests,
>> because some versions of the application use a command line tool talking to
>> a DB for configuration, rather than a plaintext ini file, and my custom
>> type supports both)   The type/provider code works in puppet, I'm writing
>> tests for our modules after the fact. :\
>>
>> lib/puppet/provider/ini_style_config.rb:
>>
>> Puppet::Type.type(:myapp_config).provide(
>>               :ini_style_config,
>>               :parent => Puppet::Type.type(:ini_setting).provider(:ruby)
>>               ) do
>>   desc "configuration items for version of the app that uses an .ini
>> file"
>>
>>  < ... provider code ... >
>>
>> spec/lib/puppet/provider/ini_style_config_spec.rb:
>>
>> require 'spec_helper'
>>
>>
>> describe Puppet::Type.type(:myapp_config).provider(:ini_style_config) do
>>
>>
>>   on_supported_os.each do |os, facts|
>>     context "on #{os}" do
>>       before :each do
>>         Facter.clear
>>         facts.each do |k, v|
>>           Facter.stubs(:fact).with(k).returns Facter.add(k) { setcode {
>> v } }
>>         end
>>       end
>>
>>
>>       describe 'instances' do
>>         it 'should have an instance method' do
>>           expect(described_class).to respond_to :instances
>>         end
>>       end
>>
>>
>>       describe 'prefetch' do
>>         it 'should have a prefetch method' do
>>           expect(described_class).to respond_to :prefetch
>>         end
>>       end
>>     end
>>   end
>> end
>>
>>
>> When I run the tests I get an error because it can't find the ini_setting
>> type from puppetlabs/inifile:
>>
>>
>>
>> mymacbook:myapp bsirinek$ pdk test unit
>> [✔] Preparing to run the unit tests.
>> [✖] Running unit tests.
>>
>>
>> An error occurred while loading ./spec/unit/puppet/provider/
>> ini_style_config_spec.rb.
>> Failure/Error: :parent => Puppet::Type.type(:ini_setting).provider(:ruby)
>>
>>
>> Puppet::Error:
>>   Could not autoload puppet/type/myapp_config: Could not autoload puppet/
>> provider/myapp_config/ini_style_config: undefined method `provider' for
>> nil:NilClass
>> # ./lib/puppet/provider/myapp_config/ini_style_config.rb:3:in `<top (
>> required)>'
>> #
>> /opt/puppetlabs/pdk/share/cache/ruby/2.1.0/gems/puppet-5.3.3/lib/puppet/util/autoload.rb:68:in
>> `load'
>> #
>> /opt/puppetlabs/pdk/share/cache/ruby/2.1.0/gems/puppet-5.3.3/lib/puppet/util/autoload.rb:68:in
>> `load_file'
>> #
>> /opt/puppetlabs/pdk/share/cache/ruby/2.1.0/gems/puppet-5.3.3/lib/puppet/util/autoload.rb:83:in
>> `block in loadall'
>> #
>> /opt/puppetlabs/pdk/share/cache/ruby/2.1.0/gems/puppet-5.3.3/lib/puppet/util/autoload.rb:81:in
>> `each'
>> #
>> /opt/puppetlabs/pdk/share/cache/ruby/2.1.0/gems/puppet-5.3.3/lib/puppet/util/autoload.rb:81:in
>> `loadall'
>> #
>> /opt/puppetlabs/pdk/share/cache/ruby/2.1.0/gems/puppet-5.3.3/lib/puppet/util/autoload.rb:208:in
>> `loadall'
>> #
>> /opt/puppetlabs/pdk/share/cache/ruby/2.1.0/gems/puppet-5.3.3/lib/puppet/metatype/manager.rb:126:in
>> `newtype'
>> # ./lib/puppet/type/myapp_config.rb:1:in `<top (required)>'
>> #
>> /opt/puppetlabs/pdk/share/cache/ruby/2.1.0/gems/puppet-5.3.3/lib/puppet/util/autoload.rb:68:in
>> `load'
>> #
>> /opt/puppetlabs/pdk/share/cache/ruby/2.1.0/gems/puppet-5.3.3/lib/puppet/util/autoload.rb:68:in
>> `load_file'
>> #
>> /opt/puppetlabs/pdk/share/cache/ruby/2.1.0/gems/puppet-5.3.3/lib/puppet/util/autoload.rb:194:in
>> `load'
>> #
>> /opt/puppetlabs/pdk/share/cache/ruby/2.1.0/gems/puppet-5.3.3/lib/puppet/metatype/manager.rb:171:in
>> `type'
>> # ./spec/unit/puppet/provider/ini_style_config_spec.rb:3:in `<top
>> (required)>'
>> # ------------------
>> # --- Caused by: ---
>> # NoMethodError:
>> #   undefined method `provider' for nil:NilClass
>> #   ./lib/puppet/provider/myapp_config/ini_style_config.rb:3:in `<top
>> (required)>'
>>   Evaluated 0 tests in 0.00058 seconds: 0 failures, 0 pending.
>> [✔] Cleaning up after running unit tests.
>> mymacbook:myapp bsirinek$
>>
>>
>> I have inifile listed in my .fixtures.yml.
>>
>> ---
>> fixtures:
>>   symlinks:
>>     myapp: "#{source_dir}"
>>   forge_modules:
>>     stdlib:
>>       repo: "puppetlabs/stdlib"
>>       ref: "4.20.0"
>>     inifile:
>>       repo: "puppetlabs/inifile"
>>       ref: "2.0.0"
>>
>>
>> Am I missing something?
>>
>> Thanks
>>
>> Bill
>>
>>
>> --
> 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/72b541e1-ac28-4e1f-a015-5bc349c78731%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/72b541e1-ac28-4e1f-a015-5bc349c78731%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
-- 
Cheers, David

https://twitter.com/dev_el_ops

-- 
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/CALF7fHbKEmPtxjtG_%2BF8pHjvEfYb-cL0bD%2BNBiOZxGn0g_RgGg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to