Skip to content
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

Allow an attribute with default boolean value to be set correctly #110

Merged
merged 3 commits into from
Aug 9, 2018
Merged

Allow an attribute with default boolean value to be set correctly #110

merged 3 commits into from
Aug 9, 2018

Conversation

da-ar
Copy link

@da-ar da-ar commented Aug 6, 2018

No description provided.

@da-ar da-ar requested a review from DavidS August 6, 2018 11:03
@da-ar da-ar added the bug label Aug 6, 2018
if options[:behaviour] != :read_only
if options.key? :default
if options[:behaviour] != :read_only && options.key?(:default)
if type.is_a? Puppet::Pops::Types::PBooleanType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about compound types like Optional[Boolean], Array[Boolean] and Variant[String, Boolean]?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be enough to apply the workaround if and only if the default value is actually false?

@@ -521,6 +524,15 @@ def self.mungify(type, value, error_msg_prefix)
# the correct types, e.g. "1" (a string) to 1 (an integer)
cleaned_value, error_msg = try_mungify(type, value, error_msg_prefix)
raise Puppet::ResourceError, error_msg if error_msg
elsif type.is_a? Puppet::Pops::Types::PBooleanType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See compound types above.

context 'when the default value is false' do
let(:type) { Puppet::Type.type(:default_bool) }
let(:default_value) { false }
let(:instance) { type.new(name: 'foo', ensure: 'present') }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lots of duplication here that can be pulled out to the parent context?

@@ -1344,6 +1430,7 @@ def set(_context, changes)
context 'when flushing' do
before(:each) do
Puppet.debug = true
instance.my_provider.set(nil, nil) # reset the current_state
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, how are the changes above leaking into this test case?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

believe random seed order was changed when the new test went in and exposed the bug

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, ok! then please put this in a separate commit with a short note about that, to inform future-us of what went down here.

da-ar and others added 2 commits August 8, 2018 10:46
* ensure that the provider produces valid resources on `get`
* run the `puppet apply` command in a let, instead of a hook
* use the `wibble` resource to test the "optional boolean is absent" case
* test the "variant uses string" case
@DavidS
Copy link
Contributor

DavidS commented Aug 9, 2018

Added some cleanups to the tests. After this has passed CI, we can merge and release?

@da-ar da-ar merged commit 1e62dba into puppetlabs:master Aug 9, 2018
@da-ar da-ar deleted the default_bool branch May 14, 2019 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants