Skip to content
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

71/fix up unit tests #72

Merged
merged 1 commit into from
Jan 28, 2025
Merged

Conversation

avitacco
Copy link
Contributor

The only unit test that existed did not work, so I fixed that and added tests for most other resources in this module. I did not add tests for the anchors as the anchor pattern is not considered good practice and is something that pdk validate complains about.

I also added an integration acceptance test. This test actually applies the graylog::server class per the documentation to test that the module behaves as expected. This test could be expanded upon, but this serves as a good starting point.

This fixes #71

Notes for Reviewers

  • The commit history must be preserved - please use the rebase-merge or standard merge option instead of squash-merge
  • Sync up with the author before merging

The only unit test that existed did not work, so I fixed that and added
tests for most other resources in this module. I did not add tests for
the anchors as the anchor pattern is not considered good practice and is
something that `pdk validate` complains about.

I also added an integration acceptance test. This test actually applies
the graylog::server class per the documentation to test that the module
behaves as expected. This test could be expanded upon, but this serves
as a good starting point.
Copy link
Member

@bernd bernd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, nice! Thank you! 🙏

How do we integrate the tests with GitHub Actions? What commands need to be executed?

@avitacco
Copy link
Contributor Author

avitacco commented Jan 27, 2025

Short answer

There are three different types of tests you can run against the code, they're detailed below.

pdk validate

This command will look at different parts of the code and do code style-checking. It checks most file types used in puppet, even tests which can be annoying sometimes. There are occasions where you need to have the linter ignore things, the documentation for that is at http://puppet-lint.com/controlcomments/.

pdk test unit

This command runs the unit tests (optionally, with --parallel). Unit tests are written using rspec puppet, the documentation for that is at https://rspec-puppet.com/.

Litmus tests

Puppet litmus tests use docker containers to test the module on "actual machines". There are a couple of files that control different things for this. Documentation for litmus is annoyingly sparse and poor. Some documentation is at https://puppetlabs.github.io/litmus/.

Litmus tests are written using server spec. Please see https://serverspec.org/ for more information about that.

.fixtures.yml

This file (in fixtures.forge_modules) controls which modules get added to the containers.

provision.yaml

This file controls what images are brought up for different groups.

Running

pdk bundle exec rake 'litmus:provision_list[default]'

This command brings up the 'default' group of container images. See the provision.yaml file for other groups. I use the 'single' group when developing, then switch to 'default' to test all distros.

pdk bundle exec rake 'litmus:install_agent'

This command will install the agent on the containers.

pdk bundle exec rake 'litmus:install_module'

This command installs the module code onto the containers.

pdk bundle exec rake 'litmus:acceptance:parallel'

This command runs the acceptance tests.

pdk bundle exec rake litmus:tear_down

This command stops and removes all container images that the provision_list command starts.

@bernd
Copy link
Member

bernd commented Jan 28, 2025

@avitacco Thank you very much for the detailed response! 🙏 I ran the tests successfully on my local machine. I will update our Actions workflow to run the tests.

@bernd bernd merged commit 13d249e into Graylog2:main Jan 28, 2025
1 check passed
@avitacco avitacco deleted the fix-and-expand-upon-tests branch January 28, 2025 13:29
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.

Unit tests are incomplete and broken
2 participants