Puppet 4 functions#40
Merged
duritong merged 10 commits intoduritong:masterfrom Mar 24, 2026
Merged
Conversation
This makes it a lot easier to run tests manually but also to understand the output in CI.
This helper function is the basis for the puppet functions `trocla()` and `trocla_get()`. Because of the trouble the singleton class in the helper is causing to tests, we're testing actual functionality of trocla only here.
The tests themselves are simplistic since they only ensure that params are passed down to trocla correctly and we get the correct response from it. The complexity in the test file is mostly just linked to getting trocla to read test data from a temporary directory. Compared to the static storage file in fixtures/data that the previous gsub unit tests were using, we want to test getting a value for a key that's not yet present in the storage, which will result in data being added to the storage file. So it would be better to use a dynamically created storage file that is reinitialized for every test.
This is almost the same as the tests for trocla(). We only want to test that parameters to the trocla helper are the ones being tested in the spec file for the helper function.
The example with pgsql format comes from the function documentation, but I'm not convinced that it will be a robust test in the future since nothing from the user request specifies which hashing algorithm is used for the password.
The return type of the function changes from nil to :undef with the puppet function syntax migration
in trocla.set_password the options hash gets modified, but rspec-puppet sets all run parameters as frozen, so we need to create a duplicate of the options hash in order to be able to run tests.
We can require our helper function using the puppet namespace instead of using a relative path.
We now have type annotations for the newly transformed puppet 4.x functions. Plus the puppet-strings example tags get picked up and enumerated as such.
Owner
|
wow - much ❤️ !!! thank you very much! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This series migrates all remaining puppet 3.x ruby functions into 4.x syntax
Before doing that migration though, it creates unit tests. This way we can easily check before/after that the behavior of the functions was not broken with the migration.
Just to make the rspec output more useful, the first commit also sets a different output format for rspec.
Closes: #39