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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.