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-917) Validates provider.get values against Type schema #88

Merged
merged 1 commit into from
Jun 8, 2018
Merged

(PDK-917) Validates provider.get values against Type schema #88

merged 1 commit into from
Jun 8, 2018

Conversation

da-ar
Copy link

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

No description provided.

@da-ar da-ar requested a review from DavidS June 6, 2018 16:19
Style/TrailingCommaInLiteral:
Description: Prefer always trailing comma on multiline literals. This makes diffs,
and re-ordering nicer.
EnforcedStyleForMultiline: comma
Copy link
Contributor

Choose a reason for hiding this comment

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

Please revert that

@@ -4,7 +4,7 @@
require 'tempfile'

RSpec.describe 'exercising simple_get_filter' do
let(:common_args) { '--verbose --debug --trace --modulepath spec/fixtures' }
let(:common_args) { '--verbose --debug --trace --strict=error --modulepath spec/fixtures' }
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a space too much here (and everywhere you copy&pasted this)

@@ -304,6 +290,8 @@ def call_provider(value); end
my_provider.get(context).find { |h| namevar_match?(h) }
end

@warning_count = 0 # always reset when called
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't reset here. After 100 warnings for a type, there is no additional info that devs can get from this, and we don't want to kill production if someone slips in hitting this.

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.

Besides the mostly cosmetic changes here, there is also another call to get() in SimpleProvider that needs the check_schema call, too.

let(:prefix) { 'Warning:' }

it 'is raises the expected warnings' do
stdout_str, status = Open3.capture2e("puppet resource #{common_args} provider_validation")
Copy link
Contributor

Choose a reason for hiding this comment

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

You can re-use the expectations here by wrapping the describes in a loop like this:

[ ['warning', 'Warning: '], ['error', 'Error: Could not run:'], ...].each do |strict_value, prefix_value|
describe "when strict is set to #{strict_value}" do
  let(:common_args) { super() + " --strict=#{strict_value}" }
  let(:prefix) { prefix_value }
...

end

describe '#check_schema_values' do
let(:definition) do
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason not to update the main :definition, instead of this and duplicating it in the next context?

message = "Provider returned data that does not match the Type Schema for `#{name}[#{resource[namevars.first]}]`"

rejected_keys = check_schema_keys(resource) # removes bad keys
bad_values = check_schema_values(resource.dup)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is check_schema allowed to modify resource or not? If yes, do you need to dup here? If not, shouldn't this dup before check_schema_keys?

Also, now that the question has come up, you might want to add a unit test making sure that resource doesn't get modified when checking.

@DavidS DavidS merged commit aab421e into puppetlabs:master Jun 8, 2018
@da-ar da-ar deleted the pdk-917-strict-get-checks branch June 8, 2018 14:29
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