-
Notifications
You must be signed in to change notification settings - Fork 580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(#12345) hiera enabled function for stdlib #32
Changes from 2 commits
d54fa78
a78cdf2
15c7137
773cb47
85ea966
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'puppet/util/feature' | ||
Puppet.features.add(:hiera, :libs => %{hiera}) | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Puppet::Parser::Functions | ||
newfunction(:hiera_enabled, :type => :rvalue ) do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd really like to see an inline doc string here so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you give me an example? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like the Doc lines here --> https://github.com/puppetlabs/puppetlabs-stdlib/blob/master/lib/puppet/parser/functions/abs.rb#L6-8 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed this with commit 773cb47 |
||
if Puppet.features.hiera? and Puppet::Parser::Functions.function(:hiera) | ||
true | ||
else | ||
false | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'puppet' | ||
require 'mocha' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't the spec_helper take care of this? If not, could you add these two requires to the spec_helper please? |
||
|
||
RSpec.configure do |config| | ||
config.mock_with :mocha | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should definitely be in the spec_helper There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spec_helper? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! This is done with commit 85ea966 |
||
|
||
describe Puppet::Parser::Functions.function(:hiera_enabled) do | ||
before :each do | ||
@scope = Puppet::Parser::Scope.new | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend avoiding instance variables and instead use let to get a memoized helper method like this: More information at let and let! describe 'Puppet::Parser::Functions.function(:hiera_enabled)' do
let :scope do
Puppet::Parser::Scope.new
end
it "should fail if hiera is not installed" do
Puppet.features.expects(:hiera?).returns false
Puppet::Parser::Functions.stubs(:function).with(:hiera).returns false
scope.function_hiera_enabled([]).should be_false
end
end |
||
end | ||
it "should fail if hiera is not installed" do | ||
Puppet.features.stubs(:hiera?).returns false | ||
Puppet::Parser::Functions.stubs(:function).with(:hiera).returns false | ||
@scope.function_hiera_enabled([]).should be_false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that all the .stubs should be .expects - setup an expectation that the function call (or features call) IS made so that if that call is ever NOT made then you know something broke. As it stands now, we're saying "IF you call this function, just return false" when in reality we want to say "YES, this function SHOULD be called, AND it should return FALSE". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/.stubs/.expects and the first test now fails and I'm not sure why
"/opt/puppet/share/puppet/modules/stdlib/spec"
F...
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When this happens it's because the thing you're stubbing never actually receives a message. Switching the stub to an expectation means it will fail if it's never sent a message. When this happens to me, it's almost always because the thing I thought I was calling isn't actually the thing being called. Does this help? |
||
end | ||
it "should fail if hiera is not installed but the function, hiera(), is available" do | ||
Puppet.features.stubs(:hiera?).returns false | ||
Puppet::Parser::Functions.stubs(:function).with(:hiera).returns true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These stubs shouldn't actually return A quick way to find out what would actually be returned from a real object rather than a mocked object is to drop into an interactive debugger right before setting up your mock. For example: Does
Ah, it looks like a valid function returns a string rather than |
||
@scope.function_hiera_enabled([]).should be_false | ||
end | ||
it "should fail if hiera is installed but the function, hiera(), is not available" do | ||
Puppet.features.stubs(:hiera?).returns true | ||
Puppet::Parser::Functions.stubs(:function).with(:hiera).returns false | ||
@scope.function_hiera_enabled([]).should be_false | ||
end | ||
it "should succeed is hiera is installed and the function, hiera(), is available" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/is/if/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. huh? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You wrote 'is' twice on that line, --> "should succeed IF hiera is installed..." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah! committed 15c7137 to fix that |
||
Puppet.features.stubs(:hiera?).returns true | ||
Puppet::Parser::Functions.stubs(:function).with(:hiera).returns true | ||
@scope.function_hiera_enabled([]).should be_true | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
:hiera
or:hiera?
It doesn't seem to match up to spec/unit/puppet/parser/functions/hiera_enabled_spec.rb:L13 where you usePuppet.features.stubs(:hiera?).returns false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There doesn't seem to be any test coverage for this feature, I only see that we stub it. I'd like to see an expectation that the feature is added to Puppet. This could be as simple as setting an expectation like
Puppet.features.expects(:add).with(:hiera, :libs => 'hiera')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something actionable that I need to address?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sorry for not being direct.
It actually seems strange that
Puppet.features.add(:hiera, :libs => %{hiera})
isn't contained in anything. What'sself
when this code is evaluated?This should definitely have some coverage.