Skip to content

Commit

Permalink
Merge pull request #205 from bastelfreak/input
Browse files Browse the repository at this point in the history
systemd::network: Validate if content/source are set for file resource
  • Loading branch information
bastelfreak authored Jul 27, 2021
2 parents cf036c9 + 3e997ea commit 8271a5b
Show file tree
Hide file tree
Showing 2 changed files with 25 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('Either content or source must be set')
}
if $content =~ NotUndef and $source =~ NotUndef {
fail('Either content or source must be set but not both')
}
}
file { "${path}/${name}":
ensure => $ensure,
content => $content,
Expand Down
17 changes: 17 additions & 0 deletions spec/defines/network_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,23 @@

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

it { is_expected.to compile.and_raise_error(%r{Either content or source must be set}) }
end
context 'with content and source' do
let :params do
{
content: 'bla',
source: 'foo'
}
end

it { is_expected.to compile.and_raise_error(%r{Either content or source must be set but not both}) }
end
end
end
end
Expand Down

0 comments on commit 8271a5b

Please sign in to comment.