Navigation Menu

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

Provide a method-based accessor for SimpleConfig hashes #1544

Merged
merged 1 commit into from Mar 22, 2017

Conversation

adamleff
Copy link
Contributor

@adamleff adamleff commented Mar 6, 2017

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

# (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
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 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?

Copy link
Contributor Author

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>
@adamleff adamleff force-pushed the adamleff/hash-values-in-simpleconfig branch from 78a0190 to ea7c0c4 Compare March 15, 2017 19:49
@adamleff
Copy link
Contributor Author

@chris-rock do you approve of this one now that I switched to using hashie instead?

Copy link
Contributor

@chris-rock chris-rock left a 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

@adamleff adamleff merged commit 73e3bfd into master Mar 22, 2017
@adamleff adamleff deleted the adamleff/hash-values-in-simpleconfig branch March 22, 2017 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants