Skip to content

Commit

Permalink
systemd::network: Validate if content/source are set for file resource
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Jul 27, 2021
1 parent cf036c9 commit 76f8eb6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions manifests/network.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
$notify = undef
}

if $ensure == 'file' {
if $content =~ Undef and $source =~ Undef {
fail('you need to provide content or source')
}
if $content =~ NotUndef and $source =~ NotUndef {
fail('you can only set $content or $source')
}
}
file { "${path}/${name}":
ensure => $ensure,
content => $content,
Expand Down
19 changes: 19 additions & 0 deletions spec/defines/network_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@

it { is_expected.to create_file("/etc/systemd/network/#{title}").that_notifies('Service[systemd-networkd]') }
end
context 'without content and without source' do
let(:title) { 'wg0.netdev' }
let :params do
{}
end

it { is_expected.to compile.and_raise_error(%r{you need to set}) }
end
context 'with content and source' do
let(:title) { 'wg0.netdev' }
let :params do
{
content: 'bla',
source: 'foo'
}
end

it { is_expected.to compile.and_raise_error(%r{you can only set}) }
end
end
end
end
Expand Down

0 comments on commit 76f8eb6

Please sign in to comment.