-
Notifications
You must be signed in to change notification settings - Fork 42
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
Conversation
Style/TrailingCommaInLiteral: | ||
Description: Prefer always trailing comma on multiline literals. This makes diffs, | ||
and re-ordering nicer. | ||
EnforcedStyleForMultiline: comma |
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.
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' } |
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 is a space too much here (and everywhere you copy&pasted this)
lib/puppet/resource_api.rb
Outdated
@@ -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 |
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.
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.
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.
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") |
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.
You can re-use the expectations here by wrapping the describe
s 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 |
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.
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) |
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 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.
No description provided.