0

We are currently developing three puppet modules. One contains a Defined Type which the other two shall use. This module, lets call it ModuleA, is not released yet into our local forge/repository and will not until it was successfully implemented and tested in at least one of the other two modules (company procedure).

The Definded Type is used in the other two modules to create a resource and is referenced via 'include'. In the metadata.json ModuleA is added as dependency.

When I run pdk test unit it fails because the Defined Type is unknown. Currently there is only a single it { is_expected.to compile.with_all_deps } test in the other two modules, nothing complex.

How can the other two modules be tested if ModuleA is not released yet?

Michael P.
  • 33
  • 6

1 Answers1

0

How can the other two modules be tested if ModuleA is not released yet?

Your tests for the other modules can provide stub implementations of the required defined type. This can be done with a :pre_condition:

describe 'Module_b::Some_class' do
  let(:pre_condition) { 'define module_a::some_type($param1, $param2) { }' }

  # ...
end

Do be sure that the number and names of the stub match those of the real defined type.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
  • Thanks for your answer but it does not work. I even copied the defined type into the `:pre_condition` but i am still getting those `Puppet::Error: # Could not find class ::module_a::some_type for mydevpc.localdomain` errors – Michael P. Jul 13 '20 at 09:36
  • @MichaelP., you said you're dealing with a *defined type*, and this answer responds to that. If Puppet complains that it "could not find *class* [...]", however, then the code under test expects a class. Classes and defined types are not interchangeable. You can also use a `:pre_condition` to declare a class, but before changing that you should sort out what it is that module A actually provides, and whether that's in fact what you need it to provide. – John Bollinger Jul 13 '20 at 12:45
  • I know that _defined type_ and _class_ is not interchangeable. Sadly the error message is the same for both. – Michael P. Jul 22 '20 at 09:30