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

Unit Testing Dependencies Not Properly Mocked #219

Open
DarkArc-Github opened this issue Jan 10, 2025 · 1 comment
Open

Unit Testing Dependencies Not Properly Mocked #219

DarkArc-Github opened this issue Jan 10, 2025 · 1 comment
Labels

Comments

@DarkArc-Github
Copy link

Description:
When using puppetlabs-splunk_hec as a dependency in another module's test suite, the following resources need to be mocked but should be handled within the module itself:

  1. ini_subsetting type
  2. pe_ini_subsetting type
  3. puppetserver service
  4. Custom fact splunk_hec_is_pe

Current Behavior:
Tests fail with errors like:

  • Unknown variable: 'ini_subsetting'
  • Could not find resource 'Service[puppetserver]'

Expected Behavior:
The module's test suite should handle these dependencies internally, allowing dependent modules to test only their integration points without needing to mock core module dependencies.

Steps to Reproduce:

  1. Create a profile that includes the splunk_hec class
  2. Write rspec tests for that profile
  3. Run pdk test unit

Environment:

  • puppetlabs-splunk_hec version: 1.4.0
@coreymbe
Copy link
Contributor

Hello @DarkArc-Github 👋

Thank you for opening this issue. I was able to reproduce the compilation errors following the steps you provided.

error during compilation: Evaluation Error: Error while evaluating a Resource Statement, Unknown resource type: 'Ini_subsetting' (file: test_module/spec/fixtures/modules/splunk_hec/manifests/init.pp, line: 214, column: 5)
error during compilation: Could not find resource 'Service[puppetserver]' in parameter 'notify' (file: test_module/spec/fixtures/modules/splunk_hec/manifests/init.pp, line: 221)

We have a mocked report processor here for our traditional rspec tests. With rspec-puppet when the manifest being tested relies on an existing state, such as another class being included or setting variables, it can be specified using let(:pre_condition). We mock these resources in our testing here.

The evaluation error can be resolved by adding the puppetlabs/inifile module to .fixtures.yml.

Please let us know if this information does not help in resolving the errors you are seeing. If any additional issues or concerns arise please do not hesitate to report them to us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants