-
Notifications
You must be signed in to change notification settings - Fork 23
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
(IAC-1657) Fix for invalid DateTime value error in invoke_get_method
#169
(IAC-1657) Fix for invalid DateTime value error in invoke_get_method
#169
Conversation
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.
Can we get a minimal unit test to validate this behavior? Otherwise, looks good!
182004c
to
765b068
Compare
spec/unit/puppet/provider/dsc_base_provider/dsc_base_provider_spec.rb
Outdated
Show resolved
Hide resolved
df9687c
to
f7aa5bd
Compare
f7aa5bd
to
d281a5a
Compare
6f83bc4
to
4d4d2b5
Compare
invoke_get_methodinvoke_get_method
invoke_get_methodinvoke_get_method
3ce14cf
to
fdfe644
Compare
| begin | ||
| data[type_key] = Puppet::Pops::Time::Timestamp.parse(data[type_key]) if context.type.attributes[type_key][:mof_type] =~ /DateTime/i && !data[type_key].nil? | ||
| rescue ArgumentError, TypeError => e | ||
| # Catch any failures in the parse, output them to the context and then return nil | ||
| context.err("Value returned for DateTime (#{data[type_key].inspect}) failed to parse: #{e}") | ||
| return nil | ||
| 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.
I think we want the data[type_key] = assignment to the begin/rescue block itself;
As is, this implementation will attempt to assign the parsed output to the key and, if that errors, return nil for the entire resource.
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.
Ah, thought that was the desired result, have changed it now
| end | ||
|
|
||
| context 'When the DateTime is an invalid string' do | ||
| let(:name_hash) { { name: 'foo', dsc_name: 'foo', dsc_time: '21000101' } } |
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.
Let's make it more obvious this is a bad string and make it foo or something
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.
Done
fdfe644
to
f5e2472
Compare
|
|
||
| context 'When a' | ||
| it 'casts the formatted timestamp string to DateTime in the property hash' do | ||
| expect(date_time).to receive(:format).and_return('2100-01-01') | ||
| expect(result).to match(/datetime = \[DateTime\]'2100-01-01'/) | ||
| 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.
This looks like it ended up in the wrong place?
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.
oops
Fix has been put in place so that if the returned DateTime is nil it is not parsed and is instead returned as is. In addition, if the parse ever fails the error is caught and outputted into the context, with nil being returned.
f5e2472
to
f053d8e
Compare
Fix has been put in place so that if the returned DateTime is nil it is not parsed and is instead returned as is.
In addition, if the parse ever fails the error is caught and outputted into the context, with nil being returned.