Hi Bill,

On Wed, Mar 21, 2018 at 1:57 PM Bill Sirinek <[email protected]> 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(
>

this should be `newtype`, not `type`.



>               :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
>

Did you run into issues with the default fact stubbing ala
https://github.com/puppetlabs/pdk-templates/blob/046d65e6310c68c2209b7c41c73511b9821c1e79/object_templates/class_spec.erb#L6
?


>
>
>       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/194dfe1f-ff97-4388-92f7-be755de24d7b%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/194dfe1f-ff97-4388-92f7-be755de24d7b%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/CALF7fHb495jYRmxzGJ_C4rb8KwrCQu7EMH8-zP2GHc%2BHhBxjuw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to