Skip to content

Make testing of Deferred function easier #782

@baurmatt

Description

@baurmatt

In spacedog/puppet-wireguard#21 I've implemented support for Deferred functions. To make this complete, I'd like to test the functionally with rspec-puppet. After some discussion in #testing and #office-hours on the community Slack 2 solutions got found:

  1. Implement the testing based on manifest fixtures as suggested by @michaeltlombardi. Similar to what has been done in https://github.com/rodjek/rspec-puppet/pull/743/files#diff-fd749db586cffafe2365831dcc04992c for the initial Deferred support.
  2. Loading the Type somehow through a_scope.call_function("new", Puppet::Pops::Types::TypeFactory.deferred(), "myfunc", [1,2,3]) as suggested by @hlindberg.

Both solutions are, in my eyes, rather complicated to implemented for a core functionality of Puppet and I would love to see and easier way of doing this.

context "with private_key => Deferred('wireguard::genprivatekey', ['/etc/wireguard/wg0.key'])," do
  let(:params) do
    {
      private_key: Deferred('wireguard::genprivatekey', ['/etc/wireguard/wg0.key']),
      listen_port: 12345,
    }
  end

  it { is_expected.to compile.with_all_deps }

  it do
    is_expected.to contain_file('/etc/wireguard/wg0.conf').with({
      content: Deferred('inline_epp', [file('wireguard/interface.conf.epp'), $config])
    })
  end
end

Thanks! :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions