-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Use facterdb_string_keys configuration option for custom facts #157
Use facterdb_string_keys configuration option for custom facts #157
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #157 +/- ##
==========================================
+ Coverage 94.93% 95.23% +0.30%
==========================================
Files 2 2
Lines 158 168 +10
==========================================
+ Hits 150 160 +10
Misses 8 8 ☔ View full report in Codecov by Sentry. |
6fc415b
to
3ca517d
Compare
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.
Deep merging by default feels wrong, because then you can't replace facts entirely anymore.
You're also ignoring RSpec.configuration.facterdb_string_keys
exists. We should really do a breaking change at some point to and flip it to true
. That does mean everyone needs to change their specs. I've also thought about ActiveSupport::HashWithIndifferentAccess but that's a dependency I don't want to pull in.
Agreed, seems like bit of an anti-pattern in hindsight to have this deep_merge all the time.. |
828b171
to
977acc2
Compare
1b0e86b
to
0121a50
Compare
0121a50
to
7482750
Compare
7482750
to
8243868
Compare
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 also the weird bit where top level facts are symbolized but all other levels aren't (and thus strings). Right now I can see someone trying to add a custom (structured) fact to override built in facts and use symbols for the second level. So
add_custom_fact 'identity', { user: "test_user" }, merge_facts: true
The result would be:
{
"gid"=>0,
"group"=>"root",
"privileged"=>true,
"uid"=>0,
"user"=>"root",
:user => "test_user"
}
I tried to look at a setting for this, but I don't think there is one. It happens here: https://github.com/voxpupuli/facterdb/blob/4d3f5e846de545dad89ad5e4196024eedbcaeec2/lib/facterdb.rb#L146
8243868
to
54203f7
Compare
Yeah okay that is strange.. Not ideal. |
54203f7
to
2655b2e
Compare
thanks @ekohl i'll look to address your comments shortly |
0421a21
to
86ad164
Compare
b6bb647
to
16bca72
Compare
27e252d
to
5c54e93
Compare
Let me know if anything else is needed. |
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.
For the changelog I would really want the custom fact as symbol change separated into its own PR because that part backwards incompatible requiring a major version bump. It does break test suites that have conditionals on custom facts.
5c54e93
to
c1b61a9
Compare
3456d6e
to
7f6dcd6
Compare
Previously, when registering a custom fact with rspec-puppet-facts, the fact key would be converted to a string. This lead to duplicate facts being present in the facts hash, as default fact keys are stored as sym. To fix this, we remove a `to_s` conversion on the key in the register_custom_fact method, unless the rspec config stringify keys is true.
7f6dcd6
to
ab01ecc
Compare
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've rephrased the PR title to better capture what it's covering. I think this is now ready to merge.
@ekohl thanks for all your guidance with this one |
Hi, Breaking changes:
objections on how we proceed? Should we merge #157 and release it with those changes? Or do two major releases in a row? |
I'd combine them. Possibly also di the breaking change in FacterDB of removing old stuff. I can't find the issue now, but I'd also consider swapping the string keys value default and only deal with strings instead of symbols/strings |
@ekohl @bastelfreak 👋 can we merge this and I'll start looking at what #160 needs? |
When passing custom facts, it would result in a duplicate fact key if those facts were already present, for example:
would result in a facts hash like below being returned
Now, when run, the logic will update the element already present in the hash, as opposed to duplicating the sym key as a string.
Fixes #142