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

(PDK-511) Add canonicalization checking if puppet strict is on. #30

Merged
merged 2 commits into from
Mar 12, 2018
Merged

(PDK-511) Add canonicalization checking if puppet strict is on. #30

merged 2 commits into from
Mar 12, 2018

Conversation

da-ar
Copy link

@da-ar da-ar commented Mar 2, 2018

No description provided.

@da-ar da-ar requested a review from DavidS March 2, 2018 16:31
Copy link
Contributor

@DavidS DavidS left a comment

Choose a reason for hiding this comment

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

A few minor comments, and the test section needs to be tightened up to expose the differences better.

when :warning
Puppet.warning(message)
when :error
# TODO: get more context for the abort error message
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the current output of, say, puppet resource when this is hit, and what should it be?

@@ -408,105 +408,308 @@ def set(_context, changes)
before(:each) do
stub_const('Puppet::Provider::Canonicalizer', Module.new)
stub_const('Puppet::Provider::Canonicalizer::Canonicalizer', provider_class)
Puppet.settings[:strict] = :off
Copy link
Contributor

Choose a reason for hiding this comment

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

Set a global default using https://relishapp.com/rspec/rspec-core/docs/hooks/before-and-after-hooks#define-%60before%60-and-%60after%60-blocks-in-configuration . That way we don't have to worry about puppet changing under our feet across versions, and it becomes clearer if and when individual tests have to override.

And the default should be :error, because we need to be able to work under the strictest setting without crashing and burning.

end

it { expect { described_class.register_type(definition) }.not_to raise_error }
context 'with get values that will not be canonicalized' do
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm having a hard time parsing this. Maybe "when get returns canonical values" ?

it('returns an array of TypeShims') { expect(type.instances[0]).to be_a Puppet::ResourceApi::TypeShim }
it('its name is set correctly') { expect(type.instances[0].name).to eq 'somename' }
end
context 'with get values that will be canonicalized' do
Copy link
Contributor

Choose a reason for hiding this comment

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

As above, maybe "when canonicalize changes get values"?

end

it { expect { described_class.register_type(definition) }.not_to raise_error }
context 'with get values that will not be canonicalized' do
it { expect { described_class.register_type(definition) }.not_to raise_error }
Copy link
Contributor

Choose a reason for hiding this comment

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

This test does not exercise the get/canonicalize interaction, so you can leave it in the common section.

allow(type.my_provider).to receive(:get)
.with(kind_of(Puppet::ResourceApi::BaseContext))
.and_return([{ name: 'somename', test_string: 'canonfoo' },
{ name: 'other', test_string: 'canonbar' }])
Copy link
Contributor

Choose a reason for hiding this comment

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

This is duplicating a big chunk of setup code with the new with get values that will be canonicalized section, without extracting the common parts. It would be easier to read if you do something like this:

before(:each) do
  allow(type.my_provider).to receive(:get)
    .with(kind_of(Puppet::ResourceApi::BaseContext))
    .and_return([{ name: 'somename', test_string: first_test_string },
                  { name: 'other', test_string: second_test_string }])
end

context 'with get values that will not be canonicalized' do
  let(:first_test_string) { "canonfoo" }
  let(:first_test_string) { "canonbar" }

  # ...
end

context 'with get values that will be canonicalized' do
  let(:first_test_string) { "foo" }
  let(:first_test_string) { "bar" }

  # ...
end

@da-ar da-ar changed the title WIP (PDK-511) Add canonicalization checking if puppet strict is on. (PDK-511) Add canonicalization checking if puppet strict is on. Mar 8, 2018
Copy link
Contributor

@DavidS DavidS left a comment

Choose a reason for hiding this comment

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

Never closer! Let's go through the last two points after lunch.

end

after(:each) do
log_sink.clear
Copy link
Contributor

Choose a reason for hiding this comment

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

due to rspec's semantics, the code gets a new let(:log_sink) instance for each example (it), so no need to clean up log_sink.

What I do wonder though is whether Puppet::Util::Log.newdestination will be happy with all the LogCollectors accumulating? With https://github.com/puppetlabs/puppet-resource_api/pull/29/files#diff-93830fa29d616f7c87903d08b5b1b29aR34 we have https://github.com/puppetlabs/puppetlabs_spec_helper/blob/4271c7222e3366c57863bc8a77ccc117f5d6ec7d/lib/puppetlabs_spec_helper/puppet_spec_helper.rb#L134-L160 available, which could supersede this entire section here.

Returned values: {:name=>"somename", :test_string=>"foo"}
Canonicalized values: {:name=>"somename", :test_string=>"canonfoo"}
MESSAGE
end
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not understanding what the different values here are used/useful for. Let's work on this bit after lunch?

Copy link
Contributor

@DavidS DavidS left a comment

Choose a reason for hiding this comment

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

Final result of pairing session.

da-ar and others added 2 commits March 12, 2018 17:31
@DavidS DavidS merged commit 8bde5fb into puppetlabs:master Mar 12, 2018
@da-ar da-ar deleted the pdk-511-strict-checking branch March 23, 2018 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants