Not to worry, had a bit of an epiphany and realised that the apply application 
does pretty much exactly what I want.

"""
require 'puppet'

Puppet[:modulepath] = "/path/to/puppet/modules"
Puppet[:code] = "sysctl { 'foo': value => 'bar' }"

unless facts = Puppet::Node::Facts.find(Puppet[:certname])
raise "Could not find facts for #{Puppet[:certname]}"
end

unless node = Puppet::Node.find(Puppet[:certname])
raise "Could not find node #{Puppet[:certname]}"
end

node.merge(facts.values)

catalog = Puppet::Resource::Catalog.find(node.name, :use_node => node)
"""



Thanks,
Tim

On Saturday, 16 July 2011 at 10:59 AM, [email protected] wrote:

> Hi Luke,
> 
> Thanks, but this is not quite what I'm after. Basically I want to test that a 
> catalogue with just the baz resource generates certain resources, so I would 
> like a way to generate the equivalent of "node 'foo' { bar { 'name': test => 
> 'value' } }" by manipulating classes like Puppet::Node etc
> 
> basically, my dream endpoint is to be able to do something like the following
> 
> describe My::Define do
> let(:facts) { {:ipaddress_eth0 => '192.168.0.1' }
> let(:node) { 'testhost.example.com (http://testhost.example.com)' }
> let(:params) { :name => 'foo', :test => 'value' }
> subject { <some magic here to get the catalogue for this test host applying 
> just this resource> }
> 
> it { should.create_file "/etc/foo".with_mode('0444') }
> end
> 
> It looks like Puppet::Node accepts a :classes attribute to apply classes to a 
> node, but I'm not sure how to just apply a single resource to a node?
> 
> Thanks,
> Tim
> 
> On Saturday, 16 July 2011 at 10:01 AM, Luke Kanies wrote:
> 
> > On Jul 15, 2011, at 2:57 PM, Tim Sharpe wrote:
> > 
> > > Hi,
> > > 
> > > I'm looking at setting up some tests for the defined types in my 
> > > manifests (probably using rspec) to test that node <foo> with facts <bar> 
> > > applying define <baz> with params <gronk> creates a catalogue with the 
> > > following resources...
> > > 
> > > Basically, I want to generate the catalogue for the following and then 
> > > inspect it's contents.
> > > 
> > > node "foo" {
> > > baz { 'name':
> > > test => value,
> > > }
> > > }
> > > 
> > > Looking over Puppet::Node, I can see how to apply classes to a host, but 
> > > nothing about individual resources. If someone could point me in the 
> > > right direction, that'd be greatly appreciated. 
> > 
> > Dan Bode has some interesting work here, I think - hopefully he can post it.
> > 
> > In the meantime, I'd probably try something like this:
> > 
> > before do
> > Puppet[:config] = "/path/to/my/config"
> > Puppet.settings.parse
> > 
> > @catalog = Puppet::Node::Catalog.indirection.find(Puppet[:certname])
> > end
> > 
> > it "should create a 'baz' resource" do
> > @catalog.resource(:baz, "name").should be_instance_of(Puppet::Resource)
> > end
> > 
> > Something like that, anyway.
> > 
> > -- 
> > This space intentionally has nothing but text explaining why this
> > space has nothing but text explaining that this space would otherwise
> > have been left blank, and would otherwise have been left blank.
> > ---------------------------------------------------------------------
> > Luke Kanies | http://puppetlabs.com | http://about.me/lak
> > Join us in PDX for PuppetConf: http://bit.ly/puppetconfsig 
> >  -- 
> >  You received this message because you are subscribed to the Google Groups 
> > "Puppet Developers" group.
> >  To post to this group, send email to [email protected] 
> > (mailto:[email protected]).
> >  To unsubscribe from this group, send email to 
> > [email protected] 
> > (mailto:[email protected]).
> >  For more options, visit this group at 
> > http://groups.google.com/group/puppet-dev?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" 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-dev?hl=en.

Reply via email to