-
Notifications
You must be signed in to change notification settings - Fork 680
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
Provide a method-based accessor for SimpleConfig hashes #1544
Conversation
4f942f8
to
78a0190
Compare
lib/utils/simpleconfig.rb
Outdated
# (such as a mysql config that has [sections]), provide | ||
# a hash whose values are accessible via methods to provide | ||
# a good user experience with `its` blocks. | ||
class ConfigHash < Hash |
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 is definitely a valid solution. We use hashie in other areas like https://github.com/chef/inspec/blob/546486ff6afc371103943501e9d7e15bcc6941ff/lib/resources/service.rb#L180-L183. Should we stick to the same solution?
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.
Hashie works for me too - updating now...
When SimpleConfig parses a config file that has sections, such as a mysqld config file, the values within that section are returned via a Hash. However, we do not provide an easy way to write tests for those deep hash values: ``` describe mysql_conf('/tmp/my.cnf') do its('mysqld.expire_logs_days') { should cmp 10 } end MySQL Configuration ∅ undefined method `expire_logs_days' for #<Hash:0x007fe463795a00> ``` This change provides a method-based accessor for Hashes that are built via SimpleConfig. ``` describe mysql_conf('/tmp/my.cnf') do its('mysqld.expire_logs_days') { should cmp 10 } end MySQL Configuration ✔ mysqld.expire_logs_days should cmp == 10 ``` Fixes #1541 by changing the way the attributes are fetched. Signed-off-by: Adam Leff <adam@leff.co>
78a0190
to
ea7c0c4
Compare
@chris-rock do you approve of this one now that I switched to using |
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.
Thank you for this improvement @adamleff
When SimpleConfig parses a config file that has sections, such as a mysqld
config file, the values within that section are returned via a Hash. However,
we do not provide an easy way to write tests for those deep hash values:
This change provides a method-based accessor for Hashes that are built via
SimpleConfig.
Fixes #1541 by changing the way the attributes are fetched.
Signed-off-by: Adam Leff adam@leff.co