-
-
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
Add a describe_on_supported_os DSL #132
base: master
Are you sure you want to change the base?
Conversation
It is quite tedious to write the on_supported_os loop in every file. This defines a short hand in the RSpec DSL. To keep access to the OS facts, it is added to the metadata.
@@ -185,6 +185,23 @@ describe 'myclass' do | |||
end | |||
``` | |||
|
|||
```ruby |
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 added the example here just so you could easily compare it to the block above it.
Codecov Report
@@ Coverage Diff @@
## master #132 +/- ##
==========================================
- Coverage 96.20% 93.41% -2.79%
==========================================
Files 2 2
Lines 158 167 +9
==========================================
+ Hits 152 156 +4
- Misses 6 11 +5
Continue to review full report at Codecov.
|
This demonstrates how the new describe_on_supported_os method would change the templates. This is still a draft PR to rspec-puppet-facts (voxpupuli/rspec-puppet-facts#132) and this is to raise awareness.
I do not care for the proposed addition, but I don't mind it being added as long as I can opt out of using it. That includes it not being incorporated into the standard PDK test templates, though I suppose PDK is out of scope here. I find the proposed new approach less readable overall than the current one, the (minor, as far as I am concerned) advantage of reducing nesting depth notwithstanding. Additionally, I see some functionality issues, including:
|
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.
Also, would something like this still be possible?
let(:facts) do
facts.merge(classification: {
'stage' => nil,
})
end
... | ||
|
||
# If you need any to specify any operating system specific tests | ||
case metadata[:os_facts][:osfamily] |
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.
The current setup only symbolizes part of the data used in blocks like this. How would one expanded to use non-legacy facts look? It looks like this today, for context:
case os_facts[:os]['family']
when 'RedHat'
...
when 'Debian'
...
else
...
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.
metadata[:os_facts]
is os_facts
so metadata[:os_facts][:os]['family']
.
Again, really unrelated but yes, it's really confusing that it's not fully using symbols. The root cause is here. Ideally speaking it would use something like HashWithIndifferentAccess but pulling in ActiveSupport just for that feels very heavy. However, facts from FacterDB should really be read-only besides overrides. We can probably easily subclass Hash
and override [](key)
to call .to_s(key)
. While we're at it, implement override
in it as well.
Regarding overriding facts, this hasn't changed. I'd recommend https://github.com/voxpupuli/voxpupuli-test#fact-handling where I've documented what I think are best practices. In short: you need to use context 'with SELinux on' do
let(:facts) { super().merge(selinux: true) }
end Unrelated, but with modern facts this isn't really going to work since you need to deep merge. For this we have override_facts in voxpupuli-test. #112 is open for this and |
It is quite tedious to write the
on_supported_os
loop in every file. This defines a short hand in the RSpec DSL. To keep access to the OS facts, it is added to the metadata.This is a bit hacky, but I'm submitting it here for consideration. The naming may also be confusing and perhaps there's a better name.
There are also limitations. It's no longer possible to pass a select number of operating systems.
The goal is to replace
With