Skip to content

Puppet 4 functions#40

Merged
duritong merged 10 commits intoduritong:masterfrom
lelutin:puppet_4_functions
Mar 24, 2026
Merged

Puppet 4 functions#40
duritong merged 10 commits intoduritong:masterfrom
lelutin:puppet_4_functions

Conversation

@lelutin
Copy link
Copy Markdown
Contributor

@lelutin lelutin commented Mar 21, 2026

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

lelutin added 10 commits March 20, 2026 16:16
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.
@duritong duritong merged commit 930684b into duritong:master Mar 24, 2026
3 checks passed
@duritong
Copy link
Copy Markdown
Owner

wow - much ❤️ !!! thank you very much!

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.

port functions from puppet 3.x to puppet 4.x syntax

2 participants