Sweet!
> The functions themselves seem to work fine in my manifest-based smoketests,
> but I am running into trouble that may or may not be due to my ignorance
> about rspec or Facter. Something needs to be done to initialize Facter
> because lookupvar('interfaces') just returns :undefined. I have not found
> any examples in the existing rspec tests; getvar_spec.rb seems like it
> should have something but the tests it does are pretty basic.
In general, you should assume the spec_helper for stdlib will
initialize facter for you. In fact, you don't need to do require
'facter' in your example specification.
> You can see some of what I've been trying at
> https://github.com/wcooley/puppetlabs-stdlib/blob/master/spec/unit/puppet/parser/functions/has_interface_with_spec.rb
Cool, I went ahead and pulled down your branch. If I might make a
suggestion, I notice you're developing on the "master branch" and you
have a number of commits that have not actually been merged into the
"master" branch of the puppetlabs repository.
This situation of having two different branches, both named master, is
confusing and makes it a bit difficult to work with.
When using Git, creating new branches is almost effortless. It's just
two commands.
When you start hacking please create a topic branch:
# Create a branch indicating this is a new feature based on master
having something to do with an interface function
git branch feature/master/has_interface_with_function origin/master
# Checkout the branch
git checkout feature/master/has_interface_with_spec
# Hack away
It's also fairly easy to rename your current topic branch which is
named "master"
# Rename your local master branch to a topic branch
git branch rename master feature/master/has_interface_with_function
# Push the new name to your github repository
git push wcooley
feature/master/has_interface_with_function:feature/master/has_interface_with_function
# Set your local topic branch to track the published copy of it.
git branch --set-upstream feature/master/has_interface_with_function
wcooley/feature/master/has_interface_with_function
# Re-synchronize the Puppet Labs master branch (I assume origin is
git://github.com/puppetlabs/puppetlabs-stdlib.git)
git fetch origin
# Create your local master tracking Puppet Labs master (These should
always be in sync. Don't commit on this branch...)
git branch master --track origin/master
# Replace your own master branch on Github with the Puppet Labs master
branch (because it's not actually master right now)
git push wcooley +origin/master:master
# Finally, work in your topic branch
git co feature/master/has_interface_with_function
> Is there something obvious I'm missing?
The setup looks to be quite strange. You shouldn't ever need to
define a get_scope method. I recommend looking at the
validate_re_spec.rb for a good example.
I'm also re-working your topic branch in my own if you'd like to take
a look at the changes.
-Jeff
I went ahead and re-worked the example specification.
Please take a look at the commit message and the way I'm setting an
expectation that mocks the behavior of lookupvar for both Mac OS X and
Linux.
https://github.com/jeffmccune/puppetlabs-stdlib/tree/feature/master/has_interface_with
$ rspec --format d spec/unit/puppet/parser/functions/has_interface_with_spec.rb
function_has_interface_with
On Mac OS X Systems
should have loopback (lo0)
should not have loopback (lo)
On Linux Systems
should have loopback (lo)
should not have loopback (lo0)
Finished in 0.04262 seconds
4 examples, 0 failures
Please feel free to reply here if you have any questions. We might
also want to consider moving this thread to puppet-dev since it's
developing a new function.
Hope this helps,
-Jeff
Forgot to mention, the most recent commit in that branch is where I
re-worked the spec you asked about.
I've found it's better to link to branches instead of commits because
I often re-write history and commits are absolute references that
might go away inside of a branch whereas a branch is a relative
reference that can be updated frequently.
The actual commit I was referring to is:
https://github.com/jeffmccune/puppetlabs-stdlib/commit/dac3c508659bfc7d034509d3860afe5291aed722
Hope this helps,
-Jeff
On Tue, Apr 10, 2012 at 11:00 PM, Wil Cooley <wilc...@gmail.com> wrote:In general, you should assume the spec_helper for stdlib will
initialize facter for you. In fact, you don't need to do require
'facter' in your example specification.> You can see some of what I've been trying at
> https://github.com/wcooley/puppetlabs-stdlib/blob/master/spec/unit/puppet/parser/functions/has_interface_with_spec.rbCool, I went ahead and pulled down your branch. If I might make a
suggestion, I notice you're developing on the "master branch" and you
have a number of commits that have not actually been merged into the
"master" branch of the puppetlabs repository.
The setup looks to be quite strange. You shouldn't ever need to define a get_scope method. I recommend looking at the validate_re_spec.rb for a good example.
I'm also re-working your topic branch in my own if you'd like to take
a look at the changes.
Ah, this is a problem our platform team is actively working on right now.
The problem is that modules like stdlib need Puppet to be initialized
in a manner suitable for testing. Setting things like confdir and
what not. This means different actions for different versions of
Puppet, and stdlib works all the way back through 2.6.
In any event, if you run against Puppet 2.7.x from source, this method
should already be added to Puppet.
We should also have stdlib fixed up shortly.
If you'd like to actively work on this, please feel free to hop into
#puppet and or #puppet-dev on freenode and ping cprice or myself.
More background information on this problem is located at:
http://projects.puppetlabs.com/issues/13693
Hope this helps,
-Jeff
The problem is that modules like stdlib need Puppet to be initialized
in a manner suitable for testing. Setting things like confdir and
what not. This means different actions for different versions of
Puppet, and stdlib works all the way back through 2.6.
Yes, please file a ticket at:
http://projects.puppetlabs.com/projects/stdlib
You'll need to register an account if you don't already have one.
If it's a somewhat substantial patch could you also please sign the CLA at:
https://projects.puppetlabs.com/contributor_licenses/sign
Thanks,
-Jeff McCune