Skip to content

Commit

Permalink
Fix vhost unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jay7x committed Dec 20, 2024
1 parent b03e563 commit 249cdd4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion manifests/vhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
) {
include caddy

if ($ensure == 'present') and !($source or $content) {
if ($ensure != 'absent') and !($source or $content) {
fail('Either $source or $content must be specified when $ensure is "present"')
}

Expand Down
32 changes: 30 additions & 2 deletions spec/defines/vhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,37 @@
end

context 'with config_dir set' do
let(:params) { super().merge(config_dir: '/etc/caddy/conf.d') }
let(:params) { super().merge(config_dir: '/etc/caddy/sites-available') }

it { is_expected.to contain_file('/etc/caddy/conf.d/example.conf') }
it { is_expected.to contain_file('/etc/caddy/sites-available/example.conf').with_ensure('file') }
end

context 'with enable_dir set' do
let(:params) { super().merge(enable_dir: '/etc/caddy/sites-enabled') }

it { is_expected.to contain_file('/etc/caddy/config/example.conf').with_ensure('file') }

it do
is_expected.to contain_file('/etc/caddy/sites-enabled/example.conf').
with_ensure('link').
with_target('/etc/caddy/config/example.conf')
end

%w[present disabled].each do |ens|
context "with ensure => #{ens}" do
let(:params) { super().merge(ensure: ens) }

it { is_expected.to contain_file('/etc/caddy/config/example.conf').with_ensure('file') }
it { is_expected.to contain_file('/etc/caddy/sites-enabled/example.conf').with_ensure('absent') }
end
end

context 'with ensure => absent' do
let(:params) { super().merge(ensure: 'absent') }

it { is_expected.to contain_file('/etc/caddy/config/example.conf').with_ensure('absent') }
it { is_expected.to contain_file('/etc/caddy/sites-enabled/example.conf').with_ensure('absent') }
end
end

context 'with ensure => absent' do
Expand Down

0 comments on commit 249cdd4

Please sign in to comment.