Skip to content

Instantly share code, notes, and snippets.

@riton
Created July 4, 2017 13:44
Show Gist options
  • Save riton/4c51370c6d9c4bc34de69986ff891da9 to your computer and use it in GitHub Desktop.
Save riton/4c51370c6d9c4bc34de69986ff891da9 to your computer and use it in GitHub Desktop.
rspec-puppet-function
# functions/myfunction.pp
function mymodule::myfunction(Array[String] $domains) >> Array {
$result = $domains.map |$domain| {
{
"${domain}/.../*" => { 'include' => true }
}
}
$result
}
# vim: tabstop=2 shiftwidth=2 softtabstop=2
# spec/functions/myfunction_spec.rb
require 'spec_helper'
describe 'mymodule::myfunction', :type => :puppet_function do
it 'should return Array' do
h = subject.execute(['/d1', '/d2'])
expect(h).to be_a(Array)
end
let(:expected_result) do
[
{ '/d1/.../*' => {
'include' => true
},
},
{
'/d2/.../*' => {
'include' => true
}
}
]
end
it 'should return proper structure with order respected' do
h = subject.execute(['/d1', '/d2'])
expect(h).to eq(expected_result)
end
it 'should return empty array when called with empty arg' do
h = subject.execute([])
expect(h).to eq([])
end
end
# vim: tabstop=2 shiftwidth=2 softtabstop=2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment