-
Notifications
You must be signed in to change notification settings - Fork 109
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
stages: add new unit test for kickstart stage #1425
Conversation
This is neither a waste of time nor trivial. I'd love to have a quicker way to test stages doing the right things :) |
I like the stage tests living close to the stages. People do write their own stages as well and it fits better in future (tm) plans to support different types of stages which each have their own test. |
d05a5e6
to
cbaa24e
Compare
Thanks, for your excellent feedback! I addressed the points and moved the PR from draft to real and tried to polish it. I'm sure there are a bunch of fixes needed around exact naming and location of the files etc but I hope the shape is now looking good. Fwiw, I'm happy to split the import helper out but given that it's small and the test is the use-case I felt like it might be a good idea to just leave it in :) |
cbaa24e
to
1ccf7e5
Compare
1ccf7e5
to
bbb94bc
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.
Love it. Let's keep it out of CI for now so we can work with it locally for a bit then enable it later or do we want it in now? (cc: @achilleas-k).
Thank you for the review and approval!
Silly me, I understand now what you mean and add the new test to the CI runs. |
Does putting a |
322bf3e
to
f57bbe4
Compare
Thanks, excellent catch (that would have been slightly embarrassing to release with that)! I updated the spec file now to exclude anything |
This commit adds `osbuild.testutil.imports.import_module_from_path` that can be used to import arbitrary python source files. This allows importing files from the stages directory that have a non python friendly filename like `org.osbuild.kickstart`.
This commit adds a simple and lightweight unit test for the new kickstart options. It's pretty simple but also cheap and runs fast.
Include the new `stages/test` test category to the CI runs as well. Note that because `stages/__init__.py` and `stages/test/__init__.py` are missing it is not possible to use the existing style of just doing `stages.test`. Adding `stages/__init__.py` feels wrong and the desire is to have the stages tests close to the stages so this seems the least invasive way.
f57bbe4
to
35c231b
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.
Very nice, can't wait to expand on this in followups :)
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.
LGTM
This commit adds a simple and lightweight unit test for the new kickstart options. It's pretty trivial but also cheap and runs fast. The idea behind it is that the code of the kickstart stage is tested without the need for a full osbuild tree, just passing the test input options and observing the expected file content. The same pattern could potentially be used for other stages (like the user stage) to check that the content of the output has the expected format (or that options that are mutually exclusive are handled correctly).
While this is trivial now and looks a bit like a waste of time I think this will become useful as more kickstart stage options get implemented. The goal is to eventually support the options in https://github.com/RedHatInsights/edge-api/blob/main/templates/templateKickstart.ks in a declarative manner and part of this will involve supporting more things that kickstart is currently doing, e.g https://github.com/RedHatInsights/edge-api/blob/main/templates/templateKickstart.ks#L77 and here we will need to be careful about things like input validation/escaping so having this unit tested seems quite useful. I personally also like it because it tells me at a glance what the kickstart file should look like (test as docuementation).
Note that this is not urgent at all and given how trivial it is I'm fine with being told that this is over-testing. We could keep it in draft stage (or close it even) until there is a more complex use case (as stated above I anticipate there will be one for kickstart).
I'm not happy with chage chage in line 22 (tox.ini), it's needed because with the "*" glob pylint will consider the test dir a python module but because it has no init.py that fails. Adding a init.py will ake pytest fail. The alternative would be to move this under the top level
test/
dir (e.g. undertest/unit/stages
or something.Having said all this - I would love your intput and feedback :)