Skip to content

Commit

Permalink
Add configfile unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jay7x committed Dec 20, 2024
1 parent 249cdd4 commit 147cc05
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions spec/defines/configfile_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'caddy::configfile', type: :define do
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts
end
let(:pre_condition) { 'class { "caddy": config_dir => "/etc/caddy/config" }' }
let(:title) { 'example' }

context 'with source' do
let(:params) { { source: 'puppet:///modules/caddy/etc/caddy/config/example1.conf' } }

it do
is_expected.to contain_file('/etc/caddy/config/example.conf').with(
'ensure' => 'file',
'source' => 'puppet:///modules/caddy/etc/caddy/config/example1.conf',
'mode' => '0444',
'require' => 'Class[Caddy::Config]',
'notify' => 'Class[Caddy::Service]'
)
end

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

it { is_expected.to contain_file('/etc/caddy/conf.d/example.conf') }
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') }
end

context 'with custom title' do
let(:title) { 'test' }

it { is_expected.to contain_file('/etc/caddy/config/test.conf') }
end
end

context 'with content' do
let(:params) { { content: 'localhost:2015' } }

it do
is_expected.to contain_file('/etc/caddy/config/example.conf').with(
'ensure' => 'file',
'content' => 'localhost:2015',
'mode' => '0444',
'require' => 'Class[Caddy::Config]',
'notify' => 'Class[Caddy::Service]'
)
end
end

context 'without source & content' do
it { is_expected.to compile.and_raise_error(%r{Either \$source or \$content must be specified}) }
end
end
end
end

0 comments on commit 147cc05

Please sign in to comment.