Hi Oliver,
Sorry for taking so long to respond on this.  We definitely appreciate
the help writing some tests for that patch as it looks like something
that would definitely help people once it gets merged in.

Writing tests for puppet providers can be tricky, as you're finding.
I'll take a look and see where you're running into problems.
Hopefully I'll have some help for you by the end of Monday.

(note: this is a duplicate of the email I sent to puppet-dev, which is
definitely more frequently read by developers who can help out with
this kind of stuff)
Matt

On Mon, Aug 16, 2010 at 4:32 AM, Oliver <ohook...@gmail.com> wrote:
> Sorry, but this is a blatant call for help. I'm desperately out of my
> depth with creating tests due to my lack of experience with just about
> every component involved.
>
> The background is, I'm trying to create the necessary tests to have
> #2866 accepted. I'm running into problems just getting a basic "should
> specify the package version if one is asked for" test running. I've
> looked through the yum provider code, the other providers, tests for
> other providers etc but can't seem to come up with something that
> works. I'm quite certain it is mostly due to lack of knowledge but
> perhaps also is related to the providers working in slightly different
> ways.
>
> Here is what I have so far:
> -----
>
> #!/usr/bin/env ruby
>
> require File.dirname(__FILE__) + '/../../../spec_helper'
>
> provider = Puppet::Type.type(:package).provider(:yum)
>
> describe provider do
>    before do
>        # Create a mock resource
>       �...@resource = stub 'resource'
>
>        # A catch all; no parameters set
>       �...@resource.stubs(:[]).returns nil
>
>        # We have to set a name, though
>       �...@resource.stubs(:[]).with(:name).returns "mypackage"
>       �...@resource.stubs(:[]).with(:ensure).returns :installed
>       �...@resource.stubs(:[]).with(:ensure).returns "1.0"
>
>       �...@provider = provider.new(@resource)
>       �...@provider.stubs(:resource).returns @resource
>    end
>
>    it "should have an install method" do
>       �...@provider.should respond_to(:install)
>    end
>
>    it "should be versionable" do
>        provider.should be_versionable
>    end
>
>    it "should use erase to purge" do
>       �...@provider.expects(:yum).with("-y", :erase, "mypackage")
>
>       �...@provider.purge
>    end
>
>    describe "when installing" do
>        it "should specify the package version if one is asked for" do
>           �...@resource.expects(:name).with(:ensure).returns "1.0"
>           �...@resource.expects(:name)
>           �...@provider.expects(:yum).with("-d", "0", "-e", "0", "-y",
> :install, "mypackage-1.0")
>
>           �...@provider.stubs(:yum).returns "yum"
>           �...@provider.install
>        end
>    end
> end
> -----
>
> My output is as follows:
> -----
>
> Puppet::Type::Package::ProviderYum
> - should have an install method
> - should be versionable
> - should use erase to purge
>
> Puppet::Type::Package::ProviderYum when installing
> - should specify the package version if one is asked for (FAILED - 1)
>
> 1)
> Puppet::Error in 'Puppet::Type::Package::ProviderYum when installing
> should specify the package version if one is asked for'
> Could not find package
> ./spec/unit/provider/package/yum.rb:45:
> /home/ohookins/work/puppet/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb:22:in
> `run'
> /home/ohookins/work/puppet/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb:17:in
> `each'
> /home/ohookins/work/puppet/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb:17:in
> `run'
>
> Finished in 0.160654 seconds
>
> 4 examples, 1 failure
> -----
>
> I guess that I am not pre-setting the correct information in the
> mocked provider, so that it thinks the relevant package is available
> to be installed. I previously did not have the
> "@resource.expects(:name)" line in the last test, and it complained
> about an unexpected invocation to <Mock#resource>.name() which does
> not make sense to me but then, not much of this does.
>
> Some kind soul helped me out last week on the IRC channel and
> mentioned there may be bugs in the actual provider, but I cannot
> comment on that.
>
> Any input or flames are welcome.
> Best Regards,
> Oliver
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Puppet Users" group.
> To post to this group, send email to puppet-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> puppet-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/puppet-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-us...@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to